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


width: 1000
height: 1000
 
trunkLength: 400
scaleFactor: 0.6
startingAngle: 1.5 * pi
deltaAngle: 0.2 * pi
 
drawTree: function [out x y len theta][
    if len < 1 -> return null
 
    x2: x + len * cos theta
    y2: y + len * sin theta
 
    'out ++ ~"<line x1='|x|' y1='|y|' x2='|x2|' y2='|y2|' style='stroke: white; stroke-width:1'/>\n"
 
    drawTree out x2 y2 len*scaleFactor theta+deltaAngle
    drawTree out x2 y2 len*scaleFactor theta-deltaAngle
]
 
svg: {
    <?xml version='1.0' encoding='utf-8' standalone='no'?>
    <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'
              'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
    <svg width='100%%' height='100%%' version='1.1'
         xmlns='http://www.w3.org/2000/svg'>
        <rect width="100%" height="100%" fill="black"/>
}
 
drawTree svg 0.5*width height trunkLength startingAngle
'svg ++ "</svg>"
 
write "fractal.svg" svg