unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Image1: TImage;
Timer1: TTimer;
Timer2: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
public
end;
var
Form1: TForm1;
mx, my, r, vx, vy, pyth1, pyth2 : integer;
mx1 : array[1..19] of integer;
my1 : array[1..19] of integer;
r1 : array[1..19] of integer;
vx1 : array[1..19] of integer;
vy1 : array[1..19] of integer;
c : integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.enabled := true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.enabled := false;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
//zurücksetzen des programms
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize; //lässt alle zahlen neu berechnen
doublebuffered := true; //reduziert lags
mx := 10; //legt werte fest
my := 10;
r := 15;
vx := 7;
vy := 7;
timer1.enabled := false; //deaktiviert ersten timer
for c := 1 to 19 do begin //array
mx1[c] := random(951);
my1[c] := random(656);
r1[c] := random(15);
vx1[c] := random(15);
vy1[c] := random(15);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
with image1.canvas do begin
pen.color := clblack;
brush.color := clblack;
ellipse(mx-r, my-r, mx+r, my+r);
mx:=mx+vx;
my:=my+vy;
pen.color:=clblue;
brush.color:=clblue;
ellipse(mx-r, my-r, mx+r, my+r);
for c:= 1 to 19 do begin
pen.color := clblack;
brush.color := clblack;
ellipse(mx1[c]-r1[c], my1[c]-r1[c], mx1[c]+r1[c], my1[c]+r1[c]);
mx1[c]:=mx1[c]+vx1[c];
my1[c]:=my1[c]+vy1[c];
pen.color:= clblue;
brush.color:= clblue;
ellipse(mx1[c]-r1[c], my1[c]-r1[c], mx1[c]+r1[c], my1[c]+r1[c]);
end;
end;
if my+r>=image1.height //lässt von den wänden abprallen
then vy:= -vy;
if mx+r>=image1.width
then vx:=-vx;
if my-r<0
then vy:=-vy;
if mx-r<0
then vx:=-vx;
for c:= 1 to 19 do begin
if my1[c]+r1[c]>=image1.height //lässt von den wänden abprallen
then vy1[c]:= -vy1[c];
if mx1[c]+r1[c]>=image1.width
then vx1[c]:=-vx1[c];
if my1[c]-r1[c]<0
then vy1[c]:=-vy1[c];
if mx1[c]-r1[c]<0
then vx1[c]:=-vx1[c];
if
sqrt(sqr(mx-mx1[c])+sqr(my-my1[c]))<=r+r1[c] //pythagoras um die kugeln bei berührung von sich abprallen zu lassen
then begin //kehrt Geschwindigkeiten um
pyth1:=vx;
vx:=vx1[c];
vx1[c]:=pyth1;
pyth2:=vy;
vy:=vy1[c];
vy1[c]:=pyth2;
end;
end;
end;
end.