patches

 

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