type
TValueArray =
array of Cardinal;
var
ValueArray: TValueArray;
implementation
{$R *.dfm}
procedure PaintGraph(Bmp: TBitmap; Color: TColor; ValueArray: TValueArray);
var
rect: TRect;
i: Integer;
len: Integer;
begin
Bmp.Canvas.Brush.Color := clWhite;
rect.Top := 0;
rect.Left := 0;
rect.Right := Bmp.Width;
rect.Bottom := Bmp.Height;
Bmp.Canvas.FillRect(rect);
len := length(ValueArray);
Bmp.Canvas.Pen.Color := Color;
for i := 0
to Bmp.Width - 1
do
begin
Bmp.Canvas.MoveTo(i, Bmp.Height);
Bmp.Canvas.LineTo(i, Bmp.Height-ValueArray[len-i-1]);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OffScreenBmp := TBitmap.Create;
OffScreenBmp.Width := ClientWidth;
OffScreenBmp.Height := ClientHeight;
SetLength(ValueArray, ClientWidth);
Index := length(ValueArray) - 1;
Randomize;
Timer1.Interval := 50;
DoubleBuffered := True;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(OffScreenBmp);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
BitBlt(Canvas.Handle, 0, 0, ClientWidth, ClientHeight, OffScreenBmp.Canvas.Handle, 0, 0, SRCCOPY);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i: Integer;
begin
ValueArray[
Index] := random(ClientHeight);
//GetCPUUsage * 10;
Dec(
Index);
if Index = 0
then
begin
for i := 0
to length(ValueArray) - 1
do
ValueArray[i] := 0;
PaintGraph(OffScreenBmp, clRed, ValueArray);
Repaint;
Index := length(ValueArray)-1;
end;
PaintGraph(OffScreenBmp, clRed, ValueArray);
Repaint;
end;