我正在使用LineDDA
绘制动画选区:
procedure TFormMain.DrawMarchingAnts;
begin
AMarchingAntsCounter := AMarchingAntsCounterStart;
// Use LineDDA to draw each of the 4 edges of the rectangle
LineDDA(AMarchingAntsPointA.X, AMarchingAntsPointA.Y, AMarchingAntsPointB.X, AMarchingAntsPointA.Y,
@MarchingAnts, LongInt(
AMarchingAntsCanvas));
LineDDA(AMarchingAntsPointB.X, AMarchingAntsPointA.Y, AMarchingAntsPointB.X, AMarchingAntsPointB.Y,
@MarchingAnts, LongInt(
AMarchingAntsCanvas));
LineDDA(AMarchingAntsPointB.X, AMarchingAntsPointB.Y, AMarchingAntsPointA.X, AMarchingAntsPointB.Y,
@MarchingAnts, LongInt(
AMarchingAntsCanvas));
LineDDA(AMarchingAntsPointA.X, AMarchingAntsPointB.Y, AMarchingAntsPointA.X, AMarchingAntsPointA.Y,
@MarchingAnts, LongInt(
AMarchingAntsCanvas));
if AMarchingAntsPointB.X > AMarchingAntsPointA.X then
ARubberbandVisible := True
else
ARubberbandVisible := False;
end;
是否有一个函数可以将动画椭圆添加到矩形的角点以获取抓点?
答案 0 :(得分:5)
你想要一个动画“行军蚂蚁”圈子?然后创建自定义笔样式。例如,如下:
unit Unit1;
interface
uses
Windows, Classes, Graphics, Controls, Forms, ExtCtrls, Math;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormPaint(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FMarkBrush: LOGBRUSH;
FMarkPen: HPEN;
FPenStyle: array[0..1] of Integer;
FStartAngle: Single;
end;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FPenStyle[0] := 4;
FPenStyle[1] := 4;
FMarkBrush.lbStyle := BS_SOLID;
FMarkBrush.lbColor := ColorToRGB(clBlue);
FMarkPen := ExtCreatePen(PS_GEOMETRIC or PS_USERSTYLE, 1, FMarkBrush, 2,
@FPenStyle);
Canvas.Pen.Handle := FMarkPen;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
X: Integer;
Y: Integer;
begin
Canvas.FillRect(Rect(0, 0, 50, 50));
X := Round(25 * (1 + Cos(FStartAngle)));
Y := Round(25 * (1 + Sin(FStartAngle)));
Canvas.Arc(0, 0, 50, 50, X, Y, X, Y);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
FStartAngle := FStartAngle + DegToRad(5);
Invalidate;
end;
end.