Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Agent Coloring With NetLogo

Tags:

netlogo

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
like image 252
Y. Leonce Eyog Avatar asked Feb 25 '26 11:02

Y. Leonce Eyog


1 Answers

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.

like image 70
Nicolas Payette Avatar answered Feb 28 '26 09:02

Nicolas Payette



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!