下面的代码是在“卷起千堆雪tyn”在ID:930660中发布的代码中修改而成。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Counter :Byte;
implementation
{$R *.DFM}
procedure MovingDots(X,Y: Integer; TheCanvas: TCanvas); stdcall;
var
r:TRect;
begin
r.Left:=x-1;
r.Right:=x+1;
r.Top:=y-1;
r.Bottom:=y+1;
Counter := Counter shl 1; // Shift the bit left one
if Counter = 0 then Counter := 1; // If it shifts off left, reset it
if (Counter and 224) > 0 then // Are any of the left 3 bits set?
begin
//TheCanvas.Pixels[X,Y] :=clBtnFace // Erase the pixel
TheCanvas.Brush.Color:=clBtnFace;
TheCanvas.FillRect(r);
end
else
begin
//TheCanvas.Pixels[X,Y] :=clBlack; // Draw the pixel
TheCanvas.Brush.Color:=clGreen;
TheCanvas.FillRect(r);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
LineDDA(30,30,200,30,@MovingDots,LongInt(Canvas));
LineDDA(200,30,200,150,@MovingDots,LongInt(Canvas));
LineDDA(200,150,30,150,@MovingDots,LongInt(Canvas));
LineDDA(30,150,30,30,@MovingDots,LongInt(Canvas));
end;
end.