GroIMP Module XL English
Spoken text
To demonstrate the functionality of the turtle interpretation in more detail, we first look at this small example.
If you want to use your own symbols in addition to the predefined turtle commands such as F or Sphere, you have to declare them as modules first. This can be useful for making a program clearer and easier to understand. Instead of using the Sphere command for a bud, you can directly use "Bud", this facilitates the modeling and understanding of the model code distinctly.
It is important that the characteristics of the existing turtle commands are inherited to these declared modules, what is happening here with "extends Sphere". If you want to use parameters for the length or diameter of the modules in the following program, you have to declare these as well.
By defining your own modules including own parameters the concept of parametric L-systems is clarified. Real-valued parameters can be utilized not only by the turtle commands, but for all characters. The characters can be provided with finite parameter lists of any length, which all can be used and changed as attributes of the object. This is another great advantage of using your own modules.
In this example, two new modules are declared, each having the width as a floating-point parameter. The properties of a sphere are inherited. The apical bud and the lateral buds are differentiated. The initiator is an apical bud with a diameter of 0.2.
In the subsequent "public" run() method the rewriting rules are defined. Due to the fact that this method is public and not "protected" like the initiator, the run button is available as a control instrument for the simulation. The name must not necessarily be "run", but this naming is suggestive.
There are two rewriting rules: The apical bud and the lateral buds are replaced in each derivation step by the according right-hand rule side.
By pressing the "run" button, one derivation step is executed. By the first execution only the start bud is replaced. The second rule is not applied, because only after the first execution a lateral bud exists. The present lateral bud is visually occluded by the apical bud. Only in the second step, there is a simultaneous replacement.
The derivation chain after three executions of the rewriting rules looks like this. The turtle geometry interprets the currently existing derivation chain, whereby the shown structure arises.