Generate and draw a fractal tree.

 Draw the trunk
 At the end of the trunk, split by some angle and draw two branches
 Repeat at the end of each branch until a sufficient level of branching is reached


Related tasks
 Pythagoras Tree


graphsize 300,300
 
level = 12 : len =63		# initial values
x = 230: y = 285			
rotation = pi/2
 
A1 = pi/27 : A2 = pi/8		# constants which determine shape
C1 = 0.7 : C2 = 0.85
 
dim xs(level+1) : dim ys(level+1)	# stacks
 
fastgraphics
color black
rect 0,0,graphwidth,graphheight
refresh
color green
gosub tree
refresh
imgsave "Fractal_tree_BASIC-256.png", "PNG"
end
 
tree:
	xs[level] = x : ys[level] = y
	gosub putline
	if level>0 then
		level = level - 1
		len = len*C1
		rotation = rotation - A1
		gosub tree
		len = len/C1*C2
		rotation = rotation + A1 + A2
		gosub tree
		rotation = rotation - A2
		len = len/C2
		level = level + 1
	end if
	x = xs[level] : y = ys[level]
	return
 
putline:
	yn = -sin(rotation)*len + y
	xn = cos(rotation)*len + x
	line x,y,xn,yn
	x = xn : y = yn
	return