如何导出NetLogo 6.2的世界,只给那些天生的乌龟上色? [英] How to export the world of NetLogo 6.2 coloring only the patches that were born turtles?

查看:0
本文介绍了如何导出NetLogo 6.2的世界,只给那些天生的乌龟上色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道如何导出以下输出...

我有16个海龟配置文件,它指的是生境覆盖类型的非重复组合(参见ValidHabs变量)

在模型中,它从10只可以繁殖或死亡的乌龟开始。

我想生成一个输出,其中整个世界都变白了,只在海龟出生的地方画洋红色,也就是说,开始世界的10只海龟,然后是通过繁殖过程出现的新海龟。这是通过海龟侧写出来的。我已经查找了NetLogo词典,我认为我应该使用EXPORT-VIEW命令

但是,我仍然不能在一个简单的代码中执行,该代码只能以图像形式导出该海龟配置文件的所有刻度结尾处仅存在海龟(绘制为洋红色)的补丁(即,所有包含海龟的补丁都考虑了所有刻度)。

到目前为止,我成功完成的工作如下所示。

我们非常欢迎任何形式的帮助:)

提前谢谢!

globals [ ValidHabs ValidHabsItem HotPatchSet CurrentHotPatchSet PatchAvailable ListProfiles Death ]

patches-own [ habitatcover resources turtle-count ]

turtles-own [ turtle-profiles-habitat metabolism reproduction all-code code-metabolism code-reproduction energy my-patches x ]

to setup
  clear-all
  random-seed 1
  set ValidHabs [[1] [2] [3] [4] [5] [6] [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] ]
  set Death 0
  set ListProfiles [ ]
  setup-world
  setup-patches
  reset-ticks
  foreach sort turtles
  [
    t ->
    ask t
    [
      print ( word "I am:" " " who )
    ]
  ]
  print ""
end

to setup-world
  let pcolors []
  set pcolors [ 25 65 23 53 105 45 ]
  ask patches [
    set pcolor item (random 6) pcolors
  ]

  ask patches [
    if pcolor = 25 [ set habitatcover 1 ]
    if pcolor = 65 [ set habitatcover 2 ]
    if pcolor = 23 [ set habitatcover 3 ]
    if pcolor = 53 [ set habitatcover 4 ]
    if pcolor = 105 [ set habitatcover 5 ]
    if pcolor = 45 [ set habitatcover 6 ]
  ]
  ask patches [ set resources random 100 ]
end

to setup-patches
  set HotPatchSet patches with  [ ( habitatcover != 6 ) ]
  let list1 ( list 2 )
  let list2 ( list 5 )
  let n0 count turtles
  set CurrentHotPatchSet HotPatchSet with [ habitatcover = one-of item ValidHabsItem ValidHabs ]
  while [ n0 < ( length list1 ) * ( length list2 ) * 10 ]
  [
    (
      foreach list1
      [
        this-metabolism ->
        foreach list2
        [
          this-reproduction ->
          let c count CurrentHotPatchSet
          if c = 0 [ stop ]
          ask one-of CurrentHotPatchSet
          [
            sprout 1
            [
              set turtle-profiles-habitat item ValidHabsItem ValidHabs
              set metabolism this-metabolism
              set reproduction this-reproduction
              setup-turtles who
            ]
            set CurrentHotPatchSet CurrentHotPatchSet with [ not any? turtles in-radius 2 ]
          ]
        ]
      ]
    )
    set n0 count turtles
  ]
end

to setup-turtles [ WhichColony? ]
  set color black
  set energy 0
  ask turtle who [
    (
      ifelse
      metabolism = 2 [set code-metabolism "M1"]
    )
    (
      ifelse
      reproduction = 5 [set code-reproduction "R1"]
    )
    set all-code ( word code-metabolism code-reproduction )
  ]

  set x turtle-profiles-habitat

  ask turtle who
  [
    if length x = 1
      [
        let a 1
        while [ a < 7 ]
        [
          if member? a x
          [
            set my-patches patches with [ habitatcover = a ]
          ]
          set a a + 1
        ]
    ]

     if length x = 2
    [
      let a 1
      while [ a < 7 ]
        [
        let b 1
        while [ b < 7 ]
        [
          if a = item 0 x and b = item 1 x
            [
              set my-patches patches with [ habitatcover = a or habitatcover = b ]
          ]
          set b b + 1
        ]
        set a a + 1
      ]
    ]
  ]
end

to go
  metabolic
   print ( word "TICK: " ticks )
  ask turtles [ print ( word "I am: " who ) ]
  tick
  let n count turtles  
  if n = 0 or ticks = 10 and ExportView? = true [ output ] ;; ExportView? is a switch in the interface
end

to metabolic
  ask turtles
  [
    let z [ resources ] of patch-here
    if
    metabolism = 2 [
      set energy ( ceiling ( z ) - 2 )
      if energy <= 1.7 [ die-turtles ]
      if
      reproduction = 5 [
        if energy >= 5 [ dispersion ]
      ]
    ]
  ]
end

to dispersion
  let p 0
  while [ p < 1 ] [
    let available-patch my-patches with [ distance myself > 3 and distance myself < 5 and count turtles-here = 0 and not any? other turtles in-radius 3 ]
    set PatchAvailable count available-patch
    if PatchAvailable = 0 [ stop ]
    let choose-patch one-of available-patch
    let coordx [ pxcor ] of choose-patch
    let coordy [ pycor ] of choose-patch
    hatch 1 [
      setxy coordx coordy
      set turtle-count count turtles-here
      set color white
      set energy 0
      set p p + 1
    ]
  ]
end

to die-turtles
    foreach ListProfiles [ lp ->
    set Death 0
    set Death Death + 1
  ]
  die
end

to color_patches  
  ask patches [ set pcolor white ]   
  ask turtles [    
    ask patch-here [ set pcolor magenta ]
  ]
end


to output  
  export-view ( word "View.png" )
end

;; in the interface go button, I put the following:
;if ExportView? = true
;[ 
;  color_patches    
;]
;go

推荐答案

我认为最好的跟踪方法是使用patches-own变量来跟踪是否patch上出生。在此示例代码中,我调用了turtle-born-here,在设置中将变量设置为false,然后在任何时候(无论是在安装过程中,还是在go期间)更新该变量。

patches-own [ turtle-born-here ]

to setup
  ca
  ask patches [ set turtle-born-here false ]
  ask n-of 5 patches [ 
    sprout 1 
    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 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 ]
  ]
  export-view "example_view_export.png"   
end

运行此命令将生成如下图像:

这篇关于如何导出NetLogo 6.2的世界,只给那些天生的乌龟上色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