NetLogo:设置距中心特定距离的随机补丁的 pcolor
NetLogo: set pcolor of random patches in specific distance from center
我是 NetLogo 的新手,我想 创建斑块状的世界表面,其中斑块(黄色)与中心斑块 (红色虚线圆圈)的距离不同。
更具体地说,我想 select 3 个距离为 10、20、30 个来自中央补丁的随机补丁,并将它们变成黄色。我确信这样做非常简单,但我无法弄清楚距离测量的正确使用。
非常感谢任何建议!
to setup
clear-all
setup-patches
end
to setup-patches
clear-all
ask patches [ set pcolor green ]
ask patch 0 0
[
set pcolor yellow
ask patches in-radius 10 [set pcolor yellow] ; how to include distance here??
]
ask n-of 5 patches [ set pcolor yellow] ; or here ??
end
这比看起来更棘手!你会认为你可以只使用 distance
:
foreach [ 10 20 30 40 ] [
ask n-of 3 patches with [ distance patch 0 0 = ? ] [
set pcolor yellow
]
]
但是如果我们放下 n-of 3
让每个距离的所有补丁都变成黄色,结果如下:
问题是它在指定的精确距离处寻找补丁。
能不能稍微宽容一点呢?
foreach [ 10 20 30 40 ] [
ask patches with [
distance patch 0 0 > ? - 0.5 and
distance patch 0 0 < ? + 0.5
] [
set pcolor yellow
]
]
这样更好,但仍然相当不对。圆圈的某些部分比其他部分更粗:
但也许它足以满足您的目的,或者您可以稍微调整容差。
最后,这里有一个古怪的方法来实现类似的结果:
to-report circle-at [ d ]
let dummies []
let circle []
create-turtles 2 [
set dummies lput self dummies
]
ask last dummies [
setxy 0 d
create-link-with first dummies [ tie ]
]
repeat 3600 [
ask first dummies [
right 0.1
ask last dummies [
set circle lput patch-here circle
]
]
]
ask turtle-set dummies [ die ]
report patch-set circle
end
它使用 tie
命令让一只乌龟绕着另一只乌龟转,并将它遍历的补丁添加到我们的结果集中。它很慢,但它有效,你会得到一个漂亮的平滑圆圈:
使用此过程,您的最终代码将是:
foreach [ 10 20 30 40 ] [
ask n-of 3 circle-at ? [
set pcolor yellow
]
]
还有另一种选择:
to setup
clear-all
ask patches [ set pcolor green ]
foreach [10 20 30] [
repeat 3 [
make-yellow-patch ?
]
]
end
to make-yellow-patch [dist]
create-turtles 1 [
rt random-float 360
fd dist
while [pcolor = yellow] [
bk dist
rt random-float 360
fd dist
]
set pcolor yellow
die
]
end
示例结果:
observer> show sort [round distancexy 0 0] of patches with [pcolor = yellow ]
observer: [10 10 10 19 20 20 30 30 30]
我认为 19 不是错误。正如 Nicolas 所示,您不想偏向圆圈的任何特定部分,因此这意味着您必须允许距离发生一些变化。
我是 NetLogo 的新手,我想 创建斑块状的世界表面,其中斑块(黄色)与中心斑块 (红色虚线圆圈)的距离不同。
更具体地说,我想 select 3 个距离为 10、20、30 个来自中央补丁的随机补丁,并将它们变成黄色。我确信这样做非常简单,但我无法弄清楚距离测量的正确使用。
非常感谢任何建议!
to setup
clear-all
setup-patches
end
to setup-patches
clear-all
ask patches [ set pcolor green ]
ask patch 0 0
[
set pcolor yellow
ask patches in-radius 10 [set pcolor yellow] ; how to include distance here??
]
ask n-of 5 patches [ set pcolor yellow] ; or here ??
end
这比看起来更棘手!你会认为你可以只使用 distance
:
foreach [ 10 20 30 40 ] [
ask n-of 3 patches with [ distance patch 0 0 = ? ] [
set pcolor yellow
]
]
但是如果我们放下 n-of 3
让每个距离的所有补丁都变成黄色,结果如下:
问题是它在指定的精确距离处寻找补丁。
能不能稍微宽容一点呢?
foreach [ 10 20 30 40 ] [
ask patches with [
distance patch 0 0 > ? - 0.5 and
distance patch 0 0 < ? + 0.5
] [
set pcolor yellow
]
]
这样更好,但仍然相当不对。圆圈的某些部分比其他部分更粗:
但也许它足以满足您的目的,或者您可以稍微调整容差。
最后,这里有一个古怪的方法来实现类似的结果:
to-report circle-at [ d ]
let dummies []
let circle []
create-turtles 2 [
set dummies lput self dummies
]
ask last dummies [
setxy 0 d
create-link-with first dummies [ tie ]
]
repeat 3600 [
ask first dummies [
right 0.1
ask last dummies [
set circle lput patch-here circle
]
]
]
ask turtle-set dummies [ die ]
report patch-set circle
end
它使用 tie
命令让一只乌龟绕着另一只乌龟转,并将它遍历的补丁添加到我们的结果集中。它很慢,但它有效,你会得到一个漂亮的平滑圆圈:
使用此过程,您的最终代码将是:
foreach [ 10 20 30 40 ] [
ask n-of 3 circle-at ? [
set pcolor yellow
]
]
还有另一种选择:
to setup
clear-all
ask patches [ set pcolor green ]
foreach [10 20 30] [
repeat 3 [
make-yellow-patch ?
]
]
end
to make-yellow-patch [dist]
create-turtles 1 [
rt random-float 360
fd dist
while [pcolor = yellow] [
bk dist
rt random-float 360
fd dist
]
set pcolor yellow
die
]
end
示例结果:
observer> show sort [round distancexy 0 0] of patches with [pcolor = yellow ]
observer: [10 10 10 19 20 20 30 30 30]
我认为 19 不是错误。正如 Nicolas 所示,您不想偏向圆圈的任何特定部分,因此这意味着您必须允许距离发生一些变化。