Understanding L-Systems

I kept reading about L-systems in plant-modeling papers, but I never really got them until I drew one myself. This post is a quick write-up of that small experiment.

What an L-system is

An L-system (short for Lindenmayer system) is a string-rewriting system invented by Aristid Lindenmayer in 1968 to model cell growth in filamentous organisms Lindenmayer 1968. It is surprisingly simple:

  1. Start with a string called the axiom, e.g. F.
  2. Apply a set of production rules that replace each symbol with another string.
  3. Repeat for a few iterations.
  4. Interpret the final string as drawing commands.

For example, a classic fractal tree uses:

Axiom: F
Rule:  F → F[+F]F[-F]F

After one iteration the string becomes F[+F]F[-F]F. After four iterations it is already long enough to look like a branching plant.

Turtle commands

To turn the string into a picture, each symbol gets a turtle-graphics meaning:

Symbol Action
F Draw forward one step
+ Turn left by the angle
- Turn right by the angle
[ Save the current position and heading
] Restore the last saved position and heading

The square brackets are the key trick. They let the turtle split into branches, draw each one, and come back to keep going.

Fractals and plants share the same grammar

L-systems are great for fractals because the rule F → F[+F]F[-F]F is self-similar: big branches split into smaller branches that split again. That same self-similarity shows up in real plants, so the same formalism can model trees too Prusinkiewicz 2004.

But the rule alone is not enough to look like an actual tree. Realistic plant models need more knobs:

  • Branching angle and thickness
  • Tropism (response to gravity, light, or wind)
  • 3D orientation and phyllotaxis
  • Physiology such as carbon transport and growth rules

These extensions are what moved L-systems from pretty fractals to real virtual-plant research Prusinkiewicz et al. 1997; Allen et al. 2005. L-Py later wrapped many of these ideas into a usable simulation framework Boudon et al. 2012.

Try it

Below is the small web-based explorer I built. The idea and some preset rules came from Ali Radwani’s L-system blog series. Pick a preset, change the angle or iterations, or write your own rules and click Generate & Draw.

Interactive L-System Explorer. Choose a preset or edit the grammar and click “Generate & Draw”. Open in new tab for a larger view.

References

Lindenmayer, A. (1968). Mathematical models for cellular interactions in development I. Filaments with one-sided inputs. Journal of Theoretical Biology, 18(3), 280–299. https://doi.org/10.1016/0022-5193(68)90079-9

Prusinkiewicz, P. (2004). Modeling plant growth and development. Current Opinion in Plant Biology, 7(1), 79–83. https://doi.org/10.1016/j.pbi.2003.11.007

Prusinkiewicz, P., Hanan, J., Hammel, M., & Mech, R. (1997). L-systems: from the theory to visual models of plants. In M. T. Michalewicz (Ed.), Proceedings of the 2nd CSIRO Symposium on Computational Challenges in Life Sciences. http://www.algorithmicbotany.org/papers/l-sys.csiro96.html

Allen, M. T., Prusinkiewicz, P., & DeJong, T. M. (2005). Using L-systems for modeling source–sink interactions, architecture and physiology of growing trees: the L-PEACH model. New Phytologist, 166(3), 869–880. https://doi.org/10.1111/j.1469-8137.2005.01348.x

Boudon, F., Pradal, C., Cokelaer, T., Prusinkiewicz, P., & Godin, C. (2012). L-Py: An L-system simulation framework for modeling plant architecture development based on a dynamic language. Frontiers in Plant Science, 3, 76. https://doi.org/10.3389/fpls.2012.00076