Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetLogo turtles leaving a trail that fades with time

Tags:

netlogo

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?

like image 501
Nigel Avatar asked Jan 12 '14 11:01

Nigel


People also ask

What are turtles NetLogo?

Turtles are mobile agents in NetLogo that can be placed anywhere in the world, can look like anything (e.g., shape, color, size), and can move around. They are the primary type of agents in NetLogo models. The turtle primitive reports a specific turtle with the given number.

What does breed do in NetLogo?

breed is a special primitive that can only be placed in the top of a netlogo code tab. Using breed , you can define custom kinds or breeds of turtles.

How do you change the turtle size in NetLogo?

To modify the shape, click on its top-left corner and drag that corner to the top-left corner of the graphical editor window. Then do the same with the bottom-right corner.


1 Answers

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.)

like image 141
Seth Tisue Avatar answered Oct 16 '22 23:10

Seth Tisue