在延长的问题之间发芽乌龟

时间:2014-09-25 11:10:20

标签: netlogo

这个问题是上一个问题的延伸。 Netlogo Sprouting turtles at regular intervals

运行代码并将乌龟大小设置为大约0.4。我面临以下问题:(检查下图) Simulation run

Problem issue

在图2中,您可以注意到没有海龟的黑色间隙。这是不可取的,也是我想要的。所以在某种程度上,萌芽应该从贴片的边缘开始,而不是从中心开始。

感谢。

代码:( Nicolas Payette上的Question回答)

to fill-wall [ d ]
  set d precision d 1 ; make sure d is a multiple of 0.1
  let n precision (d / 0.1) 0 ; interval at which to hatch
  ask one-of possible-next-patches [ 
    sprout 1 [
      hatch 1
      let i 0
      let next-patch my-next-patch
      while [ next-patch != nobody ] [
        face next-patch
        while [ patch-ahead 0.55 != nobody and [ pcolor ] of patch-ahead 0.55 = black ] [
          fd 0.1
          setxy precision xcor 1 precision ycor 1 ; avoid floating point imprecisions
          set i i + 1
          if i mod n = 0 [ hatch 1 ]
        ]
        set next-patch my-next-patch
      ]
      die
    ]
  ]  
end

to-report possible-next-patches
  let empty-black-patches patches with [ pcolor = black and not any? turtles-here ]
  report empty-black-patches with [
    count neighbors4 with [ member? self empty-black-patches ] = 1
  ]
end

to-report my-next-patch
  report one-of possible-next-patches with [ member? self [ neighbors4 ] of myself ]
end

以下是您将如何使用它:

to setup
  ca  
  ; draw the background:
  ask patches with [ abs pxcor != max-pxcor and abs pycor != max-pycor ] [ set pcolor grey ]
  ask patches with [ pycor = max-pycor and abs pxcor <= 1 ] [ set pcolor white ]
  set-default-shape turtles "circle 2"
  fill-wall 0.3
end

约束:

  • d必须是0.1
  • 的倍数
  • 世界包装需要关闭

0 个答案:

没有答案