Table of Contents
1. Creating the world |
2. Buttons and Procedures |
3. Sliders and Variables |
4. Creating Turtles and Patches |
5. Making the Model Go |
To finish the model we need to create a go
button. This will start the
model running.
go
. This will make the button start a procedure called 'go'.
You can give the button any name you want (typically people use 'Go', but you could use
'Begin model' or whatever, it doesn't matter).
to go
ask turtles [
  rt (random 360)
fd 1
if pcolor = green [
set pcolor brown
]
]
end
There are some more new commands in there, but they are quite easy to explain.
go
procedure does is run ask turtles
.
This means that all the commands in between the square brackets will be sent to the
turtles.rt (random 360)
tells the turtles to rotate a random amount from 0
to 360 degrees.fd 1
means move forward one step in whatever direction that they are
facing.
if pcolor = green [
set pcolor brown
]
mean "if the turtle is standing on a green patch, then make the colour of the patch
brown. Notice the use of square brackets to make it clear which commands should happen
if the colour of the patch is green. This basically makes it look like the turtle
(or sheep, if you prefer) has just eaten all the grass on that square.That's it! You now have a very simple simulation with some turtles that will move around and eat grass. With a few small additions to the code it is possible to have grass that grows and can be eaten, turtles that die if they do not have enough to eat, and a graph to show how many turtles are alive. We'll look at these changes next time. If you have the energy, you can move straight on to practical 3. Or, if you are ready to either cry or destroy the computer in front of you, go and have another cup of tea.