我有乌龟在视线中移动,我希望能够跟随他们走到哪里,让他们在他们身后留下痕迹,好像他们在他们去的时候冒出烟雾。当然,我可以使用乌龟笔(pen-down
),但由于有很多海龟,视野很快就会充满旧路。解决方案可能是在消散之前仅持续几个滴答的路径。但我不知道如何实现这一目标。
更具体:
1)是否有一种技术可以在a之后绘制线条 pen-down
命令逐渐消失了一段时间?
2)如果没有,有没有办法在绘制之后删除使用笔绘制的几个刻度线?
3)如果没有,是否还有其他一些具有类似视觉效果的技术?
我有乌龟在视线中移动,我希望能够跟随他们走到哪里,让他们在他们身后留下痕迹,好像他们在他们去的时候冒出烟雾。当然,我可以使用乌龟笔(pen-down
),但由于有很多海龟,视野很快就会充满旧路。解决方案可能是在消散之前仅持续几个滴答的路径。但我不知道如何实现这一目标。
更具体:
1)是否有一种技术可以在a之后绘制线条 pen-down
命令逐渐消失了一段时间?
2)如果没有,有没有办法在绘制之后删除使用笔绘制的几个刻度线?
3)如果没有,是否还有其他一些具有类似视觉效果的技术?
随着时间的推移,无法淡化绘图层中的轨迹。如果你想要褪色的小径,你需要使用海龟代表小径。
这里有一些示例代码,其中有“头部”乌龟,它们背后有十只乌龟“尾巴”:
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模型库的地球科学部分中,模型的示例是Fire模型。)
随着时间的推移,无法淡化绘图层中的轨迹。如果你想要褪色的小径,你需要使用海龟代表小径。
这里有一些示例代码,其中有“头部”乌龟,它们背后有十只乌龟“尾巴”:
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模型库的地球科学部分中,模型的示例是Fire模型。)
这是一个基于与@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
这是另一种方法,但没有使用额外的海龟。我为了各种各样的缘故而加入它 - 我建议先使用Seth的方法。
在这种方法中,每只乌龟都保留一个固定长度的先前位置和标题列表,并标出最后一个位置。使用这种方法有一些不需要的工件,并不像使用额外的海龟那样灵活,但我认为它使用的内存较少,可能对较大的模型有帮助。
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
]
end