Table of Contents

XL turtle geometry and graph construction

This tutorial is only on the static construction of a 3D model and the underlying graph. There is nothing chaining and there are not steps involved. Therefor our base code structure only requires the init function:

protected void init ()
[
	Axiom ==> F;
]
The 3d view and the graph structure created by the init function above

This function is called very time you reset your model.(either with the rest button by recompiling/saving the code). The basic theory behind it is that the model always rests to the Axiom node and then runs the init function, if one is provided.

Turtle commands

That if we replace the Axiom with an F, a F node appears in the 2d graph is quite strait forward. The fact that this turns into a Cylinder in 3d is a bit more of a stretch. This is happening because 'F' is a so called turtle command.

Each turtle command is interpreted for the creation of the 3d model. We can imagine that a “turtle” starts at position (0,0,0) in the 3D scene and then follows the instructions given by the nodes in the graph. Reading the graph starts at the top at Node.0 and goes down through the nodes. The first two nodes (Node.0 and RGGRoot) have no effect on the turtle, but a F tells the turtle to draw a cylinder and move to the end of that cylinder. Therefore a second F would tell the turtle to do the same thing again:

protected void init ()
[
	Axiom ==> F F;
]
The 3D and 2D representation of two F's one after another

Now looking at the list of turtle commands, we can see that F is suppose to have a parameter, which we did not give yet. If no parameter is provided most turtle commands will fall back to a default value, which means in the most cases that they do just nothing. Yet in the case of an F the default value is a length of 1 meter and a diameter of 10 cm. Meaning Axiom ==> F(1,0.1) F(1,0.1); would provide us with the exact same 3D model, but if you play around with this parameters you can change the dimensions of your cylinders.

To bring in a second command, you can try M which moves the turtle without drawing anything. M only takes one parameter for the distance and has the same default distance of 1 meter. You can combine them in any way you want

protected void init ()
[
  Axiom ==> F M F(0.2,2);
]
One F followed by a M and then a short F with a large diameter

Transformation

In the classic turtle geometry approach the F is the only visible object (no worries we will see a fix for that later), all other turtle commands are only giving instructions to the turtle on how and where to draw future cylinders. This instruction are mainly about transforming (moving, rotation, scaling) the F.

The moving part is already covered by the M node for now.

You can rotate the turtle along the three axes x, y and z. We can see an example of the rotation tool on the right with the possible rotations in colors: x=red, y=blue and z=green. In the turtle geometry we can rotate these axes with the commands RL(angle), RU(angle) and RH(angle). RL rotates around the local X-axis (the red circle in the picture), RU around the Y-axis (the blue circle) and RH around the Z-axis. If we imagine to look from the perspective of the turtle, the names make more sense: RL rotates to the left (with negative values to the right), RU rotates up and RH rotates around the head axes.

Following up on our little example above you could think about rotation the short cylinder 30 degrees up like:

protected void init ()
[
  Axiom ==> F RU(30) F(0.2,2);
]
The result of rotating the second cylinder up 30 degrees

You can try this also with the RL command and will a very similar result, with RH on the other hand you will see nothing because a cylinder is round and you cant see if it is rotated on the head axes.

That brings us to the next step: combining transformations, because even so the RH command does not give us a visible result it changes the orientation of the turtle and therefore influences all following commands for instance other rotations:

protected void init ()
[
   Axiom ==> F RH(150)RU(30) F(0.2,2);
]
The result of rotating the turtle first on the head axes and then rotate it up

You can now try to switch the order of the commands to F RU(30) RH(150)F(0.2,2) and you will see the same result as without the RH because only the already up-rotated cylinder is now rotated around its head.

Looking at the list of turtle commands, you can see that there are more rotations such as RV or RD you can explore.

There are also more computer graphics oriented approaches embedded in the GroIMP turtle commands: Translate(x,y,z) Rotate(x,y,z) and Scale(x,y,z).

Translate is moving the turtle for the given values on the local x,y,z axes:

protected void init ()
[
	Axiom ==> F Translate(3,0,1)F(0.2,2);
]

Similarly the Rotation command is rotating around all 3 local axes at the same time. They do not influence each other that way so a rotation on the head axes would once again be not that impressive in our case.

protected void init ()
[
	Axiom ==> F Rotate(20,30,0)F(0.2,2);
]

Finally the scale command can be used to change the size of all following commands, either proportionally or depending on the axes. For example if you want your howl model to be halve the size without chaining any parameter you could just add a Scale(0.5) in the beginning:

protected void init ()
[
	Axiom ==> Scale(0.5) F Rotate(20,30,0)F(0.2,2);
]

This will give us the same result as before only a smaller… Additionally, if we would like to be our cylinders to be not round but oval we can use the scale command as well, but with three parameters for the axes. For example we can turn the upper F in to a oval like this:

protected void init ()
[
	Axiom ==> F Rotate(20,30,0)Scale(0.2,1,1)F(0.2,2);
]

3D objects

Modules

Instantiation rules

Edge types

Branches

Decomposition & custom