Lindenmayer Systems in Algorithmic Botany

May 30, 2026

Lindenmayer Systems

Lindenmayer systems (or L-systems for short) are method of replacing letters in a string. They consist of a starting string and a set of replacement rules. The most common basic example is:

Starting string: a
Rule 1: a -> ab
Rule 2: b -> a

In this system, we start with just “a,” then we do one pass, and we replace “a” with “ab,” so the end result of pass one is “ab.” For the second pass, we replace “a” with “ab,” then replace “b” with “a,” so the end result of pass two is “aba.” We can continue this for as many passes as we want, but this seems a bit simple, doesn’t it? Why bother doing all of this fancy wording with rules and starting strings when I can just write some a’s and b’s? These L-systems can get far more complicated than just that, and we can even use them to model plants like this!

But before we get to modeling plants, let’s take a step back. What is an L-system, really? In computer science terms, we would call an L-system a pushdown automata, which is just the technical term for what I described earlier: a starting string with a set of rules. There are more complexities, like the fact that a pushdown automata has a stack, and is equivalent to a context-free grammar, but those are computer science details about the actual implementation. For now, just think of it as those rules I mentioned before. L-systems are used to model very realistic plants in a relatively simple way. Intstead of trying to figure out how to draw a realistic plant, or even 3D model it, we can instead use an L-system to do it for us. You may be thinking “how did you get an image like that out of just a bunch of letters?” We actually have a system for that called turtle graphics!

Turtle Graphics

Turtle graphics are a way of turning a string of letters into an image. The name comes from the fact that the system follows a digital turtle as it’s walking based on intructions you give. The basic functions (in 2D at least, 3D gets a bit more complicated) are to go forward and draw a line, turn left, turn right, and go forward without drawing a line. We are going to add a stack (just a fancy way of saying we’ll be adding a way for the system to remember where it was and go back) to make it so we can easily add branches to our plant. The most common symbols for these instructions are:

F: move forward and draw a line
f: move forward without drawing a line
+: turn right
-: turn left
[: push position to the stack
]: pop position from the stack

You’ll typically have a pre-coded distance and angle for walking and turning, but you can adjust it for having variable amounts. With just these, you can (technically) make the same image that I did. The “technically” part comes from the fact that I wanted to make certain things easier. I added a vector that we like to call “tropism.” Tropism is what we call a plant’s tendency to travel in a certain direction. This can be from things like light, gravity, etc. Adding that into my L-system is what allows me to easily make that plant curve down, and by changing a single vector, I can make it go up, or to the left, or some combination. I also added what’s called a stochastic L-system, which is a way to add randomness to your image. As you may have observed, not every plant of the same species looks the exact same. Adding a stochastic element allows for us to demonstrate the variety in nature. You can also add context and make it a context-sensitive grammar, which just means that you can change rules to look at the letters surrounding the current letter before making a replacement.

How Does This Relate to Botany?

Now, that’s all neat, but what is the connection to botany, aside from the fact that you can model plants? Well, nothing, really. But, it can teach us some interesting things about plant morphology. There is a thing called a branching angle, and these tend to be the same across a species of plant. Generally, a plant will always branch out at the same angle. For example, if plant A has a shoot brnching from the main stem at an angle of 45°, then all shoots will branch off of all stems at 45°. This makes an L-system an interesting way to model plants. Since we can have this universal branching angle, we can encode a realistic looking plant in a very simple text file.

Even more, we can learn about a thing called tropism that I mentioned before, which is the direction a plant moves or grows towards. There are many different types of tropism, but I’ll use phototropism as an example. As you may have noticed with plants in your home, they tend to grow towards sources of light. There are a lot of biological sensors and mechanisms that allow this, but what we care about is the result: the plant will grow towards the light. You would assume that modelling that would be really complicated, and it can get that way if you choose to model multiple types, but it actually isn’t that bad. We know that we can just define a vector that does everything for us. We can even define multiple that we can add to make it even easier. In fact, it isn’t very hard to edit our turtle graphics system to have a new function that starts and stops certain types of tropism so we can have, say, phototropism, in the leaves, but gravitropism in the roots.

Now, I know I’ve been saying that all of this is really simple and easy, but it really isn’t. Parts of it, specifically the parts that I talked about, are fairly simple. The actual coding of a functional L-system is fairly simple, and they are easy to add to and edit. The finding of a specific plant’s starting string and ruleset, however, is very difficult. This task is usually reserved for people who have been studying particular plants for years, and are experts on the subject.

Further Resources

I hope you were able to learn something about coding, plants, or a combination of both. L-systems are a really good introduction to botany for those who are less formally educated on them. If you are interested in going a bit further in your knowledge, here are some resources I would recommend:

https://algorithmicbotany.org/papers/#abop
This book gives a very comprehensive overview of 2D and 3D L-systems, their uses, and how they can be used to model various aspects of plants. The algorithmic botany website as a whole is a great resource for those who are knowledgeable in math and want to branch out into botany.

https://thecodingtrain.com/challenges/16-l-system-fractal-trees
This video (as well as others in this series) gives a good basic explanation, as well as shows you how to code L-systems, if you are not as strong at coding as you’d like to be.

I tried to give a general overview, as well as some of the more interesting aspects of L-systems, but I am by no means an expert. I highly suggest reading more about them if you are interested, as there are many aspects that I did not go into (either because they are more complex than I can explain, or simply because I don’t understand them well enough). I hope you can use this as a springboard to launch into a better understanding. I may even go deeper into this topic later myself.

Leave a comment