当您有多个海龟配置文件时,如何导出NetLogo 6.2 View? [英] How to export NetLogo 6.2 View when you have multiple turtle profiles?
问题描述
我正在尝试实现一个输出,该输出是从View导出的。我通过此链接获得帮助:How to export the world of NetLogo 6.2 coloring only the patches that were born turtles? 我非常感谢卢克·C的帮助,因为我设法实现了我想要的一部分。
然而,我仍然没有成功地根据海龟的侧面生成图像。我有16个海龟档案(参见ValidHabs)。
例如,我希望为16个海龟配置文件中的每一个导出一个图像。
例如,海龟轮廓1(只能在栖息地覆盖1中出生和孵化),因此:
At tick 0, the world started with: 1 turtle no (patch 15 -4),
At tick 1, there are 2 turtles in patches (patch 15 -4) and (patch 14 -8) and
At tick 2, there are 4 turtles in patches (patch 15 -4), (patch 14 -8), (patch 12 -5) and (patch 17 -1).
因此,对于海龟配置文件1,您将拥有一个白色导出图像,其中的补丁(Patch 15-4)、(Patch 14-8)、(Patch 12-5)和(Patch 17-1)绘制为洋红色。
然后我会导出一个图像到乌龟2的个人资料等。直到我了解到海龟16的概况,它只能在栖息地4和5产卵。
我尝试使用Foreach将图像导出到每个配置文件,但发生的情况是打开一个.png文件并在该文件中生成结果("覆盖")。我想要的是为每个海龟配置文件生成一个.png格式的文件。我想,使用Foreach,我可以仔细地生成文件。但到目前为止,我还没能做到。如果有人能帮我,我将不胜感激:)
提前谢谢
代码:
globals [ ListProfiles ]
patches-own [ turtle-born-here ]
turtles-own [ all-code metabolism reproduction code-metabolism code-reproduction ]
to setup
ca
set ListProfiles [ [1] [2] [3] [4] [5] ]
ask patches [ set turtle-born-here false ]
ask n-of 5 patches [
sprout 1
setup-turtles
set turtle-born-here true
]
reset-ticks
end
to go
ask turtles [
rt random 60 - 30
fd 1
if random-float 1 < 0.05 [
hatch 1
ask patch-here [ set turtle-born-here true]
]
]
end
to setup-turtles
ask turtles [
(
ifelse
metabolism = 2 [set code-metabolism "M1"]
)
(
ifelse
reproduction = 5 [set code-reproduction "R1"]
)
set all-code ( word code-metabolism code-reproduction )
]
end
to example-export-image
setup
; Some example go runs
repeat 50 [ go ]
; This is the export-view component
cd
ask turtles [
ht
]
ask patches [
ifelse turtle-born-here
[ set pcolor magenta ]
[ set pcolor white ]
]
carefully
[ file-delete ( "View.png" ) ]
[ ]
foreach ListProfiles
[
y ->
let k turtles with [ all-code = y ]
ask k [
export-view ( "View.png" )
]
]
end
推荐答案
当您提供代码时,建议您从头开始,而不是试图缩减现有模型(请参阅How to Ask和How to create a Minimal, Reproducible Example)。这将在(至少)两个主要方面有所帮助:
- 它使您的代码更具可读性,从而使您更有可能获得有用的答案,因为如果此站点上的其他用户不必还尝试了解代码的哪些部分与实际问题无关,则他们将更容易理解问题。
- 这使您自己解决问题的可能性更大,或者至少可以帮助您更好地了解问题的来源。
我建议无论何时发布问题,都要认真尝试遵循上面的指导原则。目前,您提供的代码远远超过了问题本身的实际需要,对我来说,这将归结为:&如何更改多个实验/模拟的文件名?&这个问题已经answered beforein different waysthat may suit your needs-如果下面的代码示例没有弄清楚,请仔细查看这些其他问题,并记住How To Ask帮助页的&q;搜索和研究。
作为一个独立的例子,这实际上只是对Charles在上面第一个链接中的回答的提炼:
patches-own [ hab-type turtle-born-here ]
globals [ profiles ]
to setup
ca
resize-world 0 29 0 29
set profiles [ "a" "b" "c" ]
ask patches [
( ifelse pxcor < ( max-pxcor / 3) [
set hab-type "a"
] pxcor < ( max-pxcor * 2 / 3 ) [
set hab-type "b"
] [
; else
set hab-type "c"
]
)
]
end
to fake-simulate
foreach profiles [ profile ->
ask turtles [ die ]
ask patches [
set pcolor black
set turtle-born-here false
]
ask n-of 5 patches with [ hab-type = profile ] [
sprout 1
set turtle-born-here true
]
reset-ticks
repeat 50 [
ask turtles [
rt random 60 - 30
fd 1
if random-float 1 < 0.1 and [ hab-type ] of patch-here = profile [
hatch 1
ask patch-here [ set turtle-born-here true]
]
]
tick
]
export-image profile
]
end
to export-image [ unique-id ]
; Prepare the view for export
ask turtles [ ht ]
ask patches [
ifelse turtle-born-here
[ set pcolor magenta ]
[ set pcolor white ]
]
; Use word to create a file name
let out-file ( word "example_view_export_" unique-id "_.png" )
export-view out-file
end
输出如下:
这篇关于当您有多个海龟配置文件时,如何导出NetLogo 6.2 View?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!