代碼2:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormPaint(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
procedure TForm1.FormPaint(Sender: TObject);
const
pt: TPoint = (X:130; Y:130);
r = 120;
colors: array[0..0] of TGPColor = (aclRed);
var
g: TGPGraphics;
p: TGPPen;
path: TGPGraphicsPath;
pb: TGPPathGradIEntBrush;
pts: array[0..9] of TGPPoint;
radian: Single;
i,num: Integer;
rx: Single;
begin
for i := 0 to 9 do
begin
rx := r;
if Odd(i) then rx := r * (1- (Sqrt(5)-1)/2); {(Sqrt(5)-1)/2 是黃金分割點, 約為 0.618}
radian := i * (360/10) * (Pi/180);
pts[i].X := pt.X + Round(Sin(radian) * rx);
pts[i].Y := pt.Y - Round(Cos(radian) * rx);
end;
g := TGPGraphics.Create(Canvas.Handle);
path := TGPGraphicsPath.Create;
path.AddPolygon(PGPPoint(@pts), Length(pts));
pb:= TGPPathGradIEntBrush.Create(path);
num := Length(colors);
pb.SetSurroundColors(@colors, num);
pb.SetCenterColor(aclYellow);
{描個邊}
p := TGPPen.Create(aclYellow);
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.DrawPath(p, path);
g.FillPath(pb, path);
pb.Free;
path.Free;
p.Free;
g.Free;
end;
end.
窗體文件:object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClIEntHeight = 238
ClIEntWidth = 259
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
end