J
jxjlsun
Unregistered / Unconfirmed
GUEST, unregistred user!
一个弹性小球,当它撞着区域的边缘,就会向相反的方向运动,运动过程中小球的半径会不停
的变化,利用TRACKBAR和SPINEDIT可以改变小球的运行速度,我编的程序如下(不知哪里出错了
,按BUTTON1,小球不动)[?][?]:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, Spin, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
TrackBar1: TTrackBar;
SpinEdit1: TSpinEdit;
Panel1: TPanel;
Image1: TImage;
Timer1: TTimer;
Shape1: TShape;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Interval:=trackbar1.Position;
if i=1 then
begin
if shape1.Left>0 then
begin
shape1.Left:=shape1.Left-10;
shape1.Width:=(shape1.Width+1)mod 70;
shape1.Height:=(shape1.Height+1)mod 70;
end
else
i:=2;
end;
if i=2 then
begin
if shape1.Left<(panel1.width-shape1.width-5) then
begin
shape1.Left:=shape1.Left+10;
shape1.Width:=(shape1.Width+1)mod 70;
shape1.Height:=(shape1.Height+1)mod 70;
end
else
i:=1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Interval:=trackbar1.Position;
timer1.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled:=false;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
spinedit1.Value:=trackbar1.Position;
end;
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
trackbar1.Position:=spinedit1.Value;
end;
initialization
i:=1;
end.
的变化,利用TRACKBAR和SPINEDIT可以改变小球的运行速度,我编的程序如下(不知哪里出错了
,按BUTTON1,小球不动)[?][?]:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, Spin, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
TrackBar1: TTrackBar;
SpinEdit1: TSpinEdit;
Panel1: TPanel;
Image1: TImage;
Timer1: TTimer;
Shape1: TShape;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Interval:=trackbar1.Position;
if i=1 then
begin
if shape1.Left>0 then
begin
shape1.Left:=shape1.Left-10;
shape1.Width:=(shape1.Width+1)mod 70;
shape1.Height:=(shape1.Height+1)mod 70;
end
else
i:=2;
end;
if i=2 then
begin
if shape1.Left<(panel1.width-shape1.width-5) then
begin
shape1.Left:=shape1.Left+10;
shape1.Width:=(shape1.Width+1)mod 70;
shape1.Height:=(shape1.Height+1)mod 70;
end
else
i:=1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Interval:=trackbar1.Position;
timer1.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled:=false;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
spinedit1.Value:=trackbar1.Position;
end;
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
trackbar1.Position:=spinedit1.Value;
end;
initialization
i:=1;
end.