🌿 L-System Fractals

Lindenmayer Systems · Turtle Graphics · Fractal Plants & Curves

3D Presets

Parameters

Stats

Segments
Iterations
Preset
A 3D L-system (Lindenmayer system) rewrites a string with production rules, then a turtle draws it in space: F = forward, +/- = yaw, &/^ = pitch, \\ and / = roll, [ ] = push/pop. Organic plant-growth complexity emerges from simple rules.

About L-System Fractals

This simulation generates fractal plants, snowflakes and space-filling curves using a Lindenmayer system (L-system): a formal grammar that rewrites a starting string, the axiom, by simultaneously replacing every symbol with the right-hand side of its production rule. After a chosen number of iterations the long output string is read by a turtle-graphics interpreter, where each symbol is a drawing command, producing self-similar geometry from just a handful of simple rules.

You set the axiom, edit one or more production rules (F → FF+[…]), and adjust the iteration count (1–9) and turn angle (5°–90°). The turtle reads F, G, A and B as "draw forward", + and − as turn left/right by the angle, and [ and ] to push and pop position and heading for branching. Built-in presets include the Koch snowflake, Dragon curve, Sierpinski, Hilbert curve and Barnsley fern. L-systems underpin procedural vegetation in games, films and botanical modelling.

Frequently Asked Questions

What is an L-system?

An L-system, or Lindenmayer system, is a parallel string-rewriting grammar invented by botanist Aristid Lindenmayer in 1968 to model plant growth. You start with an axiom and repeatedly replace every symbol at once using production rules. The resulting string is then drawn as geometry, yielding intricate, self-similar fractal forms.

How does the turtle graphics interpreter work?

A virtual "turtle" walks the final string one symbol at a time. F, G, A and B move it forward while drawing a line segment, + turns it left by the set angle and − turns it right. The square brackets [ and ] save and restore the turtle's position and heading, which is what creates branches.

What do the Iterations and Angle sliders do?

Iterations (1 to 9) sets how many times the rewriting rules are applied, so higher values produce far more detail but exponentially longer strings. Angle (5° to 90°) is the amount the turtle turns for each + or − command. Small changes in angle can dramatically alter a plant's spread or a curve's shape.

What does a production rule like F → FF+[−F] mean?

It means: every time the symbol F appears, replace it with the sequence FF+[−F]. All F symbols are substituted simultaneously in one pass, then the next iteration substitutes again. Symbols with no rule, such as + or [, are left unchanged, acting as fixed turtle commands rather than rewritable variables.

Why does the string grow so quickly with more iterations?

Because rewriting is exponential. If a rule replaces one symbol with several, the string roughly multiplies in length each pass, so nine iterations can reach hundreds of thousands of characters. This simulation includes a safety cap that stops expansion once the string exceeds 500,000 symbols to keep the browser responsive.

How is the Koch snowflake built from rules?

It starts from the axiom F--F--F, an equilateral triangle, with the single rule F → F+F--F+F and a 60° angle. Each segment is replaced by a smaller zig-zag bump, so the perimeter grows without bound while the enclosed area stays finite, a hallmark fractal paradox.

Are these shapes physically accurate models of plants?

They are mathematical idealisations rather than exact botany, but L-systems capture the branching logic of real plants remarkably well. Lindenmayer designed them precisely to describe cell division and shoot growth, and presets like the Barnsley fern show how convincingly natural a leaf shape emerges from just two production rules.

What is the fractal dimension shown by the Sierpinski preset?

The Sierpinski gasket has a fractal dimension of log3/log2, approximately 1.585. That non-integer value means it is more than a line yet less than a filled plane: as you zoom in, the same triangular holes repeat at every scale, which is the defining property of a self-similar fractal.

Why are deeper branches drawn in a different shade?

The interpreter records each segment's stack depth, meaning how many open brackets surround it. The renderer maps that depth to line opacity, so deeper, finer twigs appear brighter against the dark background. This gives a sense of three-dimensional layering even though the drawing is purely two-dimensional.

Where are L-systems used in the real world?

They power procedural generation of trees, ferns, grass and coral in video games and computer-generated films, and are used in botanical research to simulate growth. Space-filling variants such as the Hilbert curve also appear in image processing, data compression and spatial database indexing.