An interactive playground for exploring Lindenmayer Systems (L-Systems) — recursive rewriting algorithms capable of generating surprisingly complex organic structures from a handful of simple rules.
🌐 Live Demo: https://keegooroomie.github.io/l-system-playground/
L-systems were introduced by biologist Aristid Lindenmayer in 1968 to model plant growth.
An L-system is defined by four components:
- Axiom — the initial string
- Production Rule — how symbols are replaced
- Iterations — how many times rules are applied
- Angle — rotation used during drawing
A tiny rule can produce thousands of drawing instructions after only a few iterations.
Starting configuration:
Axiom: F
Rule: F → F[+F]F[-F]F
Expansion process:
Iteration 0
F
Iteration 1
F[+F]F[-F]F
Iteration 2
F[+F]F[-F]F[+F[+F]F[-F]F]F[+F]F[-F]F[-F]F[+F]F[-F]F
After expansion, the resulting string is interpreted by a turtle graphics renderer.
| Symbol | Meaning |
|---|---|
| F | Move forward and draw |
| A / B | Alternative drawing symbols |
| + | Rotate right |
| - | Rotate left |
| [ | Save current position and angle |
| ] | Restore saved position and angle |
The bracket system is what enables branching structures such as trees, bushes, roots, and coral-like forms.
The renderer maintains:
- Current position
(x, y) - Current direction
- State stack
Execution example:
F[+F][-F]
- Draw forward
- Save position
- Turn right and draw branch
- Restore position
- Turn left and draw another branch
This simple mechanism creates hierarchical growth patterns.
Axiom: F
Rule: F[+F]F[-F]F
Angle: 25°
Classic branching tree.
Axiom: F
Rule: F[+F][--F][-F]
Angle: 25°
Produces fern-like structures with asymmetric growth.
Axiom: F
Rule: F[+F][-F]F[-F][+F]F
Angle: 20°
Dense multi-branch vegetation.
Axiom: F
Rule: F[+F]F[-F][F]
Angle: 22°
Balanced recursive branching pattern.
L-systems grow exponentially.
Example rule:
F → F[+F]F[-F]F
Approximate command count:
| Iterations | Growth |
|---|---|
| 1 | 11 |
| 2 | 61 |
| 3 | 311 |
| 4 | 1561 |
| 5 | 7811 |
This is why even simple rules quickly generate complex structures.
Try changing:
- Branch density
- Rotation angle
- Iteration count
- Symmetry
- Nested branches
Examples:
F[++F][--F]
F[-F]F[+F]F
F[+F[-F]]
Small changes often produce dramatically different results.
- Trees
- Vegetation
- Roots
- Coral structures
- Alien flora
- Fractal art
- Organic modeling
- Environmental generation
- Plant morphology
- Branching systems
- Growth pattern research
This playground is designed as a practical way to understand:
- Recursive rewriting systems
- Turtle graphics
- Procedural content generation
- Emergent complexity
Open the page, modify a rule, press Generate, and immediately see how a tiny algorithmic change affects the resulting structure.