2

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;

是否有将动画椭圆添加到矩形角以获取夹点的功能?

4

1 回答 1

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.

在此处输入图像描述

于 2013-02-25T17:41:13.773 回答