How to export the world of NetLogo 6.2 coloring only the patches that were born turtles?

Viewed 23

I don't really know how to export the following output...

I have 16 turtles profiles, which refers to the non-repeating combination of habitatcover types (see ValidHabs variable)

In the model, it starts with 10 turtles that can reproduce or die.

I would like to generate an output in which the whole world turns white and paints magenta only where turtles were born, that is, the 10 turtles that started the world and then the new turtles that emerged through the reproduction process. And that this came out by turtle profile. I have looked up the NetLogo dictionary and I believe I should use the export-view command

But, I still couldn't execute in a simple code that can only export in image form the patches that only existed turtle (painted in magenta) at the end of all ticks (that is, all patches that had turtles taking into account all ticks ) for that turtle profile.

What I've managed to do so far is below.

Any kind of help will be very welcome :)

Thanks in advance!

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
1 Answers

I think the best way to track this is a patches-own variable to track if a turtle was ever born on the patch. In this example code I've called that turtle-born-here, set the variable to false in the setup, then update the variable any time a turtle is 'born' (either on setup, or during 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

Running this spits out an image like:

enter image description here

Related