recursion

BlitzPlus Forums/BlitzPlus Beginners Area/recursion

..and ofcourse the famous recursive tree.. or plant..

window=CreateWindow("tree",0,0,640,480)
canvas=CreateCanvas(0,0,640,480,window)

SetBuffer CanvasBuffer(canvas)
	tree 320,240,32,180
FlipCanvas canvas

Repeat
	WaitEvent()
	If EventID()=$803 End
Forever

Function tree(x,y,l#,a,counter=0)
	If counter>10 Return ; toy with the '10'
	counter=counter+1
	
	nx=x+Sin(a)*l
	ny=y+Cos(a)*l
	
	Line x,y,nx,ny
	
	l=l*.9 ; <- to toy with
	tree nx,ny,l,a+20,counter ; toy with both '20' numbers
	tree nx,ny,l,a-20,counter
	
End Function