yet another blog about computer, technology, programming, and internet

Saturday, April 19, 2008

Modeling a Tree using L-System

Saturday, April 19, 2008 Posted by Ismail Habib , 59 comments
An L-system or Lindenmayer system is a parallel rewriting system, namely a variant of a formal grammar (a set of rules and symbols), most famously used to model the growth processes of plant development, but also able to model the morphology of a variety of organisms. [wikipedia]

When using this model, we have to define a set of grammar rules that will be used to describe the growth of the branches of a tree. The rules that we define will later be implemented as the growth of the tree in an iterative fashion. In this system, we define these following alphabets that will be used in the production rules:

f : create branch
l : create leaf
[ and ]
: define a set of local area/branch. The definitions of the area are put inside the [ and ]

+ and -
: rotate the branch right/left in x-axis

^ and v
: rotate the branch up/down in y-axis

: twist the branch left/right in z-axis

By using the symbols above, we can begin to create a tree with our system. But before that, we also have to define several properties that are also important in generating the tree, which are:
  • The number of production rules iterations, for determining the level of the branches,
  • The angle, for determining branch curves, and
  • The radius of the branches and the decreasing value of it, in an iterative way The length of the branches

The following are several examples of the production rules that are used using the system:

Tree A

Angle : 25
# Iterations: 6
Branch radius: 0.02
Branch radius reduction: 0.0015
Branch length (height): 0.15
Initial value : fffffA
Production rules : A = f[++Al][--Al]>>>A

Tree B

Angle : 30
# Iterations: 10
Branch radius: 0.01
Branch radius reduction: 0.001
Branch length (height): 0.16
Initial value : fA
Production rules : A = f[^Bl]>>[^Bl]>>A, B = f[-

Tree C

Angle : 15
# Iterations: 13
Branch radius: 0.02
Branch radius reduction: 0.0015
Branch length (height): 0.15
Initial value : fA
Production rules : A = ^fB>>>B>>>>>B, B = [^^f>>>>>>A]


  1. Simple but nice production rules iterations. Very good blog. All the best!

  2. thank you for the compliment :)

  3. Anonymous11:28 PM

    Did you use c++ to code ???

  4. Yes, I do use C++ and OpenGL.

  5. Anonymous6:20 PM

    i am trying to make a 2d tree without leaves. something very simple to start with in c++. can you point me to any tutorial i can see examples of such things?

  6. Anonymous1:54 AM

    hello, is it possible to have the source for one of these trees?

  7. Thanks for posting this! I was too bored but now I'll try to design this tree. Keep posting.

  8. Hello, could you please share the source code also? thanks

  9. Anonymous8:03 PM

    This info is priceless. Where can I find out more?

    Also visit my site ... how to carrier unlock samsung galaxy s4

  10. hello, nice work :) , i have question , did you use glRotatef et PushMatrix and PopMatrix() ??

  11. Thanks a lot for publishing this. I had fun recreating your Tree C in Minecraft (with different parameters, and with leaves once the branches got small enough). Screenshot is here: . And python source code is here: (see

  12. When I try to render your Tree C, it looks good when I apply the two rules sequentially (but then they are equivalent to a single rule), but if I follow the proper L-system way and apply them simultaneously, I get something that looks to me quite different (and not as good). In my above comment things worked out OK because by mistake my l-system code was applying rules sequentially.

  13. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  14. Can I have the code for it ?

  15. I'm glad to have the opportunity to read your article, it gives me a lot of useful knowledge, I will support you and your next articles. The author of this post is very talented, I greatly admire you, hope you will succeed in the next post.
    cá koi mini, abcya for kids, friv Games for kids 2019, jogos io 2019