Lab 6 - Part II -Programming a Fire Model
Now, we want to add topography to the model. The topography we want might vary depending on what we want to study. If we want to see the effect of hilly topography we could do the same thing you learned to do in tutorial #3. You might want to have some other choices though, like a valley or a ridge to study the effect of elevation more closely.
We can do all these things by using switches. Make three switches in your interface – one for hilly topography, one for a valley, and one for a ridge. These switches will be set before the run. For now they do nothing. Let’s add the procedure that will make the switches work. Go to the procedures page and add lines for the green patches to set elevation. (You might want to look at tutorial #3 again.)
We will also want this topography to be smoothed somewhat. Use tutorial #3 to help you with this code. The arrangement and order of the steps is critical to the correct setup. You will want to put your procedures in an order that will end with the screen the way you want it. Color all patches with trees and density first. Then add elevation and smooth it before you shade color for altitude. After that you should add the border to prevent wrapping. Get your setup to work with the hilly switch on first. Your code will look something like this:
ask patches [ if hilly [ set elevation random 10000 ] ] repeat smoothness [diffuse elevation 1 ] ask patches [ set pcolor scale-color green elevation 0 10000 ]
When we scale color, we want to scale only the green ones so we add “ with [ pcolor = green] after ask patches in the scale color code. You may also change the values after elevation in the same line to something negative and something below 10000 to make the green cover more of the screen with not so much black and white. Now let’s see if we can make a topography to represent a ridge or a valley. We will add these other alternatives after the hilly switch, so it looks like this:
ask patches [ if hilly [ set elevation random 10000 ]
if valley [ ]
if ridge [ ] ]
Now, we need to decide how the valley and ridge will run. It really makes no difference because the wind direction can be adjusted in any direction. The valley could run with the pxcor or the pycor or from corner to corner. We will ask the patches to set their elevation to represent a valley based on their pycor and the valley will run with the pxcor.
The pycor of zero will be the bottom of the valley and the sides will rise as you move to the top or bottom of the screen. The equation you need will set elevation equal to zero plus the absolute value of the pycor times a hundred. To make the ridge, start at elevation 10000 and subtract the pycor times a hundred. This does not work well on a small screen so make the screen 100 X 100 and make the pixels about 2.5 in size. The result will look very smooth – too smooth. To give the forest some texture in the case of the valley and the ridge, add an “if” statement that applies only to the green patches and asks them to set their elevation like this:
if pcolor = green [ set elevation (0 + (abs pycor * 90) + random 1000) ]
Mouse down to ignite fire
In the models library is an example of how to write code to use the mouse to draw on the screen. Study the setup of this example, as we will use it to enable us to start fires in our forest. You will need a button on the interface and the matching code in the procedure. Use the patch draw example. Checkpoint – Your interface now looks something like this:
|