L-System Bonsai
Prune, water and bend a bonsai grown from a few rewriting rules.
How to play
- Tap a branch to snip it off with the shears. It stays gone when the tree grows again.
- Tap the copper watering can to grow the tree one more generation.
- Drag a branch sideways to bend it. Every branch follows the same rule, so they all bend together.
- Open Lab for a pine, a willow or a bush, the wind, and the rules themselves.
Challenges
- Snip a branch off with the shears
- Drag a branch until the branch angle is below 20°: one rule shapes every branch
- Snip a branch, then water the tree to its 8th generation: the cut never grows back
Try this
- Water the tree twice and watch the branch-segment count: it roughly doubles each time, while the tree simply fills in.
- Drag a branch to change the angle by a few degrees. The same rules give a slender tree or a wide, flat one.
- Pick the weeping willow in the Lab. Its branches droop because the turtle is gently pulled downwards after every step, the same trick botanists use to model drooping plants.
Fun facts
- L-systems were introduced in 1968 by the Hungarian biologist Aristid Lindenmayer to describe how simple multicellular organisms grow.
- The Algorithmic Beauty of Plants (1990), by Przemysław Prusinkiewicz and Aristid Lindenmayer, made L-systems famous in computer graphics.
- Turtle graphics come from the Logo programming language, in which a “turtle” moves and turns to draw on the screen.
- In an L-system every symbol is rewritten at the same time, much as the cells of a growing plant all divide and grow in parallel.
Rewriting rules that grow like plants
An L-system is a way of growing a long string of symbols from a short one. You start from an axiom, a starting string, and a few rules that say what each symbol becomes. At every generation, every symbol in the string is replaced at once. A rule such as A → F[&B]/A, applied over and over, turns one letter into hundreds or thousands.
Turning symbols into a tree
The string becomes a tree when a turtle reads it. The turtle is an imaginary pen that can move and turn in three dimensions. F means move forward and draw a branch segment; + and − turn left and right; & and ^ pitch down and up; / and roll the turtle around its own heading. Square brackets are the clever part: [ means remember where you are, and ] means jump back there. So [&F] draws a side branch and then returns to the trunk to carry on. Other symbols make branches thinner or shorter, or hang a cluster of leaves.
Why it looks alive
Because the same rules apply at every scale, each branch is built like a smaller copy of the tree, the kind of self-similarity you see in real plants. A little randomness helps: here each rule has several versions chosen by chance, so every seed gives a different tree from the same rules. A tropism term gently bends the turtle’s heading towards the ground after each step, so long branches droop, and in the willow they weep. The bonsai’s rules make low, angled branches that end in layered pads of foliage, the shape bonsai growers aim for.
Watering, pruning and bending
Each time you water the tree, the rules are applied once more and every bud grows at the same moment, so the new shoots unfurl all over the tree at once. Snip a branch and the symbols it grew from are struck out, so it stays gone when the tree grows again while every other bud keeps following the rules. Bend a branch and you change the rule’s angle δ, so every branch moves together. The wind sways every point by an amount that grows with its height, so tips move most and the trunk barely at all.
For the curious
The number of symbols grows roughly geometrically with each generation, which is why the branch-segment readout roughly doubles with each watering. Tropism follows the rule used in The Algorithmic Beauty of Plants: after each step the heading H turns towards a direction T by an angle e·|H × T|, where e is a bending strength. The rules for the tree you are growing are listed in the Lab, so you can read exactly what the turtle is doing.
Questions people ask
What is an L-system?
It is a set of rewriting rules that turns a short string of symbols into a longer one, generation after generation. Read by a turtle that draws as it moves, the string becomes a picture of a plant, a fractal or a tree.
Who invented L-systems?
The Hungarian biologist Aristid Lindenmayer, in 1968. He used them to describe the growth of simple organisms such as algae; they were later extended to model whole plants in three dimensions.
How do L-systems make trees look natural?
The same rules repeat at every scale, so each branch resembles the whole tree. Adding a little randomness to the rules, and a bending force that pulls branches downwards, makes each tree unique and gives it a natural droop.