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


 
 NoMainWin
sw = 640 :   sh = 480
WindowWidth  = sw+8 : WindowHeight = sh+31
UpperLeftX = (DisplayWidth -sw)/2
UpperLeftY = (DisplayHeight-sh)/2
Open"Fractal Tree" For Graphics_nf_nsb As #g
#g "Down; Color darkgreen; TrapClose halt"
h$ = "#g"
 
'initial assignments
initAngle = Acs(-1)*1.5 'radian equivalent of 270 degrees
    theta = 29 * (Acs(-1)/180) 'convert 29 degrees to radians
   length = 110 'length in pixels
    depth = 25   'max recursion depth
    'draw the tree
    Call tree h$, 320, 470, initAngle, theta, length, depth
    #g "Flush; when leftButtonDown halt" 'L-click to exit
    Wait
 
Sub halt handle$
    Close #handle$
    End
End Sub
 
Sub tree h$, x, y, initAngle, theta, length, depth
    Scan
    newX = Cos(initAngle) * length + x
    newY = Sin(initAngle) * length + y
    #h$ "Line ";x;" ";y;" ";newX;" ";newY
    length = length * .78
    depth = depth - 1
    If depth > 0 Then
        Call tree h$, newX, newY, initAngle-theta, theta, length, depth
        Call tree h$, newX, newY, initAngle+theta, theta, length, depth
    End If
End Sub 
 