Lindenmayer Systems
An interactive string-rewriting system initially conceived to model the growth of plants. By recursively applying simple replacement rules to a starting string, complex self-similar structures emerge when interpreted as turtle graphics.
The Algorithm
An L-system consists of an alphabet of symbols, a starting string called the axiom, and a set of production rules that specify how symbols are replaced in each iteration.
Turtle Graphics Interpretation
The resulting string is drawn using a "turtle" cursor that responds to specific commands:
ForG: Move forward and draw a linef: Move forward without drawing+: Turn left by the angle parameter-: Turn right by the angle parameter[: Push current state (position and angle) onto a stack]: Pop state from the stack (useful for branching)
Any other character (like X or Y) is ignored by the turtle, but can be used in the rewriting rules to control the evolution of the string.
Examples
The classic Koch curve uses axiom F, rule F=F+F-F-F+F, and angle $90^\circ$. A fractal plant might use axiom X, rules X=F+[[X]-X]-F[-FX]+X and F=FF, with an angle of $25^\circ$.