procedure TForm1.Button3Click(Sender: TObject);
var
x, y: integer;
x1, y1, x2, y2: integer;
nindex, nMaxindex: integer;
nWait: integer;
index, lastIndex: integer;
Step: integer;
begin
SetROP2(Canvas.Handle, R2_NOT);//与当前颜色相反
canvas.Brush.Style := bsClear;
Canvas.Pen.Mode := pmNotXor; //画两次就清除
x := trunc(width / 2);
y := trunc(height / 2);
Step := 20; //方框间距
index := 1;
lastindex := trunc((width - x) / step);
nWait := 30; //时间间隔
nMaxindex := 100; //执行次数
nindex := 1;
repeat
index := 1;
lastindex := trunc((width - x) / step);
repeat
x1 := x - trunc(index * Step);
y1 := y - trunc(index * Step);
x2 := x + trunc(index * Step);
y2 := y + trunc(index * Step);
canvas.Rectangle(x1, y1, x2, y2);
sleep(nwait);
inc(index);
until index > lastIndex;
index := 1;
repeat
x1 := x - trunc(lastIndex * Step);
y1 := y - trunc(lastIndex * Step);
x2 := x + trunc(lastIndex * Step);
y2 := y + trunc(lastIndex * Step);
canvas.Rectangle(x1, y1, x2, y2);
sleep(nwait);
dec(lastIndex);
until index > lastIndex;
inc(nIndex);
until nindex > nMaxindex;
end;
看对你有没有帮助!