scale-color

 

scale-color is a primitive that reports a shade of a color proportional to the value of a given number. For example, if we wanted to create a traffic model in which cars with fuller tanks were brighter than those with emptier tanks, we would write the following code:

ask cars [
    set color scale-color white tank-level 0 100
]

Or if we wanted to model a flock of sheep where more lush patches of grass were brighter than those that have already been eaten, we would write the following code:

ask patches [
    set pcolor scale-color green lushness 0 100
]

Things to keep in mind when using scale-color:

In the model example below, we use scale-color to adjust the color of each patch to reflect its nutrition level (1 being lowest, 5 being highest). Each time our farmer moves onto a patch, it checks the nutrition level there. If the nutrition level is above 3, the farmer plants a vegetable. We also color the vegetables using scale-color based on the nutrition level of its patch. The vegetables that get more nutrition have a brighter green color.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the scale-color primitive:
 
 
Similar primitives:
color

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

Read more
pcolor

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

Read more
set

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

Read more
turtles-own

Declare a variable that belongs to turtles.

Read more
 
Learn another primitive: