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


/* NetRexx */
options replace format comments java crossref symbols binary
 
import java.awt.Color
import java.awt.Graphics
import javax.swing.JFrame
 
class RFractalTree public extends JFrame
  properties constant
    isTrue  = (1 == 1)
    isFalse = \isTrue
  -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  method RFractalTree() public
    super('Fractal Tree')
    setBounds(100, 100, 800, 600)
    setResizable(isFalse)
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
    return
  -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  method drawTree(g = Graphics, x1 = int, y1 = int, angle = double, depth = int) private
    if depth \= 0 then do
      x2 = x1 + (int Math.cos(Math.toRadians(angle)) * depth * 10.0)
      y2 = y1 + (int Math.sin(Math.toRadians(angle)) * depth * 10.0)
      g.drawLine(x1, y1, x2, y2)
      drawTree(g, x2, y2, angle - 20, depth - 1)
      drawTree(g, x2, y2, angle + 20, depth - 1)
      end
    return
  -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  method paint(g = Graphics) public
    g.setColor(Color.BLACK)
    drawTree(g, 400, 500, -90, 9)
    return
  -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  method main(args = String[])public static
    RFractalTree().setVisible(isTrue)
    return
 