Help with code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Help with code

Lemon
This post has NOT been accepted by the mailing list yet.
Hello, I'm trying to crate a complex environment, where three types of trees co-exits and you can modify the numbers of each type using a slider. What I'm having problems implementing is a "day/night" cycle. When it is night the colors should turn darker, but with the code I have the colors get darker and never return to a brighter color. I used as a base the Algae model. Thank you very much.

Here is my code:

to setup
  clear-all
  setup-world
  reset-ticks
end

to setup-world
  ask n-of synchronic-tree-density patches [
    set pcolor blue
  ]
  ask n-of asynchronious-tree-density patches [
    set pcolor yellow
  ]

  ask n-of tree-patches patches [
    set pcolor green
    ]
  recolor-world true
end

to recolor-world [ setting-up? ]
  ask patches [
    if pcolor = blue [
        ifelse setting-up? or daytime? [
          set pcolor blue
          ] [
          set pcolor blue - 3
          ]
        ]
    if pcolor = yellow [
        ifelse setting-up? or daytime? [
          set pcolor yellow
          ] [
          set pcolor yellow - 3
          ]
        ]
    if pcolor = green [
        ifelse setting-up? or daytime? [
          set pcolor green
          ] [
          set pcolor green - 3
          ]
        ]
      ]

end

to go
  recolor-world false
  tick-advance 1
end

to-report daytime?
  report ticks mod 24 < day-length
end