我让海龟在视野中移动,我希望能够跟随它们的去向,让它们在身后留下一条小径,就像它们在行进时排放烟雾一样。当然,我可以用海龟笔(pen-down),但由于有很多海龟,视野中很快就会充满古老的小径。解决之道可能是在它们消散之前只持续几次的痕迹。但我不知道如何做到这一点。
更具体的是:( 1)是否有一种技术可以使按照pen-down命令绘制的线条在某段时间内逐渐消失? 2)如果没有,是否有一种方法可以在画笔画出几个滴答字后将画出的线移除? 3)如果没有,是否有其他技术会产生类似的视觉效果?
发布于 2014-01-12 22:42:12
随着时间的推移,画层中的痕迹无法褪色。如果你想要褪色的小径,你需要用海龟来代表小径。
下面是示例代码,用于在“头”海龟后面跟踪十只海龟的“尾巴”:
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模型库的地球科学部分,火模型就是一个这样做的模型的例子。)
发布于 2014-01-12 23:21:38
这里有一个基于@SethTisue的相同原理的版本,但是尾部逐渐消失了:
globals [ tail-fade-rate ]
breed [heads head] ; turtles that move at random
breed [tails tail] ; segments of tail that follow the path of the head
to setup
clear-all ;; assume that the patches are black
set-default-shape tails "line"
set tail-fade-rate 0.3 ;; this would be better set by a slider on the interface
create-heads 5
reset-ticks
end
to go
ask tails [
set color color - tail-fade-rate ;; make tail color darker
if color mod 10 < 1 [ die ] ;; die if we are almost at black
]
ask heads [
hatch-tails 1
fd 1
rt random 10
lt random 10
]
tick
end发布于 2014-01-13 04:06:55
这是另一种方法,但不用额外的海龟。我包括它的多样性-我建议先采用塞斯的方法。
在这种方法中,每只海龟都有一个固定长度的前一位置和标题的列表,并在最后的位置上盖章。这种方法存在一些不必要的工件,不像使用额外的海龟那样灵活,但我认为它使用的内存更少,这可能有助于更大的模型。
turtles-own [tail]
to setup
ca
crt 5 [set tail n-values 10 [(list xcor ycor heading)] ]
end
to go
ask turtles [
rt random 90 - 45 fd 1
stamp
; put current position and heading on head of tail
set tail fput (list xcor ycor heading) but-last tail
; move to end of tail and stamp the pcolor there
let temp-color color
setxy (item 0 last tail) (item 1 last tail)
set heading (item 2 last tail)
set color pcolor set size 1.5 stamp
; move back to head of tail and restore color, size and heading
setxy (item 0 first tail) (item 1 first tail)
set heading item 2 first tail
set size 1 set color temp-color
]
endhttps://stackoverflow.com/questions/21074186
复制相似问题