问题 NetLogo乌龟留下随着时间流逝而消失的踪迹


我有乌龟在视线中移动,我希望能够跟随他们走到哪里,让他们在他们身后留下痕迹,好像他们在他们去的时候冒出烟雾。当然,我可以使用乌龟笔(pen-down),但由于有很多海龟,视野很快就会充满旧路。解决方案可能是在消散之前仅持续几个滴答的路径。但我不知道如何实现这一目标。

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


4700
2018-01-12 11:40


起源



答案:


随着时间的推移,无法淡化绘图层中的轨迹。如果你想要褪色的小径,你需要使用海龟代表小径。

这里有一些示例代码,其中有“头部”乌龟,它们背后有十只乌龟“尾巴”:

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模型。)


7
2018-01-12 22:42



我想你也可以在里面问这个问题:问补丁 - 这里[Sprout-tails 1] - Marzy
对于颜色,如果你将龟的初始颜色设置为白色,在每个动作中你可以设置颜色 - 1表示褪色效果 - Marzy
问补丁 sprout 尾巴会失去标题和精确的xcor和ycor hatch 保留。 - Seth Tisue
谢谢,我不知道:) - Marzy


答案:


随着时间的推移,无法淡化绘图层中的轨迹。如果你想要褪色的小径,你需要使用海龟代表小径。

这里有一些示例代码,其中有“头部”乌龟,它们背后有十只乌龟“尾巴”:

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模型。)


7
2018-01-12 22:42



我想你也可以在里面问这个问题:问补丁 - 这里[Sprout-tails 1] - Marzy
对于颜色,如果你将龟的初始颜色设置为白色,在每个动作中你可以设置颜色 - 1表示褪色效果 - Marzy
问补丁 sprout 尾巴会失去标题和精确的xcor和ycor hatch 保留。 - Seth Tisue
谢谢,我不知道:) - Marzy


这是一个基于与@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

4
2018-01-12 23:21





这是另一种方法,但没有使用额外的海龟。我为了各种各样的缘故而加入它 - 我建议先使用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

2
2018-01-13 04:06