NetLogo:在一堆补丁周围创建半月形?
NetLogo: create half-moon around clump of patches?
我想在我的斑点周围创建 "a half-moon"(黄色),由半径内函数(蓝色)创建。
我想我可以简单地用 in-radius value
表示蓝色,in-radius (value + 1)
表示黄色。然后把中间有 pycor < pycor
个色块的所有黄色色块变成黑色。
请问,如何将此条件写入我的代码?还是有更简单的解决方案?谢谢!
我的代码:
to setup
clear-all
setup-patches
end
to setup-patches
ask patch 0 0 [
set pcolor red
ask patches in-radius 2 [
set pcolor yellow
]
ask patches in-radius 1 [ ; put the blue after yellow to be on the top
set pcolor blue
]
]
ask patches with [pcolor = yellow] [
let ycor_center [pycor] of patch 0 0 ; how to write this condition?
if [pycor] of patch-here > ycor_center [
set pcolor green
]
]
end
看看 NetLogo 编程指南。坐标在开头解释(在代理部分)。当你提到补丁5 3时,你指的是pxcor = 5和pycor = 3的补丁。即补丁0 0已经在中心。
我已经修改了你的代码以使用这个事实并将着色限制为 pycor >= 0(即等于或高于中心)的那些补丁。
to setup
clear-all
setup-patches
end
to setup-patches
ask patch 0 0 [
set pcolor red
ask patches with [pycor >= 0] in-radius 2 [
set pcolor yellow
]
ask patches with [pycor >= 0] in-radius 1 [ ; put the blue on top
set pcolor blue
]
]
end
扩展版修改:
to setup-patches
ask n-of 5 patches [
ask patches with [pycor >= [pycor] of myself] in-radius 2 [
set pcolor yellow
]
ask patches in-radius 1 [
set pcolor blue
]
]
end
补丁的 运行 代码不仅位于 0 0 坐标
to setup
clear-all
setup-patches
end
to setup-patches
ask n-of 5 patches [
set pcolor red
]
ask patches with [pcolor = red] [
let pycor_red pycor ; create variable refering the position of one patch with pcolor = red
ask patches with [pycor >= pycor_red] in-radius 2 [
set pcolor yellow
]
ask patches in-radius 1 [
set pcolor blue
]
]
end
导致:
我想在我的斑点周围创建 "a half-moon"(黄色),由半径内函数(蓝色)创建。
我想我可以简单地用 in-radius value
表示蓝色,in-radius (value + 1)
表示黄色。然后把中间有 pycor < pycor
个色块的所有黄色色块变成黑色。
请问,如何将此条件写入我的代码?还是有更简单的解决方案?谢谢!
我的代码:
to setup
clear-all
setup-patches
end
to setup-patches
ask patch 0 0 [
set pcolor red
ask patches in-radius 2 [
set pcolor yellow
]
ask patches in-radius 1 [ ; put the blue after yellow to be on the top
set pcolor blue
]
]
ask patches with [pcolor = yellow] [
let ycor_center [pycor] of patch 0 0 ; how to write this condition?
if [pycor] of patch-here > ycor_center [
set pcolor green
]
]
end
看看 NetLogo 编程指南。坐标在开头解释(在代理部分)。当你提到补丁5 3时,你指的是pxcor = 5和pycor = 3的补丁。即补丁0 0已经在中心。
我已经修改了你的代码以使用这个事实并将着色限制为 pycor >= 0(即等于或高于中心)的那些补丁。
to setup
clear-all
setup-patches
end
to setup-patches
ask patch 0 0 [
set pcolor red
ask patches with [pycor >= 0] in-radius 2 [
set pcolor yellow
]
ask patches with [pycor >= 0] in-radius 1 [ ; put the blue on top
set pcolor blue
]
]
end
扩展版修改:
to setup-patches
ask n-of 5 patches [
ask patches with [pycor >= [pycor] of myself] in-radius 2 [
set pcolor yellow
]
ask patches in-radius 1 [
set pcolor blue
]
]
end
补丁的 运行 代码不仅位于 0 0 坐标
to setup
clear-all
setup-patches
end
to setup-patches
ask n-of 5 patches [
set pcolor red
]
ask patches with [pcolor = red] [
let pycor_red pycor ; create variable refering the position of one patch with pcolor = red
ask patches with [pycor >= pycor_red] in-radius 2 [
set pcolor yellow
]
ask patches in-radius 1 [
set pcolor blue
]
]
end
导致: