本文介绍了Netlogo定期发芽的海龟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以指定的步长将海龟放在每个黑色补丁上(如下图所示):
I want to place turtles on each of the black patches(below Figure) at a specified step size:
因此,如果步长较小,那么将创建/发芽的海龟更少,而步长较大的情况下,将导致更少的海龟.
Therefore if step size less more turtles will be created/sprouted and more step size will result in less turtles.
我现在使用的代码:
ask patches with [pcolor = black][sprout-dead-turtles wall-agents [set color red]]
这将产生以下结果:
This gives the following result:
先前的问题在同一行上提出: Netlogo发芽海龟的间距小于一个补丁
Previous question asked on same lines:Netlogo Sprouting turtles spaced at less than one patch
推荐答案
此处:
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的倍数 - 世界包装需要关闭
d
has to be a multiple of 0.1- world wrapping needs to be turned off
这篇关于Netlogo定期发芽的海龟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!