unit Unit1;

{$mode objfpc}{$H+}

interface

uses

Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,

StdCtrls, ColorBox;

type

{ TForm1 }

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

ColorListBox1: TColorListBox;

ColorListBox2: TColorListBox;

Image1: TImage;

Timer1: TTimer;

Timer2: TTimer;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

procedure Timer1Timer(Sender: TObject);

procedure Timer2Timer(Sender: TObject);

private

{ private declarations }

public

{ public declarations }

end;

var

Form1: TForm1;

i,mx,my,r2,mx2,my2,vx2,vy2,Freix,Freiy,r1,mx1,my1,vx1,vy1:Integer; //types set as integer

r,x,y,vx,vy: Array [1..20] of integer; //array?

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);

begin

Timer1.Enabled:=true; //activates timer (makes ellipses move)

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

timer1.Enabled:=false; //deactivates timer (makes ellipses stop)

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

doublebuffered:=true; //reducing the lags

mx:=20; //setting values

my:=20;

mx2:=20;

vx2:=6;

r2:=25;

my2:=748;

vy2:=-6;

r1:=10;

mx1:=10;

my1:=10;

timer1.enabled:=false; //timer at beginning deactivated

for i := 1 to 20 do begin //???

r[i]:= 5;

x[i]:=random(image1.width);

y[i]:=random(image1.height);

vx[i]:=random(10)-5;

vy[i]:=random(8)-4;

image1.canvas.ellipse(x[i]-r[i],y[i] - r[i], x[i] + r[i], y[i]+r[i]);

end;

end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

timer2.enabled:=true

end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin

with image1.canvas do begin //creates the first ellipse

pen.color:=clblack ;

brush.color:=clblack;

ellipse(mx-r,my-r,mx+r,my+r);

mx:=mx+vx;

my:=my+vy;

pen.color:=$FFFFFF;

brush.color:=$FFFFFF;

ellipse(mx-r,my-r,mx+r,my+r);

end;

if my+r>=image1.Height //makes it bounce off the borders

thenvy:=-vy;

if mx+r>=image1.width

then vx:=-vx;

if my-r<0

then vy:=-vy;

if mx-r<0

then vx:=-vx;

with image1.canvas do begin //creates the second ellipse?

pen.color:=clblack;

brush.color:=clblack ;

image1.canvas.ellipse(mx2-r2,my2-r2,mx2+r2,my2+r2);

mx2:=mx2+vx2;

my2:=my2+vy2;

pen.color:=$FFFFFF;

brush.color:=$FFFFFF;

ellipse(mx2-r2,my2-r2,mx2+r2,my2+r2);

end;

if my2+r2>=image1.Height //makes the second ellipse bounce off the border?

then vy2:=-vy2;

if mx2+r2>=image1.width

then vx2:=-vx2;

if my2-r2<0

then vy2:=-vy2;

if mx2-r2<0

then vx2:=-vx2;

if

sqrt(sqr(mx-mx2)+sqr(my-my2))<=r+r2 //pythagoras to let them bounce off of each other when coming too close

then begin

Freix:=vx; //???

vx:=vx2;

vx2:=Freix;

Freiy:=vy;

vy:=vy2;

vy2:=Freiy;

end;

end;

procedure TForm1.Timer2Timer(Sender: TObject);

begin

with image1.canvas do begin //???

pen.color:=clblack ;

brush.color:=clblack;

ellipse(mx1-r1,my1-r1,mx1+r1,my1+r1);

pen.color:=$FFFFFF;

brush.color:=$FFFFFF;

ellipse(mx1-r1,my1-r1,mx1+r1,my1+r1);

end;

end;

end.