更改一定距离内的色块颜色 Netlogo

发布于 2025-01-09 06:12:13 字数 211 浏览 0 评论 0 原文

我想改变一些补丁的颜色。

if mujeres [ ask n-of 20 patches with [pcolor = 35] [set pcolor 9]]

然而,有时两个相邻的色块会变成颜色 9,我不希望这样。我认为半径内不是最佳的,因为在此之前没有颜色为 9 的色块。

确保斑块变成白色但它们保持分开的最佳方法是什么?谢谢

I want to change the color of some patches.

if mujeres [ ask n-of 20 patches with [pcolor = 35] [set pcolor 9]]

However, sometimes two patches adjacent patches change to color 9, i dont want this. I dont think that in-radius is optimal as there are no patches with color 9 before this.

What would be the best way to guarantee that the patches turn to white but they stay apart. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有你我更好 2025-01-16 06:12:13

如果我理解正确的话,您想要将一些色块变成灰色,但在配置中不存在相邻的灰色色块。如果是这种情况,一种方法是使用 while 循环来搜索可能改变颜色的色块,直到达到所需的灰色色块数量 - 这将确保没有相邻的灰色色块因为每次运行 while 循环时,只有“允许”更改颜色的补丁才会这样做。例如:

to setup
  resize-world 0 10 0 10
  set-patch-size 30
  ca
  ; Until the condition is met, ask one patch to turn grey
  while [ count ( patches with [ pcolor = 9 ] ) < 20 ] [
    ; Ask one of the patches that does NOT have any grey neighbors
    ask one-of patches with [ not any? neighbors with [ pcolor = 9 ] ] [
      set pcolor 9
    ] 
  ]
  reset-ticks
end

应该类似于:

在此处输入图像描述

请注意 while 循环 - 如果从未满足“中断”或完成循环的条件,则循环将无限期地运行。

If I'm understanding correctly, you want to turn some patches grey, but in a configuration such that there are no adjacent grey patches. If that's the case, one way to do this is to use a while loop to search for potential patches to change color until your number of desired grey patches is reached- this will ensure that there are no adjacent grey patches since each time the while loop runs, only a patch that is 'allowed' to changed color will do so. For example:

to setup
  resize-world 0 10 0 10
  set-patch-size 30
  ca
  ; Until the condition is met, ask one patch to turn grey
  while [ count ( patches with [ pcolor = 9 ] ) < 20 ] [
    ; Ask one of the patches that does NOT have any grey neighbors
    ask one-of patches with [ not any? neighbors with [ pcolor = 9 ] ] [
      set pcolor 9
    ] 
  ]
  reset-ticks
end

Should look something like:

enter image description here

Do be careful with while loops- if the condition is never met to 'break' or complete the loop, the loop will run indefinitely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文