unit mUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
BtStart: TButton;
EdWdh: TEdit;
EdTreffer: TEdit;
EdPi: TEdit;
ImBild: TImage;
LaTropfenzahl: TLabel;
LaTreffer: TLabel;
LaPi: TLabel;
Lapii: TLabel;
Label1: TLabel;
TiLabel: TTimer;
BtClear: TButton;
BtClose: TButton;
procedure BtStartClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure TiLabelTimer(Sender: TObject);
procedure BtClearClick(Sender: TObject);
procedure BtCloseClick(Sender: TObject);
private
{ Private-Deklarationen }
IMLINKS: Boolean;
IMRECHTS: Boolean;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BtStartClick(Sender: TObject);
VAR z, x, y: REAL; i, Treffer, Tropfenzahl, x1, y1: Integer;
begin
Tropfenzahl:= StrToInt(Edwdh.Text);
Treffer:=0;
For i:=1
to Tropfenzahl
do
Begin
x:=random;
y:=random;
x1:=round (x*200);
y1:=round (y*200);
IF x*x + y*y <= 1
Then
Begin
Treffer:= Treffer + 1;
ImBild.Canvas.Pixels[x1,y1]:=clred;
End
Else
Begin
ImBild.Canvas.Pixels[x1,y1]:=clblue;
End;
End;
z:= (Treffer / Tropfenzahl) * 4;
EdTreffer.Text:=IntToStr(Treffer);
EdPi.Text:=FloatToStr(z);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
randomize;
ImBild.Canvas.Ellipse(-200,200,200,-200);
IMLINKS:= false;
IMRECHTS:= true;
IF IMRECHTS
THEN TiLabel.Enabled:=true;
end;
procedure TForm1.TiLabelTimer(Sender: TObject);
begin
IF IMRECHTS
THEN
Begin
Label1.Left:= Label1.Left + 1;
End;
IF Label1.Left >= 208
THEN
Begin
IMRECHTS:=false;
IMLINKS:=true;
End;
IF IMLINKS
THEN
Begin
Label1.Left:= Label1.Left - 1;
End;
IF Label1.Left <= 8
THEN
Begin
IMLINKS:=false;
IMRECHTS:=true;
End;
end;
procedure TForm1.BtClearClick(Sender: TObject);
begin
ImBild.Canvas.Rectangle(0,0,200,200);
ImBild.Canvas.Ellipse(-200,200,200,-200);
EdWdh.Text:='
';
EdTreffer.Text:='
';
EdPi.Text:='
';
end;
procedure TForm1.BtCloseClick(Sender: TObject);
begin
close
end;
end.