--- title: "Turtle" url: "https://help.maxon.net/c4d/en-us/Content/html/OMOSPLINE-MGMOSPLINEOBJECT_TURTLE_GROUP_TURTLE.html" section_path: "MoGraph > Generators > MoSpline > Brief introduction to L-Systems" element_id: "OMOSPLINE" group_id: "MGMOSPLINEOBJECT_TURTLE_GROUP_TURTLE" description: "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 …" --- ## Turtle 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](https://help.maxon.net/c4d/en-us/Content/html/OMOSPLINE-ID_OBJECTPROPERTIES.html.md) 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 simulating 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 object, thus creating a renderable object (Splines can be rendered directly using [Sketch and Toon](https://help.maxon.net/c4d/en-us/Content/html/5545.html.md) or [HAIR](https://help.maxon.net/c4d/en-us/Content/html/6226.html.md)). 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 **F**orwards". 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 **F**orward; turn twice to the right; take another step **F**orward; turn twice to the right; take another step **F**orward." 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: ![Image: 029766.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/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 referred 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. ![Image: 029767.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/029767.jpg)\ Change of shape when each **F** is replaced by the "F-F++F-F" code. [![Image: halvar.png](https://help.maxon.net/c4d/en-us/Content/Resources/Images/halvar.png)](https://help.maxon.net/c4d/en-us/Content/Resources/Scenes/2025-2_MoG_41_.c4d) 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](https://help.maxon.net/c4d/en-us/Content/html/OMOSPLINE-MGMOSPLINEOBJECT_TURTLE_GROUP_VALUES.html.md) 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 ![Image: 029768.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/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:** 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](https://help.maxon.net/c4d/en-us/Content/html/OMOSPLINE-ID_OBJECTPROPERTIES.html.md) 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 brackets ([ ]). 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] ![Image: 029769.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/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: ![Image: 029770.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/029770.jpg)\ A series of instruction symbols. Note that any letters (such as "A" here) can be used as a place holder. At the bottom right you will see that the default rotation was set to 90°. [![Image: halvar.png](https://help.maxon.net/c4d/en-us/Content/Resources/Images/halvar.png)](https://help.maxon.net/c4d/en-us/Content/Resources/Scenes/2025-2_MoG_42_.c4d) 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: ![Image: 029771.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/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 ![Image: 029772.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/029772.jpg) You can use the [User Data](https://help.maxon.net/c4d/en-us/Content/html/5826.html.md) 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: | | | | --- | --- | | **_total** | The total number of commands in the current string (see below) | | **_index** | The current command index in the string (see below( | | **_growth** | The current growth level | | **_level** | The current command level (if assigned, see below) | | **_x, _y, _z** | The current Turtle position in space. | | **_arg1, _arg2, _arg3, _arg4** | The first, second, third and fourth argument values (e.g., from F(1,2,3,4)) | | **_age** | The current command age (represents _growth - _level) beginning with 0.0. | | **_length** | The current arc length between Turtle and MoSpline origins. | | **_move** | The current default scale length. | | **_tropism** | The current Tropism. | | **_scale** | The current default scale. | | **_rotate** | The current default angle. | | | | All other available Cinema 4D formulas are listed [on this page](https://help.maxon.net/c4d/en-us/Content/html/6194.html.md). ## 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 "_RND" ![Image: 036260.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/036260.jpg) The following command: **Startstring****Premise**: A **Regel****Rule**: A=+(_rnd\*90)FA The, _rnd\*90’ command will ascertain a random angle between -90 and +90 for each growth spurt, i.e., a "wobbly" line with random rotations will result. ## 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°: ![Image: 029773.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/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 **F**s 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" ![Image: 029774.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/029774.jpg) [![Image: halvar.png](https://help.maxon.net/c4d/en-us/Content/Resources/Images/halvar.png)](https://help.maxon.net/c4d/en-us/Content/Resources/Scenes/2025-2_MoG_44_.c4d) 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: Cloner Object). 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](https://help.maxon.net/c4d/en-us/Content/html/6194.html.md). ### Premise Parameter ID: `MGMOSPLINEOBJECT_TURTLE` 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 Parameter ID: `MGMOSPLINEOBJECT_TURTLE_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\) 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). > **Tip:** Note:If you use e.g. 'rnd(1;12345)' for the random function, i.e. with an additional seed value, the L-systems do not change with each new evaluation or loading. ## Example "context rules" Rules can also be written in the following form: **Premise**: ABC **Rule**: A\ 1): ACC So what will happen? This depends on the sequence within the result string. The Rule "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 Parameter ID: `MGMOSPLINEOBJECT_TURTLE_OUTPUT` Displays syntax errors. ### Result String to Console Parameter ID: `MGMOSPLINEOBJECT_TURTLE_PRINT` 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 symbols from the fruits example with **Growth** set to 4): ![Image: 030013.jpg](https://help.maxon.net/c4d/en-us/Content/Resources/Images/030013.jpg)