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 3 - Sliders and Variables


You've now seen how buttons and procedures work together. Now, you will see how sliders connect up to variables (if you need to refresh your memory, there is information about variables in the lecture or in the previous section).

  1. Create a slider in the same way that you created a button.
  2. This slider is going to tell our model how many turtles should be created initially. Set the following values (as illustrated below)
  3. A new slider
  4. Press OK to create the slider. Note: if you would like to change its position, right click on it and choose 'Select'. You can then move it around.
  5. Now the slider is ready. Next we'll go back into the model code and make some improvements so that it does something more useful.

That was easy enough. In the next section we'll look more closely at how we can use the slider in the model. But first, have a go at the activities below.

Activities

These activities will check that you're familiar with how to write procedures. Before starting, type the following code into the Command Centre:

create-turtles 10 [ set xcor random 10 set ycor random 10 ]

This will temporarily create ten new turtles - we need these to see if your procedures are working properly. For the following questions, write the required code in the 'Code' section of NetLogo, and then run your commands from the Command Centre by simply typing the name of the procedure. For example, if you have created a procedure called do-something you simply type 'do-something' in the Command Centre to run it.

  1. Write the NetLogo code that creates a new procedure called 'hello' to print the text "Hello World". Once you have written the procedure, typing 'hello' into the Command Centre will run it.  
     
     
  2. Write a procedure called 'make-blue' that tells all the turtles to turn (blue). (For this, you will need to use the ask command as we did in the last practical). Once you have written the procedure in the 'Code' tab, type 'make-blue' into the Command Centre to run it.  
     
     
  3. Write a procedure called 'blue-then-move' that first makes all the turtles go blue, 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]