Sprouting turtles in between extended issue

孤者浪人 提交于 2019-12-12 02:55:50

问题


This is question is an extension of the previous question. Netlogo Sprouting turtles at regular intervals

On runnning the code and set the turtle size to about 0.4. I face the following issue:(Check figure below)

In figure 2, you can notice the black gap where there no turtles. This is undesirable and is what I am intending correct. So in a way the sprout should begin at the edge of patch instead the center.

Thanks.

CODE:(Answer by Nicolas Payette on 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

Here is how you would use it:

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

Constraints:

  • d has to be a multiple of 0.1
  • world wrapping needs to be turned off

来源:https://stackoverflow.com/questions/26037113/sprouting-turtles-in-between-extended-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!