Patches

In a NetLogo model patches are stationary agents. We can think of patches as water lilies floating in the pond, but of course patches don't have to represent water lilies. They can represent trees in a forest, mountains and valleys in a terrain, shops in a market, neighborhoods in a city, etc.

We can see the patches in the following image as each is a random shade of blue:

Patch Attributes

Every patch encapsulates five pre-defined attributes (an attribute is a variable owned by a turtle or patch):

pxcor

pycor

pcolor

plabel

plabel-color

Additional attributes can be defined as follows:

patches-own [penergy pdepth ptemperature]

Note: All names must be distinct in NetLogo (no overloading). Conventionally, names of patch attributes begin with p. This keeps them from colliding with similarly named turtle attributes.

We can change these attributes using the set command:

set VARIABLE EXPRESSION

For example, here's a procedure a patch can execute to initialize its attributes:

to init-patch
  set pdepth random 100
  set ptemperature random 100
  set penergy random 100
  set pcolor blue
  set plabel-color red
  set plabel "?"
end

Here's a snapshot of the pond after each patch has executed this procedure:

We can inspect and change the attributes of an individual patch by clicking on it with the right mouse button:

Note: I set the plabel-color of patch -2 4 to white to make it visible.

Pond Coordinates

Each patch has a fixed position given by its pxcor and pycor attributes. Think of pxcor as the patch's longitude or column and pycor as its latitude or row:

Note: Unlike turtles, patches are stationary. We can't change their positions.

Initially, patch co-ordinates run from (-16, 16) in the upper left corner to (16, -16) in the lower right corner, with patch (0, 0) always in the center. But the settings button displays the Model Settings dialog, which allows programmers to modify the attributes of the World (i.e., the pond), including maximum pxcor and pycor, patch size, location of origin, horizontal and vertical wrapping, etc.

Patches Procedures

Although patches can't move, they are still agents. They encapsulate attributes and they can execute procedures.

Here's how we can ask the patch with pxcor = pycor = 0 to execute a block of procedures

ask patch 0 0 [advertise sell restock]

Of course we can ask sets of patches to execute blocks of procedures:

ask patches [advertise sell restock]

What can patches do?

A patch knows about nearby patches and turtles. For example, here's how a patch in a video game might explode

to explode
  ask patches in-radius 5 [set pcolor red]
  ask turtles in-radius 5 [die]
  wait 3 ; wait 3 seconds
  ask patches in-radius 5 [set pcolor black]
end

In this screen shot patch 0 0 is exploding:

A patch knows all of the turtles that are on it:

to heat-up
   ask turtles-here [dance wiggle squirm]
end

A patch can also give birth to turtles:

to bloom
   sprout 10
end