本例效果图:
![](https://www.cnblogs.com/images/cnblogs_com/del/134145/o_85274.gif)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const {把五环的颜色定义为常量数组}
Colors: array[0..4] of TColor = (clBlue, clBlack, clRed, clYellow, clGreen);
var
ci: Integer; {用作颜色序号}
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := '重绘';
Self.Color := clWhite;
Canvas.Pen.Width := 5;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
r = 30; {圆半径}
var
radian: Double; {记录弧度; Sin、Cos 函数需要弧度做参数; 弧度 = 角度 * Pi/180}
i,a,b: Integer;
begin
Canvas.MoveTo(X, Y-r);
Canvas.Pen.Color := Colors[ci];
for i := 1 to 360 do
begin
radian := i * (Pi/180); {获取弧度}
a := X + Round(Sin(radian) * r); {用 Sin 函数获取横坐标}
b := Y - Round(Cos(radian) * r); {用 Cos 函数获取纵坐标}
Canvas.LineTo(a, b); {绘制}
Application.ProcessMessages; {不要影响其他操作}
Sleep(3); {等 3 毫秒}
end;
Inc(ci);
if ci = 5 then ci := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ci := 0;
Repaint;
end;
end.
System 单元下的公用函数目录