05 L-systems

L-systems have a natural growing rule set which simulates the growth of plants and trees.

The original problem that Fibonacci investigated (in the year 1202) was about how fast rabbits could breed in ideal circumstances.

Fluffy bunnies

Suppose a newly-born pair of rabbits, one male, one female, are put in a field. Rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits. Suppose that our rabbits never die and that the female always produces one new pair (one male, one female) every month from the second month on. The puzzle that Fibonacci posed was…

How many pairs will there be in one year?

.The simple rule below uses the idea of 2 adults (A) make a offspring pair (O) which after one generation become adults themselves which can also reproduce. this system repeats continuously.

The recursive nature of the L-system rules leads to self-similarity and thereby, fractal-like forms and are easy to describe with an L-system. Plant models and natural-looking organic forms are easy to define, by increasing the recursion level the form slowly ‘grows’ and becomes more complex. Lindenmayer systems are also popular in the generation of artificial life.

The simplest L-system to make is simply a growth pattern with 2 branches at the end of every branch. 

However, more complex systems use Turtles. Turtles are the interpretation of simple rules of growth. Something can grow in branches using [ ] (whatever is inside brackets). Growth be symbolised by letters ( F and G) WITH RULE SETS AND AXIOMS.

 

 

  • variables : 0, 1
  • constants: [, ]
  • axiom  : F
  • rules  : (G → GG), (F → G[F]F)
  • G draw a line segment ending in a leaf
  • F: draw a line segment
  • [: push position and angle, turn left 45 degrees
  • ]: pop position and angle, turn right 45 degrees

 

A Decaying Forest tree system

Using the above concepts and the example from Shiffman of growing tree. The code was developed to create random decaying trees over time.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Turtle

+ TURN RIGHT BY ANGLE

– TURN LEFT BY ANGLE

& PITCH DOWN BY ANGLE

^PITCH UP BY ANGLE

\ ROLL LEFT BY ANGLE

/ ROLL RIGHT BY ANGLE

| TURN AROUND BY 180 DEGREES

F move FORWARD by 1 unit

[] new BRANCH (whatever is inside brackets)

T move TROPISM BY 1 UNIT

Cloners!

group 1 = I

group 2 =J

group 3 =K

group 4 = L

The parameters in the Turtle and Values tabs are meant for advanced users with programming experience (these tabs contain an entire L-System). Those of you with little or no programming experience should, however, not be scared off. In the following are several variable examples.

Make sure you first set Mode to Turtle.

Brief introduction to L-Systems

