private
FColors: array[0..99] of TColor;
---
implementation
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
// initiate random number generator
Randomize;
// init the colors to use
for i := 0 to 99 do
begin
// full color palette
// LColors[i] := RGBToColor(Random(256), Random(256), Random(256));
// optimized grey palette
FColors[i] := RGBToColor(255 - i * 255 div 100, 255 - i * 255 div 100, 255 - i * 255 div 100);
end;
// create the bitmap to draw on
FBitmap := TBitmap.Create;
// make it big
FBitmap.SetSize(Screen.Width, Screen.Height);
// choose a background color
FBitmap.Canvas.Brush.Color := clBlack;
// fill the background
FBitmap.Canvas.FillRect(0, 0, FBitmap.Width, FBitmap.Height);
// put it on screen
Image1.Picture.Bitmap.Assign(FBitmap);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i: Integer;
begin
// cache dots
for i := 0 to 1000 do
DrawDot(FBitmap, Random(FBitmap.Width), Random(FBitmap.Height), Random(10) + 2, FColors[Random(Length(FColors))]);
// show them
Image1.Picture.Bitmap.Assign(FBitmap);
end;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
Timer1.Enabled := False;
FBitmap.Free;
CloseAction := caFree;
end;
procedure TForm1.DrawDot(const ABitmap: TBitmap; const AX, AY, ADotSize: Integer; const AColor: TColor);
begin
// 2 is the minimum to draw an ellipse
if ADotSize < 2 then
Exit;
// set color
ABitmap.Canvas.Pen.Color := clBlack;
ABitmap.Canvas.Brush.Color := AColor;
// paint a dot in an individual size
ABitmap.Canvas.Ellipse(AX - ADotSize div 2, AY - ADotSize div 2, AX + ADotSize div 2, AY + ADotSize div 2);
end;