Teaching Aid

Query (6) / if/else on rhs of rule

 

 
Copy/Paste the following code to your GroIMP project:
//**********************************************************
/*
You will learn:
– the use of a query on the left-hand side of a rule in connection
with an if/else control structure.
*/

module B extends Sphere(0.1)
{{setShader(GREEN);}};

// module A will not be drawn.
module A;

protected void init()
[
Axiom ==> F(10, 1, 14) [ RU(30) B ] [ RU(-30) A B ];
]

public void run()
[

// The right-hand side of the rule is controlled by an if-else structure.
// Its condition uses a query.
// The aggregation operator empty() checks the result set of the query
// (is the number of graphs contained in the result == 0 ?)
// Only the branch marked with A continues to branch.

b:B ==> if ((empty((* b -ancestor-> A *))))
( F(10, 1, 4) B )
else
( F(10, 1, 14) [ RU(30) B ] B );
]

//**********************************************************
 

DATE: 2009

 

AUTHOR: W. Kurth

 

DESCRIPTION: see model

 

Welcome to the website grogra.de. This site is the web centre of growth grammars of the Department Ecoinformatics, Biometrics and Forest Growth at the Georg-August University of Göttingen and its cooperation partners.