1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TForm1 = class(TForm) Image1: TImage; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private public end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure Sierpinski(x1, y1, x2, y2, x3, y3: Extended; t: Integer); begin if t > 0 then begin with form1.Image1.Canvas do begin MoveTo(Round(x1), Round(y1)); LineTo(Round(x2), Round(y2)); LineTo(Round(x3), Round(y3)); LineTo(Round(x1), Round(y1)); end; Sierpinski(x1, y1, x1 + (x3 - x1) / 4, ((y1 - y2) / 2) + y2, x2, y1, t - 1); Sierpinski(x1 + (x3 - x1) / 4, ((y1 - y2) / 2) + y2, x2, y2, x1 + (x3 - x1) / 4 * 3, ((y1 - y2) / 2) + y2, t - 1); Sierpinski(x2, y1, x1 + (x3 - x1) / 4 * 3, ((y1 - y2) / 2) + y2, x3, y3, t - 1); end; end;
procedure TForm1.Button1Click(Sender: TObject); var i: integer; begin for i:= 1 to 8 do begin image1.Canvas.rectangle(0, 0, image1.Width, image1.Height); Sierpinski(20, 350, 220, 50, 420, 350, i); application.processmessages; sleep(1000); end; end;
procedure TForm1.FormCreate(Sender: TObject); begin doublebuffered:= true; end;
end. |