Chapter 4. Using properties

Table of Contents

4.1. Initializing properties
4.2. Reading properties
4.3. Setting properties

Each node in GroIMP's graph has a set of properties. For example, every node has a name. A sphere additionally has a radius, a location in space, a shader which defines its appearance, and some other properties.

4.1. Initializing properties

The basic geometric properties of a geometric node can be set in its constructor: The class Sphere declares the constructor Sphere(float radius) which initializes the radius with the specified value, for the turtle command RU the constructor RU(float radius) is defined which initializes the rotation angle. However, there is no constructor in these classes which initializes the name or (in case of the Sphere) the shader. This is because generally it would not be feasible to provide constructors for all combinations of properties which the modeller wants to initialize.

Nevertheless, one often wants to initialize properties which are not accessible through the constructor. For this purpose, the classes define setter methods like setRadius(float radius) in class Sphere to initialize values of these properties. These can be invoked immediately after the constructor with the help of a special syntax (instance scope expressions of the XL programming language) as in

Axiom ==> Sphere(1).(setShader(RED), setTransform(0, 0, 1));

As in this example, a constructor expression (or in fact any expression) can be followed by a "." and a parenthesized comma-separated list of method invocations (or in fact statements). Within the parenthesized list, the result of the constructor is used as the implicit this for the method invocations. The example creates a sphere of radius 1, sets its shader to the colour red and translates it to the relative location (0, 0, 1). Such a coloured sphere is used in this simple example, where you should have a look at the method init. The methods swap and grow will be discussed in the next sections.