color

 

color is a built-in turtle characteristic that represents the color of each turtle in a NetLogo model. Every time we create new turtles, each one is assigned a random color. We can use the set primitive and the color primitive together to change a turtle's color as follows: set color red.

ask turtles [
    ifelse size > 2 [
        set color red
    ][
        set color green
    ]
]

color is also a reporter; we can use it to access the color of a turtle as follows:

ask turtles with [color = red][
    set size 5
]

Things to keep in mind when using color:

In the model example below, we have a white sheep and some plants. We use the color primitive to make some of the plants green and some yellow. We use the ask turtles with [color = white] to just ask the sheep to move, while the plants remain stationary. Our sheep moves around randomly. When there is a yellow plant on the same patch, our sheep just ignores it. However, if there is a green plant on the same patch, our sheep eats the green plant.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

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

Reports a patch's color and changes a patch's color when used with the set primitive.

Read more
scale-color

Reports a shade of a base hue (color) based on where a speficied value falls is within a specified range (min-max).

Read more
turtles-own

Declare a variable that belongs to turtles.

Read more
of

Reports the value of an agent-owned variable.

Read more
 
Learn another primitive: