Coloring Agent Using NetLogo

I am trying to simulate the colors of newsletters on a mobile bulletin board using NetLogo. I can change the color of my colors when they meet, but the color change is random, and sometimes ballots that have the same color touch or close together in my radius. I would like the newsletters to have a unique color in this raduis.Here is part 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
+3
source share
1 answer

Here is one way to do this:

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

, base-colors , " ", . , , .

+3

All Articles