Java StarLogo
2.0
english
`turtle`
breeds [nv ut wy col az nm]

to turtle-growth
   if breed = nv 
     [if (random 5000) < Nevada-rate    ;all turtles in Nevada a pick a number between 0 and 5000
       [hatch [setc 66 - count-turtles-here]]   ;if the number is below the growth rate, hatch
     ]   
   if breed = ut
      [if (random 5000) < Utah-rate 
         [hatch [setc 76 - count-turtles-here]]
      ] 
   if breed = wy 
      [if (random 5000) < Wyoming-rate 
         [hatch [setc 116 - count-turtles-here]]
      ]
   if breed = col 
      [if (random 5000) < Colorado-rate 
         [hatch [setc 136 - count-turtles-here]]
      ]
   if breed = az 
      [if (random 5000) < Arizona-rate 
         [hatch [setc 26 - count-turtles-here]]
      ]
   if breed = nm
      [if (random 5000) < NewMexico-rate 
         [hatch [setc 46 - count-turtles-here]]
      ]
   wait delay / 50
   if ((count-turtles-here) >= 6) 
        [fd 1      ;move a little if there are a lot of turtles where you are
         if pc = 9  [bk 1] 
         seth random 360] 
   if pc = 9 [bk 1]      ;don't go outside the borders of your state
end


`observer`
globals [year Nevada Utah Wyoming Colorado Arizona NewMexico] 
   ;variables for graphing and counting

to startup
  plotid 2
end

to setup
  plotid 2
  clearplot
  setplot-title ""
  ask-turtles [die]            
  setyear 0
  ask-patches 
  [if pc = 66  
     [sprout [setbreed nv]] 
   if pc = 76
     [sprout [setbreed ut]] 
   if pc = 116
     [sprout [setbreed wy]]
   if pc = 136 
     [sprout [setbreed col]]
   if pc = 26 
     [sprout [setbreed az]]
   if pc = 46 
     [sprout [setbreed nm]]]
  count-pop
  setup-graph
end

to count-pop      ;counts every turtle of the breed specified
  setNevada (count-nv) 
  setUtah (count-ut)
  setWyoming (count-wy)
  setColorado (count-col)
  setArizona (count-az)
  setNewMexico (count-nm) 
end

to growth
  ask-turtles [turtle-growth]
  setyear year + 1
  graph
end

to setup-graph      ;graph using the patch colors of the states
  pp1 ppreset setppc 66 
  pp2 ppreset setppc 76
  pp3 ppreset setppc 116
  pp4 ppreset setppc 136
  pp5 ppreset setppc 26
  pp6 ppreset setppc 46
  setplot-yrange 0 300        
  setplot-xrange 0 200   
  setplot-title "Population vs Year"
end
  
to graph
  pp1 ppd plot Nevada 
  pp2 ppd plot Utah 
  pp3 ppd plot Wyoming 
  pp4 ppd plot Colorado 
  pp5 ppd plot Arizona 
  pp6 ppd plot NewMexico 
end

to go
  startgrowthbutton
  startcount-popbutton
end

to stop-it
   stopgrowthbutton
   stopcount-popbutton
end

to reset
  ask-turtles [die]
  count-pop
  setyear 0
end


`information`
For use with the Adventures in Modeling book,  by Vanessa Colella, Eric Klopfer, and Mitchel Resnick published by Teachers College Press, 2001.  

For more information, see  
<http://education.mit.edu/starlogo/adventures>  

Challenge 10: Turtle Demographics  
Turtle Demographics models the human population explosion. The "setup" button is used to establish initial populations, and  "go" starts the simulation. The sliders, "Nevada-rate", "Utah-rate", etc., control the birth rates for the different states. You can watch the populations grow on the Graphics Canvas, and you can track the actual populations in the monitors and in the Plot Window.  

Breeds enable both the project and the user to distinguish between people in the various states. The different growth rates in the states mean that the turtles must know when to reproduce based on the growth rate for their state. Look at the go  procedure. Notice that the turtles with "breed = nv" are following a different procedure than turtles with "breed = ut". Turtles in each state reproduce when their breed is called upon to do so.


`interface`
SLCanvas
top-left 22 302

SLMonitor
top-left 362 197
width-height 73 36
name "monitor7"
list-to-run "NewMexico"
digits 0
delay 0.5
monitor-number 7
show-name? false
whichip 16
onewhichip 17

SLMonitor
top-left 362 111
width-height 73 36
name "monitor6"
list-to-run "Arizona"
digits 0
delay 0.5
monitor-number 6
show-name? false
whichip 18
onewhichip 19

SLMonitor
top-left 362 21
width-height 73 36
name "monitor5"
list-to-run "Colorado"
digits 0
delay 0.5
monitor-number 5
show-name? false
whichip 20
onewhichip 21

SLMonitor
top-left 312 197
width-height 73 36
name "monitor4"
list-to-run "Wyoming"
digits 0
delay 0.5
monitor-number 4
show-name? false
whichip 22
onewhichip 23

SLMonitor
top-left 312 110
width-height 73 36
name "monitor3"
list-to-run "Utah"
digits 0
delay 0.5
monitor-number 3
show-name? false
whichip 24
onewhichip 25

SLMonitor
top-left 312 22
width-height 73 36
name "monitor2"
list-to-run "Nevada"
digits 0
delay 0.5
monitor-number 2
show-name? false
whichip 26
onewhichip 27

