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
   | unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;
 
type
 
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;
 
  TFlocon = class
    x, y, vitesse : integer;
    constructor Create(px, py, pvitesse : integer);
  end;
 
var
  Form1: TForm1;
  flocons : array[1..500] of TFlocon;
 
implementation
 
{$R *.dfm}
 
{ TFlocon }
 
constructor TFlocon.Create(px, py, pvitesse: integer);
begin
  x := px;
  y := py;
  vitesse := pvitesse;
end;
 
{ TForm1 }
 
procedure TForm1.FormCreate(Sender: TObject);
var
  i : integer;
begin
  for i := low(flocons) to high(flocons) do
    flocons[i] := TFlocon.Create(random(paintbox1.Width),random(paintbox1.Height),random(3));
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
var
  i : integer;
begin
  for i := low(flocons) to high(flocons) do
    flocons[i].Free;
end;
 
procedure TForm1.Timer1Timer(Sender: TObject);
var
  i : integer;
begin
  with paintbox1 do
  begin
    Canvas.FillRect(ClientRect);
    for i := low(flocons) to high(flocons) do
    begin
      flocons[i].x := flocons[i].x + 1 - random(3);
      flocons[i].y := flocons[i].y + 1 + flocons[i].vitesse;
      Canvas.MoveTo(flocons[i].x,flocons[i].y);
      Canvas.LineTo(flocons[i].x+1,flocons[i].y+1);
      if (flocons[i].y > paintbox1.Height) then
      begin
        flocons[i].x := random(paintbox1.Width);
        flocons[i].y := 0;
      end;
    end;
  end;
end;
 
end. | 
Partager