User Tools

Site Tools


tutorials:exercises_plant_like_structures_abop

Implement 'plant like structures'

Implement the 'plant like structures' as described in the book “The Algorithmic Beauty of Plants” by Prusinkiewicz and Lindenmayer (1990) on page 25 in Figure 1.24.

Help

In order to have a X we need to define it as module. For this a module without any parameters, extends, or instantiations is doing the job just fine. While we already have a F symbol - a cylinder - in our default set of symbols, we will get some scaling issues when we use it directly, since the default dimension unit is meter, therefore, the generated will become several meters high and hardly visible when zoomed out. Therefore, we simply define us a new 'small F' (sF) as Cylinder of a better fitting dimension as given below. In this way, we also can adapt other properties like the colour.

// module definitions
module X;
module sF extends Cylinder(0.1,0.015).(setShader(RED));

Further replace the L-system commands + and - by RU rotations. So, + becomes RU(angle) and - is translated to RU(-angle).

Solution

For the initialization of out scene, we do not need to do much. Just set the correct start word as initial element.

// model initialization
protected void init() [
	Axiom ==> sF; // for a), b), and c)
	//Axiom ==> X;  // for d), e), and f)
]

Translating the rules is than just 'copy/paste' and the changes for F to sF, - to RU(angle), and - to RU(-angle).

The code for the six 'plant like structures' is given below.

public void runA() [
	sF ==> sF [RU(25.7) sF] sF [RU(-25.7) sF] sF;
]
 
public void runB() [
	sF ==> sF [RU(20) sF] sF [RU(-20) sF] [sF];
]
 
public void runC() [
	sF ==> sF sF RU(-22.5) 
	  [RU(-22.5) sF RU(22.5) sF  RU(22.5) sF] RU(22.5) 
	  [RU(22.5) sF RU(-22.5) sF  RU(-22.5) sF];
]
 
public void runD() [	
	X ==> sF [RU(20) X] sF [RU(-20) X] RU(20) X;
	sF ==> sF sF;
]
 
public void runE() [	
	X ==> sF [RU(25.7) X] [RU(-25.7) X] sF X;
	sF ==> sF sF;
]
 
public void runF() [	
	X ==> sF RU(-22.5) [[X] RU(22.5) X] RU(22.5) sF [RU(22.5) sF X] RU(-22.5) X;
	sF ==> sF sF;
]

And just as example, the output of c).

tutorials/exercises_plant_like_structures_abop.txt · Last modified: 2025/10/27 16:03 by MH