NetLogo 中的补丁大纲

Nog*_*oga 2 netlogo

有没有办法为补丁创建轮廓?我想要一个带有白色背景和黑色线条的简单网格。

我设法根据我找到的代码创建一个网格,但海龟在线上行走而不是在方块内行走。

Jas*_*per 5

有一种有点愚蠢但有效的方法来使用特定的海龟形状和图元来获取补丁stamp轮廓

选项1

自定义形状是一个方形轮廓,填充海龟区域的整个大小,其 asize为 1(默认值)时与补丁区域相同。"square-outline"我在示例模型中调用了该形状。这是相关代码:

to test
  clear-all
  ask patches [ sprout 1 [
    set shape "square-outline"
    if outline-color != black [
      set color outline-color 
    ]
    stamp
    die
  ]]
end
Run Code Online (Sandbox Code Playgroud)

我使用stamp并拥有海龟die,因此您不必在其余代码中担心它们。如果这对你的模型有意义的话,你可以让它们活着。

如果您想尝试一下,这里是可以在 NetLogo Web 上使用并获取形状的示例模型。您可以导出该 nlogo 文件并使用海龟形状编辑器中的“从模型导入...”功能将形状导入到模型中。

选项2

编辑:我更新了模型,提供了隐藏/显示轮廓每个边缘的选项。"patch-edge"我通过添加一个仅占据海龟形状的一个边缘的旋转形状来做到这一点。heading然后,我可以在标记之前将海龟的边缘设置为 0(顶部)、90(右)、180(底部)或 270(左)之一来设置每个边缘。

to test
  clear-all
  ask patches [ sprout 1 [
    if outline-color != black [
      set color outline-color
    ]
    ifelse top-edges? and right-edges? and bottom-edges? and left-edges? [
      stamp-square-outline
    ] [
      if top-edges?    [ stamp-edge 0   ]
      if right-edges?  [ stamp-edge 90  ]
      if bottom-edges? [ stamp-edge 180 ]
      if left-edges?   [ stamp-edge 270 ]
    ]
    die
  ]]
end

to stamp-square-outline
  set shape "square-outline"
  stamp
end

to stamp-edge [h]
  set shape "patch-edge"
  set heading h
  stamp
end
Run Code Online (Sandbox Code Playgroud)

选项 2 扩展示例

我想制作一个更广泛的轮廓补丁形状的示例,因此我通过make-shapes创建灰色补丁斑点的过程扩展了示例模型,然后使用neighbors4图元和towards图元在不同补丁之间绘制边界。示例模型代码已更新,相关部分如下:

breed [decors decor]

to make-shapes
  clear-all
  
  ; setup the decorator to use to draw edges
  create-decors 1
  let decorator one-of decors

  ; create some grey blobs of shapes we want to outline
  let start-count 0.1 * count patches
  ask n-of start-count patches [ set pcolor grey ]
  ask patches with [pcolor = black] [
    let odds (0.1 + count neighbors4 with [pcolor = grey]) / 5
    if (random-float 1) < odds [ set pcolor grey ]
  ]
  
  ; detect the edges between grey and black patches and outline them
  ask patches with [pcolor = grey] [
    ask decorator [ 
      move-to myself 
      ifelse outline-color != black [
        set color outline-color
      ] [
        set color one-of base-colors 
      ]
    ]
    ask neighbors4 with [pcolor = black] [
      ; `towards` gets a heading from the black patch back, so some
      ; simple math reverses it for stamping the edge.
      let h ((towards myself) + 180) mod 360
      ask decorator [ stamp-edge h ]
    ]
  ]
  ; darker grey just looks a little nicer
  ask patches with [pcolor = grey] [ set pcolor grey - 3 ]
  
  ; keep the decorator from interfering with the rest of the model
  ask decorator [ die ]
end
Run Code Online (Sandbox Code Playgroud)