Netlogo - Getting Turtles in a certain area and set albedo for patches

48 views
Skip to first unread message

Tobias Koch

unread,
Jan 13, 2020, 3:48:20 AM1/13/20
to netlogo-users
Hello everyone,

I'm working on a model in Netlogo. The model should represent different surfaces in the city and their albedo. When a ray (turtle) hits the patches it should either be absorbed or transformed into heat dots. These dots should then be able to transform back into rays and leave the patches in the certain area, exactly like in the climate change model from the models library: https://ccl.northwestern.edu/netlogo/models/ClimateChange

At the moment I'm trying to get all the dots move in the certain area with the colored patches. Does anyone know how to get the dots (turtles) move in a certain area?

Additionally I'm trying to set the albedo for the different colored patches in my modell. I was just able to set the colors, not the albedo.

Here is my code:
extensions [ gis ]

globals [
  wien-grenzen
  temperature
]

patches-own [
  random-n
  centroid
  ID
  patch-type
]

breed [rays ray]
breed [IRs IR]
breed [heats heat]
breed [CO2s CO2]
breed [trees tree]
breed [industries industry]

to setup
  clear-all
  set-default-shape rays "ray"
  set-default-shape IRs "ray"
  set-default-shape heats "dot"
  set-default-shape CO2s "CO2-molecule"
  set-default-shape trees "tree"
  set-default-shape industries "industry"
  setup-map
  set-surface
  set temperature 0
  reset-ticks
  plot temperature
end

to setup-map
  clear-all
  set wien-grenzen gis:load-dataset "Bezirksgrenzen.shp"
  gis:set-world-envelope (gis:envelope-of wien-grenzen)
  let i 1
  foreach gis:feature-list-of wien-grenzen [ feature ->
    ask patches gis:intersecting feature [
;      set centroid gis:location-of gis:centroid-of feature
;      ask patch item 0 centroid item 1 centroid [
;        set ID i
;      ]
      set ID i
    ]
    set i i + 1
  ]
  gis:set-drawing-color white
  gis:draw wien-grenzen 1.5
end

to set-surface
  ask patches with [ID > 0] [
    set random-n random-float 20
    if random-n < 5
    [
      gis:set-drawing-color gray + 1
      set pcolor gray + 1
    ]
     if random-n > 5 and random-n < 10
    [
      gis:set-drawing-color gray + 2.5
      set pcolor gray + 2.5
    ]
    if random-n > 10 and random-n < 15
     [
      gis:set-drawing-color green + 1
      set pcolor green + 1
    ]
     if random-n > 15 and random-n < 20
    [
      gis:set-drawing-color green + 2.5
      set pcolor green + 2.5
    ]
  ]
  gis:set-drawing-color white
  gis:draw wien-grenzen 1.5
end

to go
  run-sunshine
  run-CO2
  run-heat
  tick
  plot temperature
  ask trees [
    catch-CO2s
  ]
  ask industries [
    emmit-CO2s
  ]
end

to radiate
   if 10 * sun-brightness > random 50 [
     hatch-rays 1 [
     set color yellow
     set heading 150 + random 60
     set size 1]
   ]
end

to run-sunshine
  ask rays [
    if not can-move? 0.3 [ die ]
    fd 0.3
  ]
  create-sunshine
  encounter-earth
end

to create-sunshine
  if 10 * sun-brightness > random 50 [
    create-rays 1 [
      set heading 370
      set color yellow
      setxy (random 60) + min-pxcor max-pycor
;      setxy (min-pxcor + 2) 22.6
    ]
  ]
end

to encounter-earth
  ask rays [
    if [ pcolor ] of patch-here = gray + 1 [
       ifelse (100 * ((pcolor / 10) mod 1)) > random 100
      [ set heading 180 - heading  ]
      [ rt random 45 - random 45
        set color red + random 4
        set breed heats ]
  ]
    if [ pcolor ] of patch-here = gray + 2.5 [
       ifelse (100 * ((pcolor / 10) mod 1)) > random 100
      [ set heading 180 - heading  ]
      [ rt random 45 - random 45
        set color red + random 4
        set breed heats ]
  ]
  ]
end

to run-heat
  set temperature 0.99 * temperature + 0.01 * (12 + 0.1 * count heats)
  ask heats
  [
    let dist 0.5 * random-float 1
    ifelse can-move? dist
      [ fd dist ]
      [ set heading 180 - heading ]
  ]
end

to add-tree
  let created false
  while [ not created ] [
    create-trees 50 [
      set color green
      set size 1.1
      setxy random-xcor random-ycor
      ifelse ID > 0 [
        set created true
      ] [
        die
      ]
    ]
  ]
end

to remove-tree
  repeat 10 [
    if any? trees [
      ask one-of trees [ die ]
    ]
  ]
end

to add-industry
  let created false
  while [ not created ] [
    create-industries 10 [
      set size 2.1
      setxy random-xcor random-ycor
      ifelse ID > 0 [
        set created true
      ] [
        die
      ]
    ]
  ]
end

to remove-industry
  repeat 10 [
    if any? industries [
      ask one-of industries [ die ]
    ]
  ]
end

to add-CO2
  let i 1
  create-CO2s 25 [
    setxy random-xcor random-ycor
  ]
end

to remove-CO2
  repeat 25 [
    if any? CO2s [
      ask one-of CO2s [ die ]
    ]
  ]
end

to run-CO2
  ask CO2s [
    rt random 51 - 25
    let dist 0.05 + random-float 0.1
    if [pycor <= 0.5] of patch-ahead dist
      [ set heading 180 - heading ]
    fd dist
    ;setxy xcor 0.996 * ycor
     setxy random-xcor random-ycor
  ]
end

to catch-CO2s
  let prey one-of CO2s-here
  if prey != nobody
    [ ask prey [ die ]
    ]
end

to emmit-CO2s
  if random 100 > 95 [
  hatch-CO2s 1 [
    set size 1
    set color green
  ]
  ]
end
Here is a screenshot of the interface:

Unbenannt.PNG


Pradeesh Kumar K V

unread,
Jan 13, 2020, 11:30:05 AM1/13/20
to netlogo-users
Hello Tobias,

If you want the dots to move within patches of the same color as it is on, then you could write something like the following (please verify the syntax)

ask dots [
   set colorhere pcolor patch-here   ; sets value of the variable colorhere to color of patch on which dot is presently at 
   set colorahead pcolor patch-ahead 0.5   ; sets value of the variable colorahead to color of patch ahead of the dot at distance of 0.5 units from the dot
   ifelse colorhere = colorahead 
      [ fd 0.1]     ; the dot moves forward if the colors are same
      [ set heading 100 fd 0.1]  ; the dot changes direction and moves away
]

The same logic could be applied if you need to restrict movement of dots within the colored portion (i.e. prevent it from going outside the envelope space)

Regards,

Pradeesh



--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/6d52e73a-fa71-4976-8d93-c68dc03295f9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages