L-System Explorer
An L-system produces a picture by replacing letters in a string, then reading the result as drawing instructions. Aristid Lindenmayer introduced these systems in 1968 to describe plant development.1
F usually means draw forward, and plus and minus mean turn. Replacing F with F+F, for example, gives two lines with a turn between them, and replacing both new F letters again gives F+F+F+F. Every replacement uses the old string, so a letter added during this round waits until the next round before being replaced itself.
Brackets let the route branch. In F[+F]F, the first F draws a stem and the opening bracket saves its endpoint and direction. Plus turns and the next F draws a side branch. The closing bracket returns to the saved position without drawing, so the final F continues the stem.
A letter can also have a replacement without drawing anything. X is often used this way, to mark where more instructions will appear, so the F lines stay in the string while X gets replaced again.
To try this, open L-System Studio Controls at the top of the page and choose the Fern 4 preset. Change the angle to spread the branches apart. Then move [+X] to the front of the X rule, so it reads [+X]FF[-X]+X. That branch now starts at the foot of the stem instead of partway up.
Further exploring
Videos
Reading
- L-system — Wikipedia
- Lindenmayer system — MathWorld
- Drawing L-systems — The Nature of Code
- L-System User Notes — Paul Bourke
- 2-D L-Systems — Robert Dickau
Sources and notes
- Przemysław Prusinkiewicz and Aristid Lindenmayer, The Algorithmic Beauty of Plants, chapter 1, Springer-Verlag, 1990. Sections 1.1–1.3 explain parallel rewriting and turtle interpretation; sections 1.5–1.6 extend them to spatial and branching structures.