我想在景观中添加森林补丁。更准确地说,想法是添加补丁集群,例如“Patch Clusters”示例。与此示例相反,我想随机分配一些具有相同颜色的补丁集群,而不是几个完全填充景观的集群。这是代码的开头:
to create-forests
repeat 30 [
ask one-of patches [
set pcolor green
ask neighbors [ set pcolor green] ] ]
end
使用此代码,群集看起来像正方形而不是像“Patch Clusters”示例那样的群集。如何在我的环境中添加林修补程序群?
感谢您的帮助 祝你有美好的一天 海洋
答案 0 :(得分:3)
如下:
to create-forests
ask n-of 10 patches [ set pcolor green ]
repeat 6 [
ask patches with [pcolor = green] [
ask one-of neighbors4 [ set pcolor green ]
]
]
end
结果如下:
答案 1 :(得分:2)
快速解决方案可能是使用补丁定位和距离功能。
to create-forests
ask patches[set pcolor black]
repeat 5
[
ask one-of patches
[
set pcolor green
repeat 20
[
let a random 360
let b random 2
ask patch-at-heading-and-distance a b
[
ask neighbors4 [ set pcolor green]
set pcolor green
]
]
]
]
end
使用此功能,您可以移动到另一个补丁邻居。使用a(角度),b(距离)的随机值范围和重复这部分代码的次数,可以实现不同的森林密度。
对于邻居4,我们尝试在森林中填充可能的黑色斑块(注意这个技巧的成功将取决于森林的大小)
更复杂的选择可能是:
to create-forests2
ask patches[set pcolor black]
repeat 5
[
ask one-of patches
[
let size_f (random 2) + 1
let border 2
let big_area [list pxcor pycor] of patches with [abs pxcor <= size_f + border and abs pycor <= size_f + border]
let forested [list pxcor pycor] of patches with [abs pxcor <= size_f + random border and abs pycor <= size_f + random border]
ask patches at-points forested[set pcolor green]
ask patches at-points big_area with[pcolor != green]
[ if count(neighbors with [pcolor = green]) > 6 [ set pcolor green ] ]
]
]
end
在列表的帮助下识别6/8森林中包围的补丁,从而转换为森林