Draw random ellipse

Draw random ellipse

Draw random ellipse

This tutorial demonstrates how to create canvas form graphics randomly using system timer. To demonstrate this we are drawing some random ellipse with different colors on the form.

DownloadDownload This Tutorials

Bookmark:

Draw random ellipse

To draw ellipse we use Form Canvas.Ellipse function and Canvas.Brush.Color, Canvas.Pen.Color to set colors for ellipse.

Draw random ellipse on form

Use following timer event to draw random ellipse using random colors.

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Form1.Canvas.Brush.Color:=Random(DColor);
  Form1.Canvas.Pen.Color:=Random(DColor);      
  Form1.Canvas.Ellipse(Random(X),Random(Y),Random(X),Random(Y));
end; 

Set up the initial variable as follows

procedure TForm1.FormCreate(Sender: TObject);
begin
     X:=Form1.Width;
     Y:=Form1.Height;
     DColor:=1000000;
end; 

Set FormResize event to change X and Y coordinates

procedure TForm1.FormResize(Sender: TObject);
begin
     X:=Form1.Width;
     Y:=Form1.Height;
end; 

Download This Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - Random-Ellipse.zipRandom-Ellipse.zip
       File size: 4 KB, File type: zip
       Total downloads: 260, Upload date: February 10 - 2009

Leave a comment