l-system
L-systems (Lindenmayer systems) are formal grammars that produce fractal patterns through string rewriting. Starting with an axiom (e.g. "F"), each iteration replaces every symbol with a rule (e.g. F β F+F-F-F+F). After N iterations, the resulting string drives a turtle graphics engine to draw the pattern. L-systems model many natural forms β trees, snowflakes, ferns, neural networks. Famous examples: Koch snowflake, Sierpinski triangle, dragon curve, fractal plants. The ZTools L-System Generator lets you define axiom + rules + angle, runs iterations, and renders the result in SVG.
Use casesβ
Generative artβ
Tweak rules to produce wildly different fractals. Each combination is unique.
Teach grammar / formal languagesβ
L-systems are simple context-free grammars. Visual feedback makes the abstract concrete.
Procedural generation in gamesβ
Trees, plants, terrain features procedurally generated via L-systems.
Mathematical curiosityβ
See the Koch snowflake, dragon curve, fractal tree all from a few rules.
How it worksβ
- Define axiom β Starting string (e.g. "F").
- Define rules β Replacement rules (e.g. F β F+F-F-F+F). Multiple rules per symbol if you want stochastic L-systems.
- Set parameters β Iterations (5-8 typical), angle (e.g. 90Β° for Koch), step length.
- Render β Tool runs iterations, then draws via turtle graphics: F = forward, + = turn left, - = turn right, [ = push state, ] = pop state.
Examplesβ
Input: Koch snowflake: axiom F, rule F β F+F--F+F, angle 60Β°, 4 iterations
Output: Iconic snowflake-edge fractal.
Input: Dragon curve: axiom FX, rules XβX+YF+, Yβ-FX-Y, angle 90Β°, 12 iterations
Output: Self-similar curve resembling a dragon.
Input: Fractal plant: axiom X, rules XβF+[[X]-X]-F[-FX]+X, FβFF, angle 25Β°
Output: Tree-like plant. Resembles a real fern.
Frequently asked questionsβ
How many iterations?
Each iteration multiplies string length by the rule's expansion factor. After 8-10 iterations, strings get massive (millions of characters). Tool caps at reasonable rendering.
Privacy?
All in browser.
Tipsβ
- Start with classic examples (Koch, dragon, plant) to understand the mechanics.
- For your own designs, tweak one rule at a time β small changes produce dramatic differences.
- For posters, use SVG export β vector scales infinitely.
- L-system rules are notation-sensitive β extra spaces or capitalisation matter.
Try it nowβ
The full l-system runs in your browser at https://ztools.zaions.com/l-system β no signup, no upload, no data leaves your device.
Last updated: 2026-05-06 Β· Author: Ahsan Mahmood Β· Edit this page on GitHub