我是netlogo的新手,我需要一些帮助。
我正在尝试生长一种颜色的连续补丁(黑色背景上的绿色)。但是,我有时会有一个完全被绿色斑块包围的黑色斑块。我想将那些黑色斑块的颜色改为绿色。
我试过了:
ask patches [
if neighbors4 with [pcolor = 55]
[set pcolor 55]
]
但是它给了我一个错误,
也是如此ask patches [
if any? neighbors4 [pcolor = 55]
[set pcolor 55]
]
以下代码有时会留下绿色斑块包围的黑色斑块:
to setup
clear-all
set-patch-size 4
resize-world -50 50 -50 50
ask patches[set pcolor black]
grow-cell
reset-ticks
end
to grow-cell
ask patch 0 0 [
set pcolor 55
ask neighbors [
set pcolor 55
]
]
repeat 45
[ ask patches with [pcolor = black]
[ set pcolor [pcolor] of one-of neighbors4 ] ]
end
答案 0 :(得分:0)
这是一个丑陋/勉强聪明的黑客。
Ask patches[
if mean [pcolor] of neighbors4 = green[set pcolor green]
]
或者替代:
Ask patches with [ count neighbors4 with [pcolor = green] = 4 ]
[set pcolor green]