Turtles with Drinking Problems

Turtles randomly swim around the pond in this model. Random walks (or swims) occur in nature and are studied in physics and economics. Think of the flight of a butterfly, the daily fluctuations of the DOW, or the movement of a molecule in a container of hot gas.

We begin by saving a copy of the Eco-0 framework (eco-0.nlogo) as drunk-turtles.nlogo.

Next, we redefine the turtle and patch initialization procedures:

to init-patch
  set pcolor blue
end

to init-turtle
  set shape "turtle"
  set color red
  set size 3
  set xcor random-xcor
  set ycor random-ycor
  pen-down
end

The init-turtle procedures sets the shape of the executing turtle to the "turtle" shape. NetLogo provides a number of pre-defined shapes: airplane, bug, cow, person, etc. as well as a shapes editor for creating custom shapes (see the user's manual for details).

After the color and size attributes are set, the x and y coordinates of the turtle are set to random positions within the pond. Clicking on the settings button in the upper right corner of the interface displays the settings for the World (what I call the "pond"). We can see from this that each patch has unique coordinates with the center patch at the origin:

Finally, the turtle lowers its pen by calling pen-down (pd). This will cause the turtle to draw red lines as it moves.

Finally, we need to implement the update-turtle procedure:

to update-turtle
  set heading random 360
  forward random 10
end

Each turtle has a heading given in degrees with heading zero degrees (north) being the top of the screen and 180 degrees (south) being the bottom. NetLogo provides a wide variety of commands for turning and moving turtles. The forward 10 command advances the turtle forward 10 steps. Because the turtles' pens are down, they will trace their path

Here's a screen shot of the interface after 82 ticks: