Search code examples
if-statementnetlogopoisson

Netlogo: How can I ask the specific patch changes the color (black) only for a specific ticks with the timing of Poisson distribution?


How can I ask the specific patch changes the color (black) only for a specific ticks with the timing of Poisson distribution? I am a beginner of Netlogo. The following is a sample program. But in this program the patch has been white colored all the time. Thank you.

ask patch max-pxcor 0 [
set poisson poisson - 1
if poisson < 0 [ ;I have no idea of the good condition setting.
  set poisson random-poisson (stop-ticks)
  set pcolor black 
]
  set pcolor white
]

Solution

  • Try this. It creates a counter (conveniently called counter) that decreases each tick and when it hits 1 (you might need 0) turns the patch black then resets the patch to white with a new counter then next tick. The poisson distribution here has a mean of 5, but that can be changed.

    globals [counter]
    
    to setup
      clear-all
      ask patches [set pcolor white]
      set counter random-poisson 5
      reset-ticks
    end
    
    to go
      print counter
      if-else counter = 1
      [ ask patch max-pxcor 0 [set pcolor black]
        set counter random-poisson 5
      ]
      [ ask patch max-pxcor 0 [set pcolor white]
        set counter counter - 1
      ]
      tick
    end