The previous sections made use of some predefined symbols
which have a meaning as turtle commands:
F
, RU
,
RH
, RL
,
Box
, Scale
. In
Section 1.4, “Third example: Creating branched structures - The graph”, it was clarified that these symbols
are nodes of a graph. Now the following question arises: What is
the possible set of symbols which can be used as nodes in an RGG?
In order to give the precise answer, we have to digress slightly
to Java: GroIMP and its RGG features are implemented in Java.
Thus, the graph of nodes which represents the visible structure
in GroIMP is also implemented in Java. As Java is an object-oriented
programming language, Java objects are instances
of classes, and so are the nodes of the graph:
Actually, the turtle command F
is a class
F
which is defined in the Java package
de.grogra.turtle
.
The turtle command Box
is a class
Box
which is defined in the Java package
de.grogra.imp3d.objects
. So a symbol
F
is a node of class de.grogra.turtle.F
in the graph.
If you are not familiar with these Java-related terms, please consult
the numerous literature on Java.
In general, every instance of a class which is a
subclass of de.grogra.graph.impl.Node
can be used as a node. GroIMP provides a lot of useful classes,
some of which are described in Chapter 2, Turtle commands and geometric objects.
But you can also define your own node classes: In an RGG file,
the simplest way to do this is to write a
module declaration:
module X;
This declares a simple node class X
. This class
can then be used like any other node classes (e.g., the turtle
commands). However, X
has no gemetrical
meaning, it is invisible. Nevertheless, such an invisible node can be
very useful.
This example uses invisible X
nodes
which represent the growing tips of a binary tree. The
growth
is implemented by replacing an X
node with
an F
line which bears two new
X
nodes as its branches:
X ==> F(1) [RU(30) X] [RU(-30) X];
It is also possible to declare parametrized modules:
module X(float length);
With the help of such a parametrized X
, the
example of a binary tree can be improved such that
child branches are shorter than their bearing parent branches:
X(len) ==> F(len) [RU(30) X(len*0.7)] [RU(-30) X(len*0.7)];
Click here to load the improved example and here to apply the growth rule.