This is an old revision of the document!
Parameter Manager
This tutorial will go through how to get started with parameter managers. It will start with an overly simple project to highlight some key features, then, apply the same parameter management to a more advanced project.
Project description
The first project is a simple “newRGG” type project. It will be composed of shoots (cylinders) and buds (spheres). The single growth rule replace a bud by a shoot and two buds.
We consider 2 types of bud that will make the growth slightly different: a green one, and a blue one. They both extend the same base bud module.
We first declare the three type of modules that will represent the possible type of “bud”.
module BaseBud(super.radius) extends Sphere { int age = 0; void grow(){ switch(aging){ case 0: age+=1; break; case 1: age = (age>1)? age*age : (age>0)? 2 : 1; break; default: } } } module GBud(super.radius) extends BaseBud.(setShader(GREEN)) { void grow(){ super.grow(); radius *= 0.8; } } module BBud(super.radius) extends BaseBud.(setShader(BLUE)) { void grow(){ super.grow(); radius *= 0.6; } }
Then we define some variables that represent the configuration of the project:
- aging : the type of aging 0 or 1, it trigger the method declared in BaseBud
- ageLimit : the threshold after which a bud cannot be replaced anymore (I know that's not how plant works but it is an example - could be any type of variable)
- budType : 0 or 1 for green of blue bud
- initialLength : the initial length of the shoot.
public global int aging = 0; public global int ageLimit = 10; public global int budType = 0; public global float initialLength = 0.8;
Then, we can declare a Bud factory, i.e. a method that produce the type of bud based on the budType:
BaseBud pBud(float len) { switch (budType) { case 0: return new GBud(len); case 1: return new BBud(len); default: return null; } }
Lastly, the initialization and growth rule:
protected void init () [ Axiom ==> pBud(initialLength); ] public void run () [ b:BaseBud(x), (!tooOld(b)) ==> F(x) [RU(30) RH(90) pBud(b[radius]).($[age]=b[age], grow())] [RU(-30) RH(90) pBud(b[radius]).($[age]=b[age], grow())]; ]
