unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, NativeFastCanvas,
Windows, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
FNativeFastCanvas: TNativeFastCanvas;
FAnimTimer: Integer;
public
procedure NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer); // Main Loop Draw
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
// Création du composant TNativeFastCanvas
FNativeFastCanvas := TNativeFastCanvas.Create(Self);
with FNativeFastCanvas do
begin
Parent := Self;
Align := alClient; // Full Screen
// SetBounds(50,5,800,600); // or déclare screen size
BackgroundColor := RGB(0, 0, 32); // Bleu foncé style Amiga
OnNativePaint := @NativeFastCanvas1NativePaint;
end;
FAnimTimer := 0;
end;
procedure TForm1.NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC;
Pixels: PFastPixel; Ww, Hh: Integer);
var
FastCanvas: TNativeFastCanvas;
i, x, y: Integer;
CenterX, CenterY: Integer;
Radius: Integer;
Col: TColor;
begin
FastCanvas := TNativeFastCanvas(Sender);
CenterX := Ww div 2;
CenterY := Hh div 2;
// **** DÉMONSTRATION DES PRIMITIVES Dessin de BASE + Etoiles Triangle Etc .. ***
// Stars
FastCanvas.Star(CenterX, CenterY, 30, 12, 5, FAnimTimer * 0.02, RGB(255, 255, 0));
FastCanvas.Star(CenterX, CenterY, 60, 25, 5, FAnimTimer * 0.03, RGB(255, 255, 0));
FastCanvas.Star(CenterX, CenterY, 100, 40, 5, FAnimTimer * 0.04, RGB(255, 255, 0));
FastCanvas.Star(CenterX, CenterY, 150, 60, 5, FAnimTimer * 0.01, RGB(255, 255, 0));
// Pixels Random !
for i := 0 to 199 do // or 19999+1 pixels
begin
x := Random(Ww);
y := Random(Hh);
// FastCanvas.SetPixel(x, y, RGB(255, 255, 255));
end;
// H Lines Copper bars style Amiga
for i := 0 to 15 do //16 lines
begin
y := 50 + i * 4; // saut 4 pixel Y
Col := RGB(255 - i * 15, i * 16, 128 + i * 8);
FastCanvas.HorizontalLine(20, Ww - 20, y, Col);
end;
// Vertical Lines
for i := 0 to 20 do
begin
x := 100 + i * 20;
FastCanvas.VerticalLine(x, 200, 280, RGB(0, 255, 100));
end;
// Diagonal Lines
for i := 0 to 11 do
begin
x := CenterX + Round(100 * Cos((i * 30 + FAnimTimer * 2) * Pi / 180));
y := CenterY + Round(100 * Sin((i * 30 + FAnimTimer * 2) * Pi / 180));
Col := RGB(255, 128 + i * 10, 0);
FastCanvas.Line(CenterX, CenterY, x, y, Col);
end;
// Rectangle The Big
FastCanvas.Rectangle(10, 10, Ww - 10, Hh - 10, RGB(255, 255, 255));
FastCanvas.Rectangle(10+1, 10+1, Ww - 9, Hh - 9, RGB(200, 200, 200));
// Rectangles Filled
for i := 0 to 15 do
begin
x := 50 + i * 50;
Col := RGB(i * 32, 255 - i * 32, 128);
FastCanvas.FillRect(x, Hh - 80, x + 40, Hh - 30, Col);
end;
// Circle
Radius := 80 + Round(20 * Sin(FAnimTimer * 0.1));
FastCanvas.Circle(CenterX - 150, CenterY, Radius, RGB(255, 0, 255));
// Circle Filled
Radius := 60 + Round(10 * Sin(FAnimTimer * 0.15));
Col := RGB(255, 255 - Round(50 * Sin(FAnimTimer * 0.1)), 0);
FastCanvas.FillCircle(CenterX + 150, CenterY, Radius, Col);
// Ellipse
FastCanvas.Ellipse(CenterX, CenterY, 200, 120, RGB(0, 255, 255));
// Ellipse Filled
x := CenterX + Round(180 * Cos(FAnimTimer * 0.05));
y := CenterY + Round(100 * Sin(FAnimTimer * 0.05));
FastCanvas.FillEllipse(x, y, 25, 15, RGB(0, 200, 100));
// Get Pixel then if not back color SetPixel mirror FX
Col := FastCanvas.GetPixel(CenterX, CenterY);
if Col <> RGB(0, 0, 32) then
begin
FastCanvas.SetPixel(CenterX + 10, CenterY + 10, Col);
FastCanvas.SetPixel(CenterX - 10, CenterY - 10, Col);
end;
// Simple Plasma Fx 100*100
for y := 320 to 420 do
for x := 20 to 120 do
begin
i := Round(128 + 127 * Sin((x + FAnimTimer) * 0.1) * Cos((y + FAnimTimer) * 0.08));
Col := RGB(i, 255 - i, 128);
FastCanvas.SetPixel(x, y, Col);
end;
// Triangle animation
FastCanvas.Triangle(350, 450, 300, 350, 150, 450, RGB(255, 0, 0));
// Triangle animation
x := CenterX + Round(80 * Cos(FAnimTimer * 0.1));
y := CenterY + Round(80 * Sin(FAnimTimer * 0.1));
FastCanvas.Triangle(CenterX, CenterY - 60, x, y, CenterX - 40, CenterY + 40, RGB(0, 255, 0));
// Triangles effet kaleidoscope fx
for i := 0 to 5 do
begin
x := CenterX + Round(100 * Cos(i * 60 * Pi / 180 + FAnimTimer * 0.05));
y := CenterY + Round(100 * Sin(i * 60 * Pi / 180 + FAnimTimer * 0.05));
Col := RGB(255, i * 40, 255 - i * 40);
FastCanvas.Triangle(CenterX, CenterY, x, y,
CenterX + Round(50 * Cos((i * 60 + 30) * Pi / 180 + FAnimTimer * 0.05)),
CenterY + Round(50 * Sin((i * 60 + 30) * Pi / 180 + FAnimTimer * 0.05)), Col);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Inc(FAnimTimer);
FNativeFastCanvas.Invalidate;
end;
// EXIT Destroy canvas !
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(FNativeFastCanvas) then FNativeFastCanvas.Free;
end;
end.