Ave555
Ave555

Reputation: 39

How can I change color of turtles over time in Netlogo?

In the simulation I am working on, I have red turtles. I want them to be yellow at the beginning, then turn orange after 10 ticks, then red after 10 other ticks. How can I do so ?

to ignite
  ask fires [
    if count neighbors > 0 [
      ask one-of neighbors with [pcolor = white or pcolor = green ]
      [
        if count fires-here < 6 [
          sprout-fires 3
          [ set color red set size 3 ]
        ]
      ]
    ]
  ]
end

Upvotes: 2

Views: 522

Answers (1)

JenB
JenB

Reputation: 17678

Note that you have tick in your setup procedure as provided. That needs to be in your go procedure. setup is for everything when the simulation starts, and go is what happens each time step. The command tick advances the counter for the time steps, and the reporter ticks reads the time step counter.

If you are going to change a turtle's colour based on how long it's been alive, the first thing you need to do is to have the turtle know when it is 'born', so create a variable for that and store the current value of ticks in that variable during the creation.

fires-own
[ state     ; you have this already
  birth-tick   ; this is the new one
]

Change this:

      sprout-fires 3
      [ set color red set size 3 set state "live"]

to this (note that spacing does not matter to NetLogo, but helps with readability)

      sprout-fires 3
      [ set color red
        set size 3
        set state "live"
        set birth-tick ticks
      ]

So that creates the birth time. Now, within your go procedure (which you don't show), you want all the turtles that are 10 ticks old to change colour. One way is:

ask fires with [ birth-tick = ticks - 10 ] [ set color orange ]

Upvotes: 2

Related Questions