Netlo go - Как отражать черепах из пятен в зависимости от цветовой гаммы - PullRequest
0 голосов
/ 17 января 2020

Я пытаюсь отразить черепах патчей в зависимости от pcolor scale-color. По сути, я использую ползунок в моей модели, где цвет шкалы патчей можно регулировать от черного до белого. Если черепаха в форме луча попадает на участок, будет создана другая черепаха в форме точки.

В зависимости от цвета, должно быть создано различное количество точек или вероятность создания точки должна быть разной. Поэтому, если патч черного цвета, нужно создавать больше точек, если патч белого цвета, нужно создавать меньше точек, как в модели изменения климата: https://ccl.northwestern.edu/netlogo/models/ClimateChange

I'm застрял в этой проблеме. Может ли кто-нибудь помочь мне с этой проблемой? Вот мой код:

extensions [ gis ]

globals [
  wien-grenzen
  temperature
]

turtles-own [
  birth-tick
]

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
  ask patches [
    set pcolor 37
  ]
  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
  let maxG 5
  let maxLG 10
  let maxGr 15
  let maxVal 20
  ask patches with [ID > 0] [
    ifelse ID = 13 [
      set maxG 17
      set maxLG 18
      set maxGr 19
    ][
      set maxG 5
      set maxLG 10
      set maxGr 15
    ]

    set random-n random-float maxVal

    ifelse random-n <= maxG [
      gis:set-drawing-color gray + 1
      set pcolor gray + 1
    ][
      ifelse random-n <= maxLG [
        gis:set-drawing-color gray + 2.5
        set pcolor gray + 2.5
      ][
        ifelse random-n <= maxGr [
          gis:set-drawing-color green + 1
          set pcolor green + 1
        ][
          gis:set-drawing-color green + 2.5
          set pcolor green + 2.5
        ]
      ]
    ]
  ]
  ask patches with [pcolor = gray + 1]
    [ update-albedo-sealed ]
  ask patches with [pcolor = gray + 2.5]
    [ update-albedo-building-regular ]
  ask patches with [pcolor = green + 1]
    [ update-albedo-grassland ]
  ask patches with [pcolor = green + 2.5]
    [ update-albedo-building-greened ]
  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
  ]
  ask turtles with [shape = "dot"][if [ pcolor ] of patch-ahead 6 != gray [set heading heading - 100 ]]
  if ticks > 5000 [stop]
end

to update-albedo-sealed ;; patch procedure
  set pcolor scale-color gray albedo-sealed 0 1
end

to update-albedo-building-regular ;; patch procedure
  set pcolor scale-color gray albedo-building-regular 0 1
end

to update-albedo-grassland ;; patch procedure
  set pcolor scale-color green albedo-grassland 0 1
end

to update-albedo-building-greened ;; patch procedure
  set pcolor scale-color green albedo-building-greened 0 1
end

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

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

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

to encounter-earth
  ask rays with [ID > 0] [
       ifelse 10 * albedo-sealed > random 10
      [ set heading 180 - heading ]
      [ rt random 45 - random 45
        set color red + random 4
        set breed heats ]
      ]
    ask rays with [ID > 0] [
       ifelse 10 * albedo-building-regular > random 10
      [ set heading 180 - heading  ]
      [ rt random 45 - random 45
        set color red + random 4
        set breed heats ]
      ]
    ask rays with [ID > 0] [
       ifelse 10 * albedo-grassland > random 10
      [ set heading 180 - heading  ]
      [ rt random 45 - random 45
        set color red + random 4
        set breed heats ]
      ]
    ask rays with [ID > 0] [
       ifelse 10 * albedo-building-greened > random 10
      [ 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.01 * count heats)
  ask heats
  [
    let dist 0.5 * random-float 1
    ifelse can-move? dist
      [ fd dist ]
      [ set heading 180 - heading
    set birth-tick ticks
      ask heats [if ticks - birth-tick > 200 [die] ]
    ]
  ]
;;  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
;]
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
...