user2960895
user2960895

Reputation: 101

Change patch colour over time / ticks

I need some assistance with my NetLogo model please.

Currently I have turtles (cows) roaming round a field. At a set rate they change patch colour from green to brown (representing defecation on that patch). However, as it stands, those patches remain brown forever, I want to code it so that after a set number of ticks (determined by a slider I have made) the patch colour changes back to green (representing the degradation of the dung).

My current coding for defecation is as follows:

to cow-defecate
  ask untreated-cows
    [if random 100 < defecation-rate [set pcolor brown]]
end

Any help is greatly appreciated - thank you.

Upvotes: 1

Views: 1023

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

I'd suggest looking at the Wolf Sheep Predation model, in the Biology section of the NetLogo Models Library. It has code that does exactly this.

The relevant parts of the code are:

patches-own [countdown]

to setup
  ...
  ask patches [
    set countdown random grass-regrowth-time
    set pcolor one-of [green brown]
  ]
  ..
end

to go
  ...
  ask sheep [ eat-grass ]
  ask patches [ grow-grass ]
  ...
end

to eat-grass  ;; sheep procedure
  if pcolor = green [
    set pcolor brown
  ]
end

to grow-grass  ;; patch procedure
  ;; countdown on brown patches: if reach 0, grow some grass
  if pcolor = brown [
    ifelse countdown <= 0
      [ set pcolor green
        set countdown grass-regrowth-time ]
      [ set countdown countdown - 1 ]
  ]
end

Note that grass-regrowth-time is a slider.

Upvotes: 2

Related Questions