Fractal Plant

Creating a fractal bush using the L-rewrite system. See Wikipedia. The fractal production rules for this specific fractal were obtained from Paul Bourke.

The production rules for this curve is:


axiom = F
F -> FF+[+F-F-F]-[-F+F+F]
angle = 22.5
                

First you need to initialize an empty stack. This follows the LIFO (Last in, First Out) method to add and remove elements. Here, F means "draw forward", − means "turn right 22.5°", and + means "turn left 25°". X does not correspond to any drawing action and is used to control the evolution of the curve. The square bracket "[" corresponds to saving the current values for position and angle, so you push the position and angle to the top of the stack, when the "]" token is encountered, pop the stack and reset the position and angle. Every "[" comes before every "]" token.