现在我正在使用
ask patch 1 1 [set pcolor grey]
ask patch 1 -1 [set pcolor grey]
ask patch -1 1 [set pcolor grey]
ask patch -1 -1 [set pcolor grey]
有没有办法在NetLogo中用一行代码为多个补丁设置补丁颜色?
答案 0 :(得分:3)
最简单的方法:
ask (patch-set patch 1 1 patch 1 -1 patch -1 1 patch -1 -1) [ set pcolor grey ]
(以下内容已根据Seth的评论进行了更新:)
如果从观察者那里运行(也就是说,它不是由任何代理运行),你可以使用at-points
,如下所示:
ask patches at-points [[1 1] [1 -1] [-1 1] [-1 -1]] [ set pcolor grey ]
但是,如果此代码由乌龟或补丁运行,则坐标列表将被视为相对于该代理。所以patches at-points [[1 0] [0 1]]
会将补丁提供给当前代理的右侧和补丁。您可以轻松制作使用绝对坐标的版本:
to-report patches-at-coords [ coordinates ]
report (patch-set map [patch first ? last ?] coordinates)
end
然后像这样使用它:
ask patches-at-coords [[1 1] [1 -1] [-1 1] [-1 -1]] [ set pcolor grey ]
无论如何,除非你这么做,否则我会采用第一种方法。