画动态多边型
【打印文章】
type
TPtArray = array[0..0] of TPoint;
PPtArray = ^TPtArray;
procedure DrawDynamicPolyArray(NumPoints : integer;
Canvas : TCanvas);
var
p : PPtArray;
i : integer;
begin
{$IFOPT R+}
{$DEFINE CKRANGE}
{$R-}
{$ENDIF}
GetMem(p, sizeof(TPoint) * NumPoints);
Randomize;
for i := 0 to (NumPoints -1) do begin
p^[i].x := Random(Form1.Width);
p^[i].y := Random(Form1.Height);
end;
Polygon(Canvas.Handle, p, NumPoints);
FreeMem(p, sizeof(TPoint) * NumPoints);
{$IFDEF CKRANGE}
{$UNDEF CKRANGE}
{$R+}
{$ENDIF}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Canvas.Brush.Color := clWhite;
Form1.Canvas.FillRect(Rect(0, 0, Form1.Width, Form1.Height));
Form1.Canvas.Brush.Color := clRed;
DrawDynamicPolyArray(SpinEdit1.Value,
Form1.Canvas);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SpinEdit1.MinValue := 2;
SpinEdit1.MaxValue := 1000;
SpinEdit1.Value := 100;
end;
end.
TPtArray = array[0..0] of TPoint;
PPtArray = ^TPtArray;
procedure DrawDynamicPolyArray(NumPoints : integer;
Canvas : TCanvas);
var
p : PPtArray;
i : integer;
begin
{$IFOPT R+}
{$DEFINE CKRANGE}
{$R-}
{$ENDIF}
GetMem(p, sizeof(TPoint) * NumPoints);
Randomize;
for i := 0 to (NumPoints -1) do begin
p^[i].x := Random(Form1.Width);
p^[i].y := Random(Form1.Height);
end;
Polygon(Canvas.Handle, p, NumPoints);
FreeMem(p, sizeof(TPoint) * NumPoints);
{$IFDEF CKRANGE}
{$UNDEF CKRANGE}
{$R+}
{$ENDIF}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Canvas.Brush.Color := clWhite;
Form1.Canvas.FillRect(Rect(0, 0, Form1.Width, Form1.Height));
Form1.Canvas.Brush.Color := clRed;
DrawDynamicPolyArray(SpinEdit1.Value,
Form1.Canvas);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SpinEdit1.MinValue := 2;
SpinEdit1.MaxValue := 1000;
SpinEdit1.Value := 100;
end;
end.
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】