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