Teaching Aid

Query (5) / operator “instanceof”

 

 
Copy/Paste the following code to your GroIMP project:
//**********************************************************
/*
You will learn:
– the use of a query for arbitrary nodes (type Node)
with subsequent checking of the found type with “instanceof”.
*/

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

module A;

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

public void run()
[

// The node preceding a node of type B is checked.
// If this node is not of type A, the first rule will be applied.
// The check is done with a condition which the result of the query
// must fulfill.

(* x:Node *) B, (!(x instanceof A)) ==> F(5, 1, 4) B;

(* A *) B ==> F(10, 1, 14) [ RU(30) B ] A 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.