frmmain.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. unit frmmain;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  6. Spin, StdCtrls;
  7. type
  8. { TForm1 }
  9. TForm1 = class(TForm)
  10. BColor: TColorButton;
  11. FEAngle: TFloatSpinEdit;
  12. Label1: TLabel;
  13. Label2: TLabel;
  14. Label3: TLabel;
  15. Label4: TLabel;
  16. PaintBox1: TPaintBox;
  17. SECorners: TSpinEdit;
  18. SEWidth: TSpinEdit;
  19. procedure BColorColorChanged(Sender: TObject);
  20. procedure FEAngleChange(Sender: TObject);
  21. procedure PaintBox1Click(Sender: TObject);
  22. procedure PaintBox1Paint(Sender: TObject);
  23. procedure SECornersChange(Sender: TObject);
  24. procedure SEWidthChange(Sender: TObject);
  25. private
  26. { private declarations }
  27. public
  28. { public declarations }
  29. end;
  30. var
  31. Form1: TForm1;
  32. implementation
  33. {$R *.lfm}
  34. { TForm1 }
  35. procedure TForm1.PaintBox1Click(Sender: TObject);
  36. begin
  37. end;
  38. procedure TForm1.FEAngleChange(Sender: TObject);
  39. begin
  40. PaintBox1.Invalidate;
  41. end;
  42. procedure TForm1.BColorColorChanged(Sender: TObject);
  43. begin
  44. Paintbox1.Invalidate;
  45. end;
  46. Procedure PaintPolygon(Canvas : TCanvas; AWidth,AHeight : Integer; ANumber : Integer; AStartAngle : Double; ALineWidth : Integer; AColor : TColor);
  47. Var
  48. CX,CY,R,I : Integer;
  49. P : Array of TPoint;
  50. A,Step : Double;
  51. begin
  52. Canvas.Pen.Color:=AColor;
  53. Canvas.Pen.Width:=aLineWidth;
  54. if ANumber<3 then
  55. exit;
  56. CX:=AWidth div 2;
  57. CY:=AHeight div 2;
  58. if aWidth<aHeight then
  59. R:=AWidth div 2
  60. else
  61. R:=AHeight div 2;
  62. SetLength(P,ANumber-1);
  63. A:=AStartAngle;
  64. Step:=(2*Pi)/ANumber;
  65. For I:=0 to ANumber-1 do
  66. begin
  67. P[i].X:=CX+Round(R*Cos(a));
  68. P[i].Y:=CY-Round(R*Sin(a));
  69. A:=A+Step;
  70. end;
  71. For I:=0 to ANumber-2 do
  72. Canvas.Line(P[I],P[I+1]);
  73. Canvas.Line(P[ANumber-1],P[0]);
  74. end;
  75. procedure TForm1.PaintBox1Paint(Sender: TObject);
  76. begin
  77. With PaintBox1 do
  78. PaintPolygon(Canvas,Width-1,Height-1,SECorners.Value,FEANgle.Value*Pi/180, SEWidth.Value, BColor.ButtonColor);
  79. end;
  80. procedure TForm1.SECornersChange(Sender: TObject);
  81. begin
  82. Paintbox1.INvalidate ;
  83. end;
  84. procedure TForm1.SEWidthChange(Sender: TObject);
  85. begin
  86. Paintbox1.INvalidate;
  87. end;
  88. end.