netlogo

NetLogo turtles leaving a trail that fades with time


I have turtles moving across the view, and I'd like to be able to follow where they go by making them leave a trail behind them, as though they were emitting smoke as they went. Of course, I could use the turtle pen (pen-down), but since there are many turtles, the view rapidly gets filled with old trails. The solution could be trails that last only for a few ticks before they dissipate. But I don't know how to achieve that.

To be more specific: 1) Is there a technique for making the line drawn following a pen-down command gradually fade away over the period of some ticks? 2) If not, is there a way of removing the line drawn using the pen a few ticks after it was drawn? 3) If not, is there some other technique that would have a similar visual effect?


Solution

  • There is no way to fade the trails in the drawing layer over time. If you want trails that fade, you'll need to represent the trails using turtles instead.

    Here's sample code for having "head" turtles that trail ten-turtle "tails" behind them:

    breed [heads head]
    breed [tails tail]
    tails-own [age]
    
    to setup
      clear-all
      set-default-shape tails "line"
      create-heads 5
      reset-ticks
    end
    
    to go
      ask tails [
        set age age + 1
        if age = 10 [ die ]
      ]
      ask heads [
        hatch-tails 1
        fd 1
        rt random 10
        lt random 10
      ]
      tick
    end
    

    I'm just killing off the old trails outright, but you could also add code that fades their color over time. (An example of a model that does that is the Fire model, in the Earth Science section of the NetLogo Models Library.)