unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Spin,
BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes;
const
xx = 42;
yy = 31;
Cell_Size = 15;
Chr_Count = 2; // Only Char 0 -1 , ascii code 48=0 49=1
type
{ TForm1 }
TForm1 = class(TForm)
Panel1: TPanel;
Red_Spin: TSpinEdit;
Green_Spin: TSpinEdit;
Blue_Spin: TSpinEdit;
Vscreen: TBGRAVirtualScreen;
Timer1: TTimer;
procedure VScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
Buff: TBGRABitmap;
CharBitmaps: array[0..Chr_Count-1] of TBGRABitmap; // bitmap table 0 to charcount
CharMatrix: array[0..xx, 0..yy] of Byte;
ChrCol : TBGRAPixel;
procedure GenChar;
procedure UpdateCharBitmaps;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
Randomize;
Buff := TBGRABitmap.Create(Vscreen.Width, Vscreen.Height);
for i := 0 to Chr_Count-1 do
begin
CharBitmaps[i] := TBGRABitmap.Create(Cell_Size, Cell_Size);
CharBitmaps[i].FontHeight := 15;
CharBitmaps[i].FontName := 'Courier New';
CharBitmaps[i].FontStyle := [fsBold];
end;
GenChar;
ChrCol := BGRA(Red_Spin.Value, Green_Spin.Value, Blue_Spin.Value);
UpdateCharBitmaps;
end;
procedure TForm1.UpdateCharBitmaps;
var
i, textW, textH: Integer;
charToUse: Char;
begin
for i := 0 to Chr_Count-1 do
begin
CharBitmaps[i].Fill(BGRABlack);
charToUse := Chr(48 + i); //0-1
// OR (A-Z from Ascii code 65 To Chr_Count ):
// charToUse := Chr(65 + i);
textW := CharBitmaps[i].TextSize(charToUse).cx;
textH := CharBitmaps[i].TextSize(charToUse).cy;
if (charTouse='0') then
CharBitmaps[i].TextOut((Cell_Size - textW) div 2,(Cell_Size - textH) div 2,charToUse,ChrCol);
if (charTouse='1') then
CharBitmaps[i].TextOut((Cell_Size - textW) div 2,(Cell_Size - textH) div 2,charToUse,BGRA(255,255,255));
end;
end;
procedure TForm1.GenChar;
var
i, j: Integer;
begin
for i := 0 to xx do
for j := 0 to yy do
CharMatrix[i, j] := Random(Chr_Count);
end;
procedure TForm1.VScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
var
i, j, x, y: Integer;
begin
Buff.Fill(BGRABlack);
for i := 0 to xx do
for j := 0 to yy do
begin
x := i * Cell_Size;
y := j * Cell_Size;
Buff.PutImage(x, y, CharBitmaps[CharMatrix[i, j]], dmDrawWithTransparency);
end;
Bitmap.PutImage(0, 0, Buff, dmSet);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
GenChar;
// optimisation maximale
ChrCol := BGRA(Red_Spin.Value, Green_Spin.Value, Blue_Spin.Value);
UpdateCharBitmaps;
Vscreen.RedrawBitmap;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
i: Integer;
begin
Buff.Free;
for i := 0 to Chr_Count-1 do
CharBitmaps[i].Free;
end;
end.