|
|
ffaebc |
unit Unit1;
|
|
|
ffaebc |
|
|
|
ffaebc |
{$mode objfpc}{$H+}
|
|
|
ffaebc |
|
|
|
ffaebc |
interface
|
|
|
ffaebc |
|
|
|
ffaebc |
uses
|
|
|
ffaebc |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
|
|
|
ffaebc |
|
|
|
ffaebc |
type
|
|
|
ffaebc |
|
|
|
ffaebc |
{ TForm1 }
|
|
|
ffaebc |
|
|
|
ffaebc |
TForm1 = class(TForm)
|
|
|
ffaebc |
procedure FormPaint(Sender: TObject);
|
|
|
ffaebc |
private
|
|
|
ffaebc |
{ private declarations }
|
|
|
ffaebc |
public
|
|
|
ffaebc |
{ public declarations }
|
|
|
ffaebc |
end;
|
|
|
ffaebc |
|
|
|
ffaebc |
var
|
|
|
ffaebc |
Form1: TForm1;
|
|
|
ffaebc |
|
|
|
ffaebc |
implementation
|
|
|
ffaebc |
|
|
|
ffaebc |
{$R *.lfm}
|
|
|
ffaebc |
|
|
|
ffaebc |
procedure Line(x1, y1, x2, y2: single);
|
|
|
ffaebc |
begin
|
|
|
ffaebc |
Form1.Canvas.MoveTo(round(x1), round(y1));
|
|
|
ffaebc |
Form1.Canvas.LineTo(round(x2), round(y2));
|
|
|
ffaebc |
end;
|
|
|
ffaebc |
|
|
|
ffaebc |
procedure Figure(x1, y1, x2, y2: single; level: integer);
|
|
|
ffaebc |
var
|
|
|
ffaebc |
ax, ay, bx, by, cx, cy: single;
|
|
|
ffaebc |
begin
|
|
|
ffaebc |
if level < 10 then begin
|
|
|
ffaebc |
ax := (x2 - x1)/3 + x1;
|
|
|
ffaebc |
ay := (y2 - y1)/3 + y1;
|
|
|
ffaebc |
|
|
|
ffaebc |
cx := (x1 - x2)/3 + x2;
|
|
|
ffaebc |
cy := (y1 - y2)/3 + y2;
|
|
|
ffaebc |
|
|
|
ffaebc |
bx := (ax + cx)/2 + (cy - ay)*sin(60/180*pi);
|
|
|
ffaebc |
by := (ay + cy)/2 - (cx - ax)*sin(60/180*pi);
|
|
|
ffaebc |
|
|
|
ffaebc |
Figure(x1, y1, ax, ay, level+1);
|
|
|
ffaebc |
Figure(ax, ay, bx, by, level+1);
|
|
|
ffaebc |
Figure(bx, by, cx, cy, level+1);
|
|
|
ffaebc |
Figure(cx, cy, x2, y2, level+1);
|
|
|
ffaebc |
end else begin
|
|
|
ffaebc |
Line(x1, y1, x2, y2);
|
|
|
ffaebc |
end;
|
|
|
ffaebc |
end;
|
|
|
ffaebc |
|
|
|
ffaebc |
{ TForm1 }
|
|
|
ffaebc |
|
|
|
ffaebc |
procedure TForm1.FormPaint(Sender: TObject);
|
|
|
ffaebc |
begin
|
|
|
ffaebc |
Figure(100, 400, 500, 400, 0);
|
|
|
ffaebc |
end;
|
|
|
ffaebc |
|
|
|
ffaebc |
end.
|
|
|
ffaebc |
|