home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / chap09 / ellipses / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  1.4 KB  |  69 lines

  1. unit Main;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: ELLIPSES }
  5.  
  6. { Program to show how to use the Canvas object to
  7.   draw ellipses to the screen. Also demonstrates
  8.   a few facts about the Delphi coordinate system,
  9.   and about accessing the colors available on your
  10.   system.
  11.  
  12.   Some cosmetic issues:
  13.     Panel added at top of screen, and controls placed
  14.     on panel. A second panel used instead of a label. }
  15.  
  16.  
  17.  
  18. interface
  19.  
  20. uses
  21.   WinTypes, WinProcs, SysUtils,
  22.   Classes, Graphics, StdCtrls,
  23.   Controls, Printers, Forms, ExtCtrls;
  24.  
  25. type
  26.   TForm1 = class(TForm)
  27.     Panel1: TPanel;
  28.     Start: TButton;
  29.     Panel2: TPanel;
  30.     Edit1: TEdit;
  31.     procedure BStartClick(Sender: TObject);
  32.     procedure FormCreate(Sender: TObject);
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure TForm1.BStartClick(Sender: TObject);
  43. var
  44.   Borders: Integer;
  45.   i, j, x, y: Integer;
  46.   R: TRect;
  47. begin
  48.   j := 0;
  49.   R := GetClientRect;
  50.   x := R.Right;
  51.   Borders := Panel1.Height;
  52.   y := R.Bottom - Borders;
  53.   i := StrToInt(Edit1.Text);
  54.   while j < i do begin
  55.     Canvas.Ellipse(Random(x), Random(y) + Borders, Random(x), Random(y) + Borders);
  56.     Canvas.Brush.Color := RGB(Random(255), Random(255), Random(255));
  57.     inc(j);
  58.   end;
  59.   Edit1.SetFocus;
  60.   Edit1.Text := '';
  61. end;
  62.  
  63. procedure TForm1.FormCreate(Sender: TObject);
  64. begin
  65.   Edit1.Text := '100';
  66. end;
  67.  
  68. end.
  69.