Sub Fractal_01(X,Y,L,n) Dim a,b,c,d,E a = Array(X+L/2,Y+L/2,0) b = Array(X-L/2,Y+L/2,0) c = Array(X-L/2,Y-L/2,0) d = Array(X+L/2,Y-L/2,0) If n > 0 Then Call Rhino.AddSrfPt(Array(a,b,c,d)) E = 0.75 * L Call Fractal_01(X+E,Y+E,L/2,n-1) Call Fractal_01(X-E,Y+E,L/2,n-1) Call Fractal_01(X-E,Y-E,L/2,n-1) Call Fractal_01(X+E,Y-E,L/2,n-1) End If End Sub
基本上我們要將程式碼先拆成兩部份來看.
Call Rhino.EnableRedraw(False) Call Fractal_01(0,0,30,2) Call Rhino.EnableRedraw(True) Sub Fractal_01(X,Y,L,n) Dim a,b,c,d,E a = Array(X+L/2,Y+L/2,0) b = Array(X-L/2,Y+L/2,0) c = Array(X-L/2,Y-L/2,0) d = Array(X+L/2,Y-L/2,0) If n > 0 Then Call Rhino.AddSrfPt(Array(a,b,c,d)) E = 0.75 * L Call Fractal_01(X+E,Y+E,L/2,n-1) Call Fractal_01(X-E,Y+E,L/2,n-1) Call Fractal_01(X-E,Y-E,L/2,n-1) Call Fractal_01(X+E,Y-E,L/2,n-1) End If End Sub 黃色的部份那些call就是在叫指令的意思, 所以我們會說call taxi意思是叫計程車不是沒有道理的.
首先(0,0,30,2)代入(X,Y,L,n)後 a = Array(X+L/2,Y+L/2,0) b = Array(X-L/2,Y+L/2,0) c = Array(X-L/2,Y-L/2,0) d = Array(X+L/2,Y-L/2,0) 會變成 a = Array(0+30/2,0+30/2,0) b = Array(0-30/2,0+30/2,0) c = Array(0-30/2,0-30/2,0) d = Array(0+30/2,0-30/2,0) 也就是 a = Array(15,15,0) b = Array(-15,15,0) c = Array(-15,-15,0) d = Array(15,-15,0)
因此這四個Call Fractal_01又會分別再去生產四個方形, Call Fractal_01(22.5,22.5,15,1)的方形是 a = Array(22.5+15/2,22.5+15/2,0) b = Array(22.5-15/2,22.5+15/2,0) c = Array(22.5-15/2,22.5-15/2,0) d = Array(22.5+15/2,22.5-15/2,0) 即 a = Array(30,30,0) b = Array(15,30,0) c = Array(15,15,0) d = Array(30,15,0) 其他三個同理,之後分裂越來越多只是把n加大而已.