Gol
Gol

Reputation: 27

Changing the color of agents in NetLogo according to a turtle-own variable

I am writing a simple food exchange model in netlogo and I want the agents to change their color as their [food] level changes in the model. The amount of food is in range [0,1] and I want the color to change from white to red (white = food level of zero and red = food level of 1) with the code below:

ask turtles [
    set color scale-color red food 1  0 ]

But my turtles turn black somehow in the middle of food exchange! Turtles own food value can be any floating point number in the range [0,1]. Does anyone know how I can keep the color within the light shades of red (red to white) and no black?

Upvotes: 0

Views: 519

Answers (1)

javylow
javylow

Reputation: 119

Scale-color and ranges

From the example above, the color and number are correct, but the issue seems to be with the range provided. Since food is within [0,1], the color gradient should match the changes, though it will be from 0 (white) to 1 (black).

As JenB mentioned, you might want to extend the range of the expected values. Changing the range from [0,1] to [0,2] for scale-color would help, since with scale-color the midpoint of the range is the color provided.

[ set color scale-color red food 2 0 ]

As long as food is within [0,1], this example should fluctuate between red and white.

Upvotes: 1

Related Questions