User Tools

Site Tools


tutorials:radiation-model-in-crop_model4

Introducing absorbing tiles

Open the file Tiles.gsz.

We also want to visualize how much light is reaching the ground. To do that, we cover the soil surface around the plant with light-absorbing tiles. First of all, you need to declare a new module:

// light absorbing tile
module Tile(float len, float wid) extends Parallelogram(len, wid)
{
	float al;
};

Note that we declare the variable al, which will be used to store the light absorbed by a tile, in a different way, namely not between parentheses but between curly braces and on a new line. We could have declared module Tile(float len, float wid, float al) …, and this would not have made a big difference. However, the method to declare variables in parentheses behind the name becomes increasingly cumbersome when we are dealing with many variables. Also, when we declare the variables in this new way, we can refer to them in a more straightforward way, for instance

t:Tile ::> t[al]

and don’t need to worry about the position of the variable in the module declaration (as was the case in parametric L-systems).

In the Axiom rule, preceding the Bud, we place 1600 (40 x 40) tiles (L. 84ff):

Axiom ==> //insert light absorbing tiles here: 
	[
		RL(90) M(4) RU(90) M(-4)
		for((1:40)) (
			for((1:40)) (
				Tile(0.25,0.25).(setShader(new RGBAShader(0.6, 0.3, 0.1)))
				)
				M(-10) RU(90) M(0.25) RU(-90)
			)
	]
 
	Bud(1, PHYLLOCHRON, 1);

Like the leaves, the tiles will become brighter when they absorb light. Update is done within the absorbAndGrow() method:

        //repainting the tiles:
	t:Tile ::> {
	t[al] = lm.getAbsorbedPower3d(t).integrate();
		//println(lf[al]);
		t.(setShader(new AlgorithmSwitchShader(
		new RGBAShader(t[al]*300, t[al]*200, t[al]),
		new RGBAShader(0.6, 0.3, 0.1))));
	}

Task: Obtain the sum of light that is absorbed by the tiles and plot it! (Hint: you can simply add a column “1” to the existing data table and then extend the method updateChart() with the sum function).

tutorials/radiation-model-in-crop_model4.txt · Last modified: 2025/05/27 17:58 by barley1965