❅ L-System Fractal Generator
Grow fractal patterns from simple rewriting rules. Six classic Lindenmayer systems — Koch Snowflake · Sierpiński Triangle · Dragon Curve · Barnsley Fern · Hilbert Curve · Fractal Plant.
1–6 presets R reset view +− zoom ↑↓←→ pan Mouse wheel + drag
What Are L-Systems?
Start with an axiom string (e.g.
F), then repeatedly replace every symbol using production rules (e.g. F → F+F−−F+F). After n iterations a turtle interprets the final string:F / G → draw forward | + → turn right by δ | − → turn left by δ | [ → push state | ] → pop state
The Six Classic Presets
| L-System | Axiom | Rule(s) | Angle δ | Rec. iter. |
|---|---|---|---|---|
| Koch Snowflake | F--F--F | F → F+F--F+F | 60° | 4–5 |
| Sierpiński Triangle | F-G-G | F → F-G+F+G-F; G → GG | 120° | 5–6 |
| Dragon Curve | FX | X → X+YF+; Y → -FX-Y | 90° | 10–12 |
| Barnsley Fern | X | X → F+[[X]-X]-F[-FX]+X; F → FF | 25° | 6–7 |
| Hilbert Curve | A | A → +BF-AFA-FB+; B → -AF+BFB+FA- | 90° | 5–7 |
| Fractal Plant | X | X → F-[[X]+X]+F[+FX]-X; F → FF | 22.5° | 4–5 |
Key Concepts
Self-Similarity
Zooming into any part reveals the same structure as the whole. The production rule is applied at every level, making the fractal look identical at all scales.
Fractal Dimension
Koch Snowflake: D = log(4)/log(3) ≈ 1.262. The boundary is 1D (a curve) yet too irregular to be 2D — it lives between dimensions.
Branching with [ ]
Square brackets push and pop the turtle's (x, y, θ) state onto a stack, enabling bifurcating branches — essential for realistic plant and tree models.
Space-Filling Curves
The Hilbert Curve fills the unit square as iterations → ∞: its fractal dimension approaches 2. It is used in image storage, memory caching, and GIS locality.
Curriculum Connections
| Level | Topics covered |
|---|---|
| GCSE / IGCSE | Sequences and recursion, geometric patterns, angles and turning |
| A-Level Further Maths | Fractals, self-similarity, iterative processes, complex numbers |
| IB / AP | Recursive algorithms, formal grammars, mathematical modelling |
| Undergraduate | Formal language theory, fractal geometry, computer graphics, biologically inspired algorithms |
Frequently Asked Questions
What is an L-system?
A Lindenmayer system (L-system) is a formal parallel rewriting grammar invented by botanist Aristid Lindenmayer in 1968. A string called the axiom is repeatedly rewritten using production rules. The resulting string is interpreted by a turtle that draws lines and turns angles, producing self-similar fractal patterns at each iteration.
Why does increasing iterations add more detail?
Each iteration applies the production rules to every character simultaneously. If a rule triples string length, then after n iterations the string has 3ⁿ characters. More characters mean more turtle commands, drawing smaller and finer segments — revealing structure at progressively smaller scales.
What is the fractal dimension of the Koch Snowflake?
The Koch Snowflake has a Hausdorff fractal dimension of D = log(4) / log(3) ≈ 1.2619. Each iteration replaces 1 segment with 4 segments each of length 1/3, so the total length grows as (4/3)ⁿ → ∞ while the enclosed area converges to a finite value — 8/5 times the area of the original triangle.
What is the Hilbert Curve used for in computing?
The Hilbert Curve is a space-filling curve that visits every point in a 2D grid exactly once. Because nearby points on the curve are also nearby in 2D space, it is used to optimise cache performance (Z-order/Morton curve), image compression, geographic information systems, and memory layout in databases — improving spatial locality dramatically over row-major ordering.