unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 =
class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
tball =
class
x,y,vx,vy,r: single;
farbe: tcolor;
procedure init (fneu: tcolor; xneu, yneu, vxneu, vyneu, rneu: single);
procedure zeigedich;
procedure bewegedich;
end;
var
Form1: TForm1;
ball: tball;
implementation
{$R *.DFM}
procedure tball.init (fneu: tcolor; xneu, yneu, vxneu, vyneu, rneu: single);
begin
farbe:= fneu;
r:= rneu;
x:=xneu;
y:=yneu;
vx:=vxneu;
vy:=vyneu;
end;
procedure tball.zeigedich;
begin
with form1.image1.canvas
do
begin
brush.color:=farbe;
ellipse(round(x-r),round(y-r),round(x+r),round(y+r));
end;
end;
procedure tball.bewegedich;
begin
x:=x+vx;
y:=y+vy;
with form1.Image1
do
begin
if (x>width-r-1)
then
begin
x:=width-r-1;
vx:=-vx;
end;
if x<r+1
then
begin
x:= r+1;
vx:=-vx
end;
if (y>height-r-1)
then
begin
y:=height-r-1;
vy:=-vy;
end;
if y<r+1
then
begin
y:=r+1;
vy:=-vy;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with image1.canvas
do
begin
pen.width:=5;
brush.color:=clwhite;
rectangle(0,0,image1.width,image1.height);
pen.width:=2;
brush.style:=bssolid;
pen.mode:=pmnotxor;
end;
ball.init(clred,random(image1.width-50)+25, random(image1.height-50)+25,random(9)-4,random(9)-20,20);
ball.zeigedich;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ball.zeigedich;
image1.canvas.pixels[round(ball.x),round(ball.y)]:=clblack;
ball.bewegedich;
ball.zeigedich;
end;
initialization
randomize;
ball:=tball.create;
finalization
ball.destroy;
end.