Notifications
Clear all

[Closed] Recursive Function Problem??

Hi Guys,

I am trying to create a script for constructing recursive forms and am beginning with an attempt to create script for 2D fractal trees. I have already looked at the L-Systems sticky topic and associated scripts, however I am hoping that I can re-create a very simple script written in ‘Processing’ which uses a simple recursive script.

The script I am writing starts by drawing two lines, one between [0,0,0] and [x,y,z]. The other between [0,0,0] [-x,y,z]. The script should then be able to make smaller and smaller branches at the ends of the two lines until a stopping condition is reached.

So far I have two functions: One which creates lines between two points and the other which will be the recursive function.

[color=blue]

[color=white] 
 
[color=blue][font=Courier New]fn [color=white]line_between_points pointA pointB =[/color]
 
(
	ss = SplineShape pos:pointA
	addNewSpline ss
	addKnot ss 1 #corner #line PointA
	addKnot ss 1 #corner #line PointB
	updateShape ss
	ss
)
[/color]

[/font][/color]
[font=Arial][color=white]The second script is:[/font][/color]
[font=Arial][/font]
[color=black][font=Courier New]

[color=black][font=Courier New] 
 
[font=Courier New][color=white]a = (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]) 
b = (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
 
fn [color=white]branch h = [/color]
 
(
	h*= 0.66
	if [color=white]h > 2 [/color]do
	(
	 c = line_between_points [0,0,0] [h,h,0]
		c.transform = a
		translate a [h,h,0]
		[color=seagreen]-[/color]-branch h
 
		d = line_between_points [0,0,0] [-h,h,0]
		d.transform = b
		translate b [h,h,0]
		branch h
	)
)
[/font][/color]

[/font][/color]
I should then be able to use the functions to make fractal trees by simply writing:

Branch 20

This is currently not working at all; I am hoping that someone might be able to give me a bit of direction or point out where I am going wrong?

Any help would be greatly appreciated.

[/font][/color][/color]

1 Reply

I think your second translate call should be translate b [[color=orange]-h,h,0][/color]

Martijn