Delphi Tutorial


 

Draw random circles on screen

 

Download this example

               Use system timer to draw circles randomly. Set timer event as follows

procedure TForm1.Timer1Timer(Sender: TObject);
Var
      X, Y : Integer;
begin
      { Change the color }
      DColor:=DColor+1;
      Form1.Canvas.Brush.Color:=DColor;
      { Create random coordinates for circles }
      Randomize;
      X:=Random(Form1.Width);
      Y:=Random(Form1.Height);
      Form1.Canvas.Ellipse(X-15,Y-15,X+15,Y+15);
end;

 

      Since in this program we set form style to NONE, as a result you want see any form control buttons on top right. In order to close your program use following FormClick event.

procedure TForm1.FormClick(Sender: TObject);
begin
      Close;
end;

 

      DColor variable hold the color value for circle. So at the beginning set this one to starting color. It's a Long Integer number.

procedure TForm1.FormCreate(Sender: TObject);
begin
      DColor:=10000000;
end;

 

DOWNLOAD this example

Click here to download this complete example for Delphi 6. (File size 4KB)

 

 

Go top

 


Previous Page First Page Next Page
 
Copyright © 2002 digitalcoding.com. All rights reserved.