Reputation: 903
I'm trying to model the colors of bulletins in a mobile bulletin board with NetLogo. I'm able to have the bulleting change their colors when they meet but the color change is random and sometimes bulletins having the same color are touching or close together in my radius I'd like to have the bulletins have a unique color in a given raduis.Here is a fraction of my code.Can anyone help me out?
to color-bulletins
ask bulletins [
ask other bulletins in-radius 2[
ask one-of bulletins [ set color green]
ask one-of bulletins [ set color white ]
ask one-of bulletins [ set color yellow]
ask one-of bulletins [ set color blue ]
]]
end
Upvotes: 3
Views: 114
Reputation: 14972
Here is one way to do it:
breed [ bulletins bulletin ]
to setup
ca
create-bulletins 1000 [ setxy random-xcor random-ycor ]
end
to color-bulletins
ask bulletins [
let used-colors [ color ] of other bulletins in-radius 2
let available-colors filter [ not member? ? used-colors ] base-colors
set color ifelse-value (length available-colors > 0)
[ one-of available-colors ]
[ one-of base-colors ]
]
end
This assumes that you want to use only the base-colors
and that they could all be used already, in which case you'd still get a "color collision", but there is nothing you could do about it. Unless the spatial distribution of your agents is fairly dense, tough, it should not happen too often.
Upvotes: 3