Draw random circles

Draw random circles

Draw random circles

This tutorial draws circles in random locations on screen. Form border style is set to NONE. At startup it automatically maximizes form to fit full screen size.

DownloadDownload This Tutorials

Bookmark:

Draw random circles

This tutorial demonstrate how to use Random function generate random numbers. Use canvas ellipse function to draw circles on the form. To auto generate circles randomly we use system timer.

Draw crosshair on form

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 Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - draw-random-circles.zipdraw-random-circles.zip
       File size: 4 KB, File type: zip
       Total downloads: 354, Upload date: February 10 - 2009

Leave a comment