pcolor

 

pcolor is a built-in patch variable that reports the color of a patch. Because pcolor is a variable, as well as a reporter, you can use set to change it. pcolor can be set by simply stating the color (e.g., brown, yellow, red; note that there are no quotation marks around the color names) or NetLogo color (a single number). For example, if we wanted to make our patches blue to represent an ocean and then create an island in the middle, we would write the following code:

ask patches [
    set pcolor blue
    if distancexy 0 0 < 5 [
        set pcolor brown
    ]
]

If we wanted to put some trees on our island, pcolor would be useful as follows:

create-trees 10 [
    move-to one-of patches with [pcolor = green]
]

Things to keep in mind when using pcolor:

In the model example below, we have some sheep that wander around randomly. We use pcolor to make some of our patches brown to represent ground and some of our patches green to represent grass. Sheep can only eat when they are on a patch with grass on it, so they can only eat if pcolor = green . This model not only changes the pcolor of a patch using set, but it shows how pcolor can be used in conditional statements.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the pcolor primitive:
 
 
Similar primitives:
color

Built-in turtle characteristic that reports the color of a turtle and allows us to change it.

Read more
set

Changes the value of a variable (global, local, or agent-owned).

Read more
patches

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

Read more
neighbors

Reports an agentset containing the eight neighboring patches.

Read more
 
Learn another primitive: