Definition of the example collage grammar

Here's the complete definition of the collage grammar that we use for our example. The following is the exact content of the grammar file that forms the input of the CollageSystem.

% sierpx - combination of 'the tunnel' with the sierpinsky gasket.

/annotated

/f sierp_%.ps

/ccp

grammar
	start
		pins
		edge T 0,30 50,30 50,80 0,80
		edge S 0,0  100,0  50,100
 		endcollage

	% Rules for the first (building) table:

	rule S prob 0.2
		pins 0,0  100,0  50,100
		edge S 0,0  50,0  25,50
		edge S 50,0  100,0  75,50
		edge S 25,50  75,50 50,100
		endcollage
	table 1
	
	rule T
		pins 0,0 100,0 100,100 0,100
		fpgon 0,0 28,0 15,75 100,92 100,100 90,100 25,65
		edge T 100,100 100,0 185,0 185,100
 		endcollage
	table 1
	

	% Rules for the second (terminating) table:

	rule S prob 0.2
		pins 0,0  100,0  50,100
		fpolygon 0,100  90,90  50,-40 color 20
		endcollage
	table 2
	rule S prob 0.2
		pins 0,0  100,0  50,100
		fpolygon 10,10  90,10  90,70  20,60  color 6
		endcollage
	table 2
	rule S prob 0.2
		pins 0,0  100,0  50,100
		fpolygon 40,0 80,40  70,80  30,90  -20,-20 color 40
		endcollage
	table 2
	
	rule T
		pins 0,0 100,0 100,100 0,100
		fpgon 0,0 28,0 15,75 100,92 100,100 90,100 25,65
 	endcollage
	table 2
	

derivation
until 25 do 1
until 26 do 2

First of all, don't panic! Although this is not a trivial example, the structure is very simple and some parts are also redundant.

The overall idea of this example is to combine two simple examples into one which yields an interesting optical effect. The two components don't interact, i.e. they develop absolutely context-free so that you could comment out one of them without affecting the other.

The two different components are both initialized in the start collage by their corresponding hyperedges named S and T. The S-hyperedge produces a figure known as the sierpinsky gasket (a triangle that contains three smaller copies of itself, each of them containing three smaller copies of itself etc.). The T-hyperedge produces an infinitely long 'tunnel'.

The rules are distributed over two tables. The S- and T-rule in the first table refine or develop the figure by adding new hyperedges. The tunnel grows linear (adding one hyperedge of its own label each step) whereas the sierpinsky gasket grows exponential (adding three hyperedges of its own label each step). To deal with the rapid development speed of the sierpinsky gasket, we have given low probabilities to the S-rules (0.2) thus making the whole thing a non-deterministic collage grammar.

The rules of the second table are all terminating rules, i.e. the collages produced by these rules do not contain any more hyperedges but only parts. For the S-rules we have defined three alternative terminating rules, each producing a different part and each with a probability of 0.2. Note that on the other hand this means that 40% (100% - 3*20%) of all S-hyperedges are not terminated at all in our example. The terminating rule for the T-hyperedges produces the same part as the T-rule in the first table.

The derivation part is a very typical one: Use rules of the refining/developing table for n steps and use rules of the terminating table in step n+1.

That's all! That wasn't that difficult, was it?

Note: You could write this example grammar with less code by using the preprocessor directives (#define, #if etc.). We didn't make use of the preprocessor in the example to keep it as simple as possible.

Now we can move on and see some of the pictures that the screen view generates out of this definition...