谢谢,用DELPHIC改一个非常简单分形图,我是个新手,怎么也改不出来,都改了一天了5
急~~~用DELPHIC改一个简单分形图,怎么也改不出来,改了一天了还是没改出 改的要求是:按一下按钮画出一条直线,再按一下那条直线下平均分成三段,去掉中间那段,依次类推,就这样一直 递归下去,这是一个递归算法 下面这个原程序 unit contor; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; a, b, c, d :real; n , m , r , p, q ,k: Integer; x , y , x0 , y0 :real; implementation {$R *.dfm} procedure cantor(ax :real;ay : real; bx :real; by :real); var c: Integer; //c 为判断小量,当(bx - ax) < c 时,堆栈释放 d : Integer; //d为两层线段之间的距离 cx,cy,dx,dy :real; begin c := 1; d := 20; If (bx - ax) < c Then begin Form1.Canvas.MoveTo(Round(ax),Round(ay)); Form1.Canvas.LineTo(Round(bx),Round(by)); end Else begin Form1.Canvas.MoveTo(Round(ax),Round(ay)); Form1.Canvas.LineTo(Round(bx),Round(by)); cx := ax + (bx - ax) / 3; cy := ay + d; dx := bx - (bx - ax) / 3; dy := by + d; ay := ay + d; by := by + d; cantor(ax, ay, cx, cy); cantor(dx, dy, bx, by); end; End ; procedure TForm1.Button1Click(Sender: TObject); begin cantor(100, 40, 500, 40); end; procedure TForm1.FormCreate(Sender: TObject); begin end; |