In the following pages, the L(indenmayer)-Systems are briefly explained. Additional books or online resources are available that offer an in-depth explanation of these systems (the pdf document “The Algorithmic Beauty of Plants” from Przemyslaw Prusinkiewicz and Astrid Lindenmayer is based on use with CINEMA 4D and can be downloaded at http://algorithmicbotany.org/papers#abop).

L-Systems are usually used for similating plant growth and similar effects. Combined with MoGraph, these can be used to create spectacular growth simulations by placing a MoSpline object into a Sweep NURBS object, thus creating a renderable object (Splines can be rendered directly using Sketch and Toon or HAIR).

Simply put, an L-System executes a series of commands that define how and where new branches should grow. It is a self-producing system that can replace existing branches with new ones.

The basic principles are fairly simple and are based on a system called “Turtle System”. A (virtual) turtle is sent on its way via simple commands. This path is represented by a Spline.

The 3 most important commands are:

  • A simple F, which simply means “Go one step Forwards”. For a MoSpline it means “Extend the Spline by one unit (in the object’s Z direction)”
  • +: Rotate right
  • : Rotate left

If you enter the sequence F++F++F in the Premise field it translates to: “Take one step Forward; turn twice to the right; take another step Forward; turn twice to the right; take another step Forward.”

How big each step is and how large the angle of rotation is can be defined in the Values tab via the Default Movement and Default Angle values, respectively. Or, as described below, by placing them in parenthesis. If Default Angle is set to 60° a perfect triangle will result for our example:

lupe.gif

029766.jpg Two different command codes: left F++F++F; right: F-F++F-F (each with a Default Angle of 60°.

 

This lets you create branch-like shapes. A very interesting function of L-Systems is its integrated replacement system with which individual branches can be replaced by others. This can also be done recursively, which lets you create very complex branching with simple command codes. If this sounds confusing, the following example can shed some more light on what’s involved:

So far you have only entered single-line command codes that were executed only once. Now enter the following command code into the respective fields:

Premise field: F++F++F

Rules field: F = F-F++F-F

As you can see, the Rules code line contains an assignment (in the following refered to as Rule) in which “F” is assigned several symbols that in turn will (internally) be inserted into the Premise line of code.

If written out in its entirety, the command line code would read as follows (replace the F in the Premise line of code with the code following the “F” in the Rules line of code):

F-F++F-F++F-F++F-F++F-F++F-F

This represents the second shape from left in the image below. Since each F in the Premise code is replaced by the Rule, each straight line will be replaced by the more complex line.

lupe.gif

029767.jpg Change of shape when each F is replaced by the “F-F++F-F” code.

 

And this replacement process can be repeated indefinitely (well, not quite, since your computer will probably throw in the towel after the exponentially increasing complexity of the Splines starts to grow…). How often this replacement process is repeated is defined by the Growth value, which replaces each F with the Rules code. Incidentally, fractals work the same way.

Of course placeholders can be used as well so that not necessarily each F has to be used. After all, this would be unrealistic for growing formations – growth in length does not always occur only at the end of branches, etc.

For this you can use placeholders (letters that do not represent any Turtle command) such as A, B, C, D, (but NOT “F” because it is the default “one unit forward command”).

Type the following into the respective fields:

Premise: FA

Rules: A=+F-FA

lupe.gif

029768.jpg

 

Since the Rule ends with an A, an increasing Growth value will result in the formation growing endlessly (Default Angle is set to 90°).

Tip:

This simple-looking replacement rules can create an amazingly complex geometry over several generations (see below). If symbols are used incorrectly you can end up crashing your computer. So be careful when experimenting and save your work often (even in a simple text editor). It is also very helpful if you set Display Mode to Line.

The code we have used so far has consisted of a single, uninterrupted line of code. However, L-Systems first become interesting when real branches are created, i.e. new lines that branch from existing lines. And this can be achieved by using square brackes ([ ]). The command sequence within a square bracket is viewed as a separate branch (and creates a new Turtle). After the branch has been created the turtle will return to the starting point prior to the square brackets and continue with the command sequence following the square brackets.

Type the following into the Premise field:

F[+F][-F[-F]F]F[+F][-F]

lupe.gif

029769.jpg This is the result of the command code above with a Default Angle of 30°.

 

If you now enter F into the Premise field and the above code (F=F[+F][-F[-F]F]F[+F][-F] ) into the Rules field, each F will be replaced by the braches at the left of the image. Increasing the Growth value will let the branch continue to grow because each straight line will be perpetually replaced by a new branch. If you look closely you will see the branch pattern at the left repeated in the tree at the right (highlighted in green).

This is an easy method of creating complex plant-like branching:

lupe.gif

029770.jpg Various command codes. Note that any letter (in this example “A”) can be used as a placeholder. At the bottom right of the image a Default Angle value of 90° was used.

 

Until now we have generated everything on a flat plane. Since branching doesn’t only take place on a single plane but in every direction, command symbols exist that also makes this possible.

These are (a degree value can be added in brackets after the command symbols):

& or ^: rotate around the Turtle’s transverse axis

\ or / : rotate around the Turtle’s longitudal axis

Type the following into the Premise field: F&F\ (90)^F+F:

lupe.gif

029771.jpg The 90° after the “/” are not really necessary because the Default Angle value will be applied for small specifications.

 

The result is the Spline pictured above. The turtle moves forward (F), rotates at a right-angle around its transverse axis (&, Default Angle is set to 90°), moves forward again (F), rotates 90° around its longitudal axis (\ (90)), then 90° around its transverse axis (^), moves forward again (F), turns right (+) and finally moves forward again (F).

If you use this method to create branched spatial formations, real bushes and trees can be created.

User Data

029772.jpg

You can use the User Data as variables in a sequence of symbols. In the image above an Angle parameter was added to the User Data that was then substituted in parenthesis for ^ (turtle rotates around transverse axis) in the Premise field.

Special characters and spaces should not be included in the variable names. Underscores are recognized (e.g. “second_length”) as is capitalization.

Formulas

Formulas, including defined variables (e.g. F(_growth*2), can be used instead of normal digits. The following are available:

029777.jpg

Example “Total/Index”

Let’s say you have the string F(_index)F(_index), which consists of two commands. The string performs the same function as F(1)F(2) (one unit forwards then two units forward). For example, since “_total” is the total number of commands, a spiral can be created with the following command:

Premise: FA

Rule: A=+(20*_index/_total)FA

Example “_level”

Let’s say you have the following command:

Premise: A

Rule: A=FA

The following level values will result (shown here in parentheses for demonstration purposes – these will NOT actually be shown):

Growth = 0 : A(0)

Growth = 1 : F(1)A(1)

Growth = 2 : F(1)F(2)A(2)

Growth = 3 : F(1)F(2)F(3)A(3)

Now that you know how the “_index” numbering is done, take a look at the following command:

Premise: FA

Rule: A=+F(_level*10)A

…creates the following spiral with Default Angle set to 90°:

029773.jpg

Example “_arg”

Just as you can define F(a,b,c)=F(a*2,b*2,c*2) to set parameters for Turtle commands (in this example F) you can also use the “_arg” command. These don’t have to be evaluated at the beginning. F=F (_arg1*2,_arg2*2,_arg3*2) does the same as the command above.

Advanced syntax variations

The following syntax is also possible:

Premise: F(2)F(1,2)F(2,3)

Rule : F(a,b) = F(a*2,b*2)

All Fs will be replaced and wherever “a” or “b” appear within the Rule existing F arguments will be handled as follows:

F(2*2,1*2)F(1*2,2*2)F(2*2,3*2) which logically equates to F(4,2)F(2,4)F(4,6).

Rule constructs like the following are also possible:

F(a,b):(a>10)=F(a,b)+F(a/2)

This Rule will, for example. only be applied if the value of the first argument is greater than 10.

In the following example both syntax variations above were combined and produce an interesting effect:

Example “fruits”

lupe.gif

029774.jpg

 

In the example above, several branches grow simultaneously. When one branch has finished growing a sphere will be placed at the end of the branch (requires the command J, see example: Klon-Objekt).

Note that “B(6)” is defined in the first Rule and that “B(h-1)” reduces the argument by 1 in Rule 2 until “h=0” finally sets the sphere in Rule 3.

Take a look at the console to see the entire string (but first click on the Result String to Console button).

Further details regarding formulas can be found in the attachment.

Premise

Enter the premise here. This is most often a single-letter command (see Rules) or a placeholder to which content is added in the Rule field. In the following pages you will find numerous examples of how strings can look.

Context Ignore

Here you can define a series of symbols (commands) that will be ignored by context rules. Example:

You have the following constellation:

Premise: A+B+C+D+E+F

Rules: A

Rules

030012.jpg

Example “creating polygons”

lupe.gif

030017.jpg

 

Take a look at the second line of the Rule field:

L=[{.-f.+f.+f.++++f.+f.+f.+f}]

Between the curly bracktes (these define a polygon), a specific number of polygon points is defined (each begins with a “.”) between which a polygon is created. Because the curly brackets are contained within square brackets, the turtle will be reset to its point prior to creating the leaf after each leaf has been created.

The entire leaf will be assigned to an “L” and the Rule in the line above will create a complete leaf wherever an “L” exists.

Note that the MoSpline can produce either a Spline OR a polygon. If you want to produce both simultaneously, use the Destination Spline.

Example “multiply/divide”

lupe.gif

030018.jpg

 

If you use a self-replacing sequence of symbols in the Rules field (e.g. A=F+BA), a multiplier or divisor (, !, ;, _, ?, @) can be used to increase or decrease the value of each new Generator.

Example “cutting a branch”

lupe.gif

030019.jpg

 

If you take a look at this Rule you will see that the placeholders A, B, C and D have been added to the premise. For various Growth values, the Rules now define the replacement of each placeholder with a % value, which means that the following symbols will be cut off at that point on (and per) each branch.

Example “Cloner object”

lupe.gif

030014.jpg If the Growth value is animated, this structure can grow exuberantly (incl. growing clone).

 

Note how J and K are used in the Rule (these could be replaced with (1,1,1,1) and (1,1,1,1), repectively, and if the parentheses argument were omitted each would use the standard value) that refers to the clones of a Cloner object. The mode must be set accordingly for both Cloner objects:

I(1,1,1,1) reflects Group 1

J(1,1,1,1) reflects Group 2

K(1,1,1,1) reflects Group 3

L(1,1,1,1) reflects Group 4

Note that one Rule

Premise: FA

Rules: A=FX

X=J(1,1,1,1)

may function but the clones don’t grow steplessly but are simply displayed abruptly.

Example “index”

lupe.gif

030015.jpg

 

A Cloner object’s Child objects are numbered sequentially (starting with “0”). If, for example, you define A=FJ(2,1,1,1)A (the RGB values can be omitted), the Cloner object will only use the object with the index “2” (left of the sphere). If you use A=J(rnd(2))A on the right side, a clone will be placed randomly in accordance with a number between “0” and “2” that is also chosen randomly.

Example “random growth”

lupe.gif

030016.jpg Different limits generate different shapes.

 

This Rule in combination with varied User Data values for Limit1 and Limit2 (together, these values should equal 100%) can be used to create differing but very similar “plants” (Stochastic L-Systems. The conditions (rnd(1)<) or (rnd(1)>) determine randomly which of the 3 Rules will be applied (each with a new random selection for each new Generator, i.e. larger Growth parameter).

Example “context rules”

Rules can also be written in the following form:

Premise: ABC

Rule: A<B=C

Result (if Growth > 1): ACC

So what will happen? This depends on the sequence within the result string. The Rule “A<B=C” searches for instances within the string where a “B” directly follows an “A” and replaces the “B” by a “C”.

If, on the other hand, you enter “A>B=C”, the “A” to the left of a “B” will replaced by “C” (the result would be “CBC”).

For the Rule “AB=C” it cannot be determined which symbol should be replaced by “C”. In this case both will be replaced by “C” (the result would be “CCC”).

Result

Displays syntax errors.

Result String to Console

Clicking on this button will display the symbol sequence currently in effect, taking into account all Rules and the Growth parameter, in the Console. Such a sequence can, for example, look like this (this is the sequence of symbold from the fruits example with Growth set to 4):

030013.jpg

 

 

Abstraction

Building on the L-system process of growth with abstraction.

 

SaveSave