L-System Generator
An L-system is a string and a set of replacement rules applied to every symbol at once. Lindenmayer invented them to model how plants grow, and the striking thing is that the rules never mention geometry at all — the shape appears only when the finished string is read as turtle commands. The dragon curve, the Hilbert curve and a recognisable fern all come out of two or three rules each, which is why writing your own is the whole point rather than a nice extra. So write them: three lines of definition, and a shape nobody predicted.
What this generator does
Applies your rules to your starting string the number of times you ask, then walks the finished string as turtle commands — F, G, A and B draw, plus and minus turn, brackets save and restore position. The length after every step is reported so the growth rate is visible. Five classic systems are there to start from or to read.
How to use this tool
- Write your rules, one a line: a symbol, an arrow, and what it becomes.
- Set what to start from, how far + and − turn, and how many times to rewrite.
- Watch the string length grow, and the shape with it. A system too big to draw is refused before it is attempted, with a count that would work.
- Or pick one of the five classics instead, and read its rules to see how it is done.
Understanding the controls
- System
- Write your own, or take one of five classics: the Koch snowflake edge, the Sierpinski arrowhead, the dragon curve, a branching plant, and the Hilbert curve.
- Your rules
- One a line: a symbol, an arrow, and what it becomes. F, G, A and B move the pen forward, + and − turn it, and [ and ] remember a position and come back to it. A symbol that is none of those and has no rule of its own does nothing at all, and the page says so rather than letting it sit there ignored.
- Start from
- The string the rewriting begins with, before any rule is applied.
- Turn by
- How far + and − turn the pen, in degrees. The same rules at a different angle are a different shape entirely, which is worth trying.
- Iterations
- How many times to rewrite. The string grows exponentially, so the size is worked out first and a system too big to draw is refused with the number it would have reached.
Common use cases
- Trying out rules of your own and finding out what they draw
- Changing one symbol in a known system to see what it does to the shape
- Teaching string rewriting through something a class can alter and re-run
- Generating fractal curves for a diagram or a laser cutter
- Comparing growth rates between rule sets you wrote yourself
How this generator works
Rewriting replaces every symbol simultaneously, leaving any symbol without a rule unchanged. The check re-expands from scratch and requires an exact match, and confirms the length after every intermediate step. Rules of your own get one more check first, and it is the one that keeps the page usable: how many of each symbol a string holds after a rewrite depends only on how many it held before, so the sizes can be carried forward a step at a time and read off without expanding anything. That is arithmetic on a few counters rather than a string in memory, which is what lets a system too big to draw be refused with its own number attached instead of attempted. The forecast is then compared against the length that actually came out — two routes to the same number.
Randomness and fairness
Nothing here is random. Rules, a starting string, an angle and a depth determine the figure completely, which is why there is no seed — the same input always gives the same shape. Rules you write stay in your browser and are never put in the address, so sharing a system means copying it out.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- The turtle understands F, G, A, B, plus, minus and brackets. Rules that need a symbol to mean something else — a different step length, a colour, a width — are outside what this reads.
- Each system is capped at its own iteration limit, because the string grows exponentially.
- The turtle treats every letter as drawing, which suits these systems but is not the general convention.
- Line width and colour are fixed.
- Curves are redrawn from the depth each time rather than stored.
Privacy and your data
Rewriting and drawing happen entirely in your browser. Nothing about the figure is transmitted or stored.
Related generators
- Koch Curve GeneratorThe Koch curve and snowflake at any depth, with the exact segment count, length factor and fractional dimension.
- Sierpinski Fractal GeneratorThe Sierpinski triangle and carpet computed by a digit rule rather than recursion, with the exact cell count at every depth.
- Geometric Pattern GeneratorBuilds a tiled pattern under a symmetry rule and hands you the SVG — mirrored, half-turn or quarter-turn.
- Maze GeneratorPrint a maze with exactly one route from start to finish — three textures from long corridors to short dead ends, any size up to 40 by 40.