我想制作对角线底座(Perfet square),但它只能工作到2号以上然后我才开始失去正方形。
我的代码是:
to setup-patches
set-patch-size 15
ask patches[
if (distancexy 20 20) < base-size [set pcolor yellow]
if (distancexy -20 -20) < base-size [set pcolor yellow]
if (distancexy -20 20) < base-size [set pcolor pink]
if (distancexy 20 -20) < base-size [set pcolor pink]
]
end
请查看图片,了解我在说什么。
答案 0 :(得分:2)
查看模型库中的两个示例:Moore和Von Neumann以及邻域示例。你想要盒子(摩尔)社区,你应该使用at-points
来获得它。但是,靠近您的编码设置,您也可以尝试:
to-report linf [#p1 #p2]
let _xdist abs ([pxcor] of #p1 - [pxcor] of #p2)
let _ydist abs ([pycor] of #p1 - [pycor] of #p2)
report max (list _xdist _ydist)
end
to setup-patches [base-size]
clear-all
set-patch-size 15
let diag1 (patch-set patch 20 20 patch -20 -20)
ask diag1 [ask patches with [linf self myself < base-size] [set pcolor yellow]]
let diag2 (patch-set patch -20 20 patch 20 -20)
ask diag2 [ask patches with [linf self myself < base-size] [set pcolor pink]]
end