SLSlider
top-left 59 186
width-height 99 25
name "slider1"
variable "Nevada-rate"
min-value 0
max-value 30
current-value 22
slider-number 0
show-name? false

SLSlider
top-left 95 186
width-height 99 25
name "slider3"
variable "Utah-rate"
min-value 0
max-value 30
current-value 6
slider-number 2
show-name? false

SLSlider
top-left 131 186
width-height 99 25
name "slider4"
variable "Wyoming-rate"
min-value 0
max-value 30
current-value 30
slider-number 3
show-name? false

SLSlider
top-left 167 186
width-height 99 25
name "slider5"
variable "Colorado-rate"
min-value 0
max-value 30
current-value 28
slider-number 4
show-name? false

SLSlider
top-left 203 186
width-height 99 25
name "slider6"
variable "Arizona-rate"
min-value 0
max-value 30
current-value 10
slider-number 5
show-name? false

SLSlider
top-left 239 186
width-height 99 25
name "slider7"
variable "NewMexico-rate"
min-value 0
max-value 30
current-value 7
slider-number 6
show-name? false

SLButton
turtle-or-observer? observer
top-left 93 82
width-height 84 30
name "count-popbutton"
line-to-run "count-pop"
forever? true
button-number 8
show-name? false
whichip 10

SLButton
turtle-or-observer? observer
top-left 93 13
width-height 59 30
name "growthbutton"
line-to-run "growth"
forever? true
button-number 6
show-name? false
whichip 11

SLSlider
top-left 189 51
width-height 75 25
name "slider2"
variable "delay"
min-value 0
max-value 50
current-value 10
slider-number 1
show-name? false

SLMonitor
top-left 141 60
width-height 54 36
name "monitor1"
list-to-run "year"
digits 0
delay 0.5
monitor-number 1
show-name? false
whichip 28
onewhichip 29

SLButton
turtle-or-observer? observer
top-left 13 82
width-height 59 30
name "button8"
line-to-run "reset"
forever? false
button-number 9
show-name? false
whichip 14

SLLineWidget
top-left 223 36
width-height 121 73
id 2
order 2
type 1
title "Population vs Year"
delay-string "1.0"
xlabel ""
ylabel ""
grid false
connected true
autoscaletrue
location 0 0
wizard-on false

SLButton
turtle-or-observer? observer
top-left 53 13
width-height 59 30
name "start"
line-to-run "go"
forever? false
button-number 4
show-name? true
whichip 12

SLButton
turtle-or-observer? observer
top-left 53 82
width-height 59 30
name "button4"
line-to-run "stop-it"
forever? false
button-number 5
show-name? false
whichip 13

SLButton
turtle-or-observer? observer
top-left 13 13
width-height 59 30
name "button2"
line-to-run "setup"
forever? false
button-number 3
show-name? false
whichip 15


`turtle shapes`
[encoded data, 5200 characters]
DhUAABUO2Q==

`template`
null

`settings`
patch-size 5
num-shapes 256
screen-half-width 37
screen-half-height 37
interface-window-xcor 139
interface-window-ycor 60
interface-window-size 696 425
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 158
info-window-ycor 108
info-window-width 500
info-window-height 419
control-center-xcor 0
control-center-ycor 85
control-center-width 285
control-center-height 415
turtle-command-center-height 150
observer-command-center-height 150

`string table`
H4sIAAAAAAAAAGNgYGBiYGAQCsgvKM1JLMnMz1MoK1aITE0sAgCmEeAjGgAAAAAA
ABo=

`symbol table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`double table`
H4sIAAAAAAAAAGNgYGB3YIAABw4oLQClRaC0BIS2/wClH0BoAFjnUW88AAAAAAAA
PA==

`list table`
H4sIAAAAAAAAAG1SSQ7CMAz0krQg9QDiRG/cEQeewLkP4QF9RJ/Gs8jEEzVIVKrG
U9sTe1IRuYqIqogVPAETPuzvSyO/WPDVgm8FreBc0As+CqJ1Qn2JM7TY4+xJ7Mns
GdjjPAs1eM6McTbqF42aFRo4W0N/hgbOjn69U+eTYvyJOkodo45TJ1EnU2eQqEF8
+BML57uF5mVrHsWelRu9anmnZ0ae6J2TZ3qYyNs+mPlJjvgYqO8WxyhVf6SXbf6R
uzj7s/3ulpnLvJOWq1x2f7zLVS67f9blnP+Pc3/tcsZZvd1vl6v8C5tSoX+EAgAA
AAAChA==

`bytecodes`
H4sIAAAAAAAAAKVWTXObMBBdMN/YBhyTOGmbepowPfnUW079OKe3Tg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er world`
H4sIAAAAAAAAAD2NMQ7CMAxFnVKaAgtHYEDsrEwgZroh1gZqtZFKXKVRSzkJK+IW
nA4nQrX0JH/9/21Y5nRt0XZoV61TDvM9jLODeVOT63VRomMdQ1KjKV3F+xqk9xo0
IboI5dFNGQnxgMoGO8mwU4XiTUB8dspnIpCXge7alCwmkB6pJqsKCo/kweonGd+Y
wizD/oQPffNe8icS4Zr4MlvmxWyYN/P5AX35hzTXAAAAAAAA1w==

`patch world`
[encoded data, 17290 characters]
cT/vq8jL7///vim1DZ2/AgAAAr+d

`turtle world`
[encoded data, 19175 characters]
YmN/nYzbyF8n44aaQ+9zKza0D4D7PxTd8/MgCgIAAAIKIA==

