如何用矩形中的另一种颜色替换颜色?

时间:2014-08-18 17:20:32

标签: netlogo

在与How to replace color with another color in a polygon相同的光学元件中,我想用蓝色斑块替换蓝色矩形中包含的白色斑块:

我有蓝色矩形,如下图所示:

enter image description here

我想要有如下蓝色矩形:

enter image description here

How to replace color with another color in a polygon中使用color-white-patches-v2 [ c ],我得到了这个数字:

enter image description here

并使用我修改的color-white-patches-v3 [ c ]如下(因为我收到此错误消息OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead.

to color-white-patches-v3  [c]
ask patches with [ pcolor = white] [
if (patch-at 0 1 != nobody and [pcolor] of patch-at 0 1 = c) or (patch-at 1 0 != nobody and [pcolor] of patch-at 1 0 = c) [
set pcolor c ] ]
end

我获得:

enter image description here

我不知道如何获得图2并且有一个适用于不同多边形形状的代码。 非常感谢你的帮助。

1 个答案:

答案 0 :(得分:6)

这个怎么样?

to color-white-patches
  ask patches with [ pcolor = white and count neighbors4 with [ pcolor = blue ] > 1 ] [
    set pcolor blue
  ]
end

检查至少两侧的补丁是否为蓝色。这应该适用于所有显示的情况。