NetLogo乌龟留下的痕迹会随着时间的流逝而消失 [英] NetLogo turtles leaving a trail that fades with time

查看:171
本文介绍了NetLogo乌龟留下的痕迹会随着时间的流逝而消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让乌龟在视线中移动,我希望能够跟随它们走到哪里,方法是让它们在自己身后留下一条小路,好像它们在走时正在冒烟.当然,我可以使用乌龟笔(pen-down),但是由于乌龟很多,因此视图很快就充满了旧痕迹.解决的方法可能是在耗散之前仅持续几刻的足迹.但是我不知道该怎么实现.

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.

更具体地说: 1)是否有一种技术可以使在pen-down命令之后绘制的线条在某些刻度线期间逐渐消失? 2)如果不是,是否有办法在笔画了几格后就删除使用笔画的线? 3)如果没有,是否还有其他类似的视觉效果技术?

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?

推荐答案

无法随时间淡化绘图层中的轨迹.如果您想让步道褪色,则需要使用乌龟来表示步道.

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

我只是彻底淘汰掉旧的痕迹,但是您也可以添加代码,使其随着时间的推移逐渐褪色. (在NetLogo模型库的地球科学"部分中,一个执行该模型的示例就是火"模型.)

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

这篇关于NetLogo乌龟留下的痕迹会随着时间的流逝而消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