GEOG3150 - GIS, Geocomputation and Geoplanning - Semster 2


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

Practical 2, part 4 - Creating Turtles and Patches


In this part of the practical, we will start to create the fundamental components of our model: the turtles and the patches.

  1. Click on the 'Code' tab. You should see the setup procedure. We will now improve it so that it does something more useful.
  2. Change the setup function so that it reads: to setup
     print "Setting Up Model"
     clear-all
     setup-patches
     setup-turtles
    end
  3. The clear-all command tells NetLogo to reset everything ready for us to create a new model. The other two lines (setup-patches and setup-turtles) call two new procedures that will contain commands to set up the turtles and patches. We could put these commands directly into the setup procedure, but by putting them into their own separate procedures it makes the model code easier to understand.

  4. Here is the code for the two new procedures. Copy it directly after the end of the setup function. to setup-patches
     ask patches [ set pcolor green ]
    end

    to setup-turtles
      create-turtles initial-number-of-turtles
      ask turtles [
       set shape "sheep"
       setxy (random 20) (random 20)
       set color blue
      ]
    end
  5. The code above should be fairly self-explanatory. The first procedure (setup-patches) does one thing: it asks all the patches to change their colour to green. This means that each patch will represent a square of grass, ready to be eaten by the turtles.

    The second procedure (setup-turtles) creates the turtles. There are some new commands in there that you wont be familiar with:

    After setting up the mode: turtles and some grass.

    Now, try going back to the 'Interface' tab. If you have made any mistakes with the model code, NetLogo will tell you about them. Otherwise you will see the main interface again.

  6. Press the setup button. You should see a few turtles created around the grid.
  7. Press the setup button again. What happens?

That's almost everything. To finish the basic model, move onto the final section to get the sheep moving around the environment.

Activities

  1. Write a procedure called 'make-white' that tells all the turtles to turn white. (For this, you will need to use the ask command as we did in the last practical).  
     
     
  2. Write a procedure called 'white-then-move' that first makes all the turtles go white, and then moves them forward 1 step. (Hint: the command fd 1 tells a turtle to go one step forward).  
     
     

[School of Geography homepage] [Leeds University homepage]