Recent Posts

Selamat datang di Coding Delphi Land Weblog kumpulan source code pemogram delphi

(Bukan maksud untuk menggurui tetapi marilah kita berbagi ilmu tuk perkembangan kemajuan teknologi kita

Minggu, 15 November 2009

Animated Graph

unit MainUnit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Label61: TLabel;
Shape1: TShape;
Bevel2: TBevel;
Panel1: TPanel;
Image3: TImage;
Shape2: TShape;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure PaintGraph;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
GraphL: integer;

implementation

{$R *.dfm}

procedure TForm1.PaintGraph; //Draw the Graph.
var
i, X: integer;
Memory: TmemoryStatus;
begin
Memory.dwLength:=sizeof(Memory);
GlobalMemoryStatus(Memory);
with image3 do
begin
canvas.brush.Color:=clblack;
canvas.pen.Color:=clgreen;
canvas.rectangle(0,0,width,height);
canvas.pen.Color:=clgreen;
canvas.MoveTo(0,15);
canvas.LineTo(width,15);
canvas.MoveTo(0,30);
canvas.LineTo(width,30);
canvas.MoveTo(0,45);
canvas.LineTo(width,45);
canvas.MoveTo(0,60);
canvas.LineTo(width,60);
canvas.MoveTo(0,75);
canvas.LineTo(width,75);
canvas.MoveTo(0,90);
canvas.LineTo(width,90);
X:=0;
for i:=0 to image3.Width do
begin
X:=X+17;
canvas.MoveTo(X,0);
canvas.LineTo(X, height);
end;
end;
GraphL := 370;
image3.Canvas.Pen.Width:=1;
image3.Canvas.MoveTo(GraphL ,strtoint(floattostr(int(Memory.dwAvailPhys/int(Memory.dwTotalPhys)*image3.Height)))); //Move the pen to Memory position
image3.Canvas.Pen.Color:=clYellow;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
PaintGraph;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
Memory: TMemoryStatus;
begin
Memory.dwLength := SizeOf(Memory);
GlobalMemoryStatus(Memory);
{You can even make the graph more attractive and impressive
by changing PenColor when the MemoryLoad changes, like:

Case Memory.dwMemoryLoad of
10..30: image3.Canvas.Pen.Color := ClLime;
31..50: image3.Canvas.Pen.Color := ClYellow;
51..70: image3.Canvas.Pen.Color := ClSomething;
71..100: image3.Canvas.Pen.Color := ClRed;
end; }
//----------------------------------
GraphL := GraphL+1;
image3.Canvas.LineTo(GraphL ,strtoint(floattostr(int((Memory.dwAvailPhys/Memory.dwTotalPhys)*image3.Height))));
image3.Left := image3.Left-1;
Label2.Caption := Floattostr(int((Memory.dwAvailPhys/ (1024.0 * 1024)))) + ' MB';
//----------------------------------
if image3.Left = -1500 then
begin
PaintGraph;
end;
end;

end.

0 komentar:

Posting Komentar