1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Déclarations privées }
return,direct:boolean;
R,sol,a,x,y:integer;
vox,voy,v,t,ttotal,tchute,yo,amortissement:double;
pt:Tpoint;
FOND:Tbitmap;
procedure rebondsouris;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender: TObject);
begin
fond.Free;
end;
procedure TForm1.rebondsouris;
begin
x:=round(vox*ttotal)+R;
if (y<=sol-R-20) and (a>0) then return:=false else return:=true;
if not return then
begin
y:=round(0.5*a*sqr(t)+yo); //chute libre
voy:=a*t;
tchute:=t;
end
else
begin
a:=-abs(a);
y:=round(sol-(0.5*a*sqr((t-tchute))+amortissement*voy*(t-tchute)))-20-R;
v:=a*(t-tchute)+voy;
if v<=0 then
begin
a:=abs(a);
t:=0;
yo:=y;
end;
end;
t:=t+0.01;
If (x>=fond.Width-R) then direct:=true;
if direct then ttotal:=ttotal-0.01 else ttotal:=ttotal+0.01;
if x<R Then direct:=false;
pt:=point(round(x),round(y));
With Fond.canvas do
begin;
Pen.Width:=4;
brush.color:=clblack;
Fillrect(RECT(0,0,fond.Width,fond.Height));
Brush.Color:=clgreen;
fillrect(rect(0,Fond.height-20,Fond.width,Fond.height));
pen.Color:=clyellow;
brush.Color:=clyellow;
ellipse(pt.X-R,pt.Y-R,pt.X+R,pt.Y+R);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Width:=screen.Width;
height:=screen.Height;
position:=poscreencenter;
formstyle:=fsstayontop;
Return:=false;
R:=20;
a:=3000;
amortissement:=0.85;
Fond:=Tbitmap.Create;
with fond do
begin
width:=Form1.ClientWidth;
height:=Form1.ClientHeight;
end;
yo:=R;
vox:=255;
Pt:=point(20,20);
sol:=Fond.Height;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
rebondsouris;
canvas.Draw(0,0,fond);
end;
end. |
Partager