unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
BGRABitmap, BGRABitmapTypes;
type
{ TForm1 }
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Panel1: TPanel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
bmp: TBGRABitmap;
tick: Double;
count: Integer;
procedure DrawFrame;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ Helper function to convert HSL to TColor }
function HSLToColor(H: integer; S, L: Single): TBGRAPixel;
var
hsla: THSLAPixel;
begin
hsla.hue := Round((H mod 360) / 360 * 65535);
hsla.saturation := Round(S * 65535);
hsla.lightness := Round(L * 65535);
hsla.alpha := 65535;
Result := HSLAToBGRA(hsla);
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
bmp := TBGRABitmap.Create(PaintBox1.Width, PaintBox1.Height, BGRABlack);
tick := 0;
count := 100;
Timer1.Enabled := True;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
bmp.SetSize(PaintBox1.Width, PaintBox1.Height);
bmp.Fill(BGRABlack);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
tick += 0.02;
DrawFrame;
end;
procedure TForm1.DrawFrame;
var
i: Integer;
rapport, t: Double;
cx, cy, x, y: Single;
hueColor: TBGRAPixel;
begin
bmp.FillRect(0, 0, bmp.Width, bmp.Height, BGRA(0, 0, 0, 25), dmDrawWithTransparency);
cx := bmp.Width / 2;
cy := bmp.Height / 2;
for i := 0 to count - 1 do
begin
rapport := i / count;
x := cx + (bmp.Width / 3) * sin(tick + rapport * Pi * 2);
y := cy + (bmp.Height / 3) * sin(tick + rapport * Pi );
hueColor := HSLToColor(Round(rapport * 360), 0.8, 0.5);
bmp.FillEllipseAntialias(x, y, 2, 2, hueColor);
end;
bmp.Draw(PaintBox1.Canvas, 0, 0, True);
end;
end.