NetLogo中的补丁轮廓

huangapple go评论43阅读模式
英文:

outline for patches in NetLogo

问题

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

我设法从找到的代码中创建了一个网格,但乌龟走在线条上而不是在方块内。

英文:

Is there a way to create outlines for patches? I want a simple grid with white background and black lines.

I managed to create a grid from a code I found but the turtles walked on the lines instead of inside the squares.

答案1

得分: 4

以下是您提供的内容的中文翻译:

有一种有点傻但有效的方法可以使用特定的乌龟形状和 stamp 原语 来获取补丁轮廓。

选项1

自定义形状是一个填满乌龟区域的正方形轮廓,在 size 为 1(默认值)时与补丁区域相同。我在我的示例模型中将该形状命名为 "square-outline"。以下是相关代码:

我使用 stamp 并让乌龟 die,这样您就不必在代码的其余部分担心它们。如果这对您的模型有意义,您也可以让它们保持活动状态。

如果您想尝试它,可以在 NetLogo Web 上玩这个示例模型 并从中获取形状。您可以导出该 nlogo 文件,并在 乌龟形状编辑器从模型导入... 功能中将形状导入到您的模型中。

选项2

编辑:我更新了模型,以添加隐藏/显示轮廓的每个边缘的选项。我通过添加一个旋转的 "patch-edge" 形状来实现这一点,该形状仅占据乌龟形状的一条边缘。然后,我可以通过设置乌龟的 heading 为 0(顶部)、90(右侧)、180(底部)或270(左侧)来设置每个边缘,然后进行印章。

选项2 扩展示例

我想制作一个更全面的示例来勾画补丁形状的轮廓,所以我扩展了示例模型,添加了一个 make-shapes 过程来创建灰色补丁的块,然后使用 neighbors4 原语和 towards 原语来绘制不同补丁之间的边界。示例模型代码已更新,以下是相关部分:

英文:

There is a somewhat silly but effective way to get patch outlines using a specific turtle shape and the stamp primitive.

Option 1

The custom shape is a square outline that fills the full size of the turtle's area, which at a size of 1 (the default) is the same as a patch area. I called the shape "square-outline" in my sample model. Here is the relevant code:

I use stamp and have the turtles die so you don't have to worry about them in the rest of your code. You could leave them alive if that made sense for your model.

And here is the sample model to play with on NetLogo Web and get the shape from if you want to try it out. You can export that nlogo file and use the Import from Model... feature in the turtle shapes editor to get the shape into your model.

Option 2

Edit: I updated the model with an option to hide/show each edge of the outline. I did this by adding a rotating "patch-edge" shape that only occupied one edge of the turtle shape. I then can set each edge by setting the turtle's heading to one of 0 (top), 90 (right), 180 (bottom), or 270 (left) before stamping it.

Option 2 Expanded Example

I wanted to make a more extensive example of outlining patch shapes so I extended the sample model with a make-shapes procedure to create a blob of grey patches, then to use the neighbors4 primitive and towards primitive to draw borders between different patches. The sample model code is updated, and here is the relevant portion:

huangapple
  • 本文由 发表于 2023年6月13日 14:57:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76462356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定