更改除一种颜色外的色块

时间:2016-02-09 05:04:08

标签: netlogo

我正在Netlogo中创建一个程序,其中有购物者(海龟)在杂货店布局中移动。当他们踩到补丁时,颜色会增加,当它没有代理时,颜色就会减少,因为这会显示购物者通过商店的路径。

我的代码是:

 ask turtles
 [ rt random 360
    fd 1
    set pcolor pcolor + 1 ]

 ask patches with [ (pcolor > 9.9) or (pcolor < 0.1) ]
  [set pcolor 0]

ask patches with [ (count turtles-here = 0) and (pcolor <= 9.9) and (pcolor > 0) ]
  [ set pcolor pcolor - 0.1 ]

然而,由于过道贴片是蓝色的,这也将它们变回黑色。我想知道我可以使用哪些代码,因此pcolor = 105的补丁会保持蓝色而不会变为黑色?

1 个答案:

答案 0 :(得分:1)

请勿使用pcolor = 105更改色块的颜色。您只需在修改色块颜色的任何位置添加其他条件。

 ask turtles
     [ rt random 360
        fd 1
        if pcolor != 105[set pcolor pcolor + 1 ]
     ]

 ask patches with [ pcolor != 105 and ((pcolor > 9.9) or (pcolor < 0.1))]
  [set pcolor 0]

ask patches with [pcolor != 105 and (count turtles-here = 0) and (pcolor <= 9.9) and (pcolor > 0) ]
  [ set pcolor pcolor - 0.1 ]