patch

 

Patches are a special kind of stationary agents in NetLogo that make up the world of a model. You can think of the patches as the squares that make up a chessboard.

The patch primitive reports the specific patch with the given coordinates. For example, if we wanted to create a model of an ant colony whose entrance was the patch at the center, we could write the following code:

ask patch 0 0 [
    set pcolor green
]

The patches primitive reports all the patches in the model. This primitive is helpful in asking all the patches to do the same things (e.g., change pcolor) or narrow down a subset of patches. For example, if we wanted to create a forest fire model with some green patches representing trees, some green patches representing ground, and the leftmost patches representing the fire (red), we would write the following code:

ask patches [
    set pcolor one-of [green brown]
]
ask patches with [pxcor = min-pxcor][
    set pcolor red
]

Things to keep in mind when using patch and patches:

In the model example below, we have a farm that is surrounded with a fence. The fence is represented with brown patches and the grassland is represented with green or lime patches. We also have a yellow square in the middle that represents a ranch and some cows who move around randomly and eat the grass on each patch until there is no grass left.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the patch primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the patch primitive:
 
 
Similar primitives:
patches

Reports an agentset that contains all the patches in a model.

Read more
clear-patches

Clears the patches by resetting all patch variables to their default initial values and making them black.

Read more
patches-own

Defines custom characteristics (variables) for patches. Each custom characteristic can have a different value for each patch.

Read more
neighbors

Reports an agentset containing the eight neighboring patches.

Read more
 
Learn another primitive: