Java StarLogo
2.0
english
`turtle`
turtles-own [sick?]

to infect 
  rt random 100 
  lt random 100
  fd 1
  if sick?       ;if you're sick, make all the other turtles on your patch sick
    [setsick?-at 0 0 true          
    make-sick]
end

to recover 
  if sick?  
    [if (random 100) < recover-rate      ;randomly recover based on the recover-rate slider
      [setsick? false     
       make-healthy]]
end

to make-healthy  
  setc green
end

to make-sick  
  setc red
end


`observer`
to setup 
  ca
  crt number 
  ask-turtles 
    [setxy random screen-width random screen-height             
     setshape 2
     ifelse who < init-infected                
       [make-sick  
       setsick? true]               
       [make-healthy 
       setsick? false]]
  clearplots
end

to go 
  startinfectbutton
  startrecoverbutton
end

to stop-it 
  stopinfectbutton
  stoprecoverbutton
end

to infected-% 
  output ((count-turtles-with [sick?]) / count-turtles) * 100
end


`information`
Epidemic  

This project presents a very simple model for the spread of a disease. There are two types of creatures: healthy creatures (green) and sick creatures (red). When a healthy creature comes in contact with a sick creature, it becomes sick.  

Click the "setup" button to setup the creatures. Click the "go" button to start the simulation. The "infected-%" monitor shows the percentage of sick creatures. The "number" slider controls the number of creatures. (Changes in this slider do not take  effect until the next setup.) The "init-infected" slider controls the initial number of sick creatures. The "recover-rate" slider controls the rate at which sick creatures become healthy. 

If you start with just one sick creature, the disease spreads slowly at first. But as more creatures become infected, the disease spreads rapidly. The spread of the disease is a good example of exponential growth.  

If the "recover" slider is set at greater than zero, sick creatures have a chance to become healthy again. So there are two competing forces: disease spreads by contact, but sick creatures have a probabilistic chance to become healthy again.  Over time, the overall percentage of sick creatures should reach a rough equilibrium. 

How do changes in the recover rate affect the equilibrium percentage of infected creatures? How is the equilibrium affected by changes in the total number of creatures?


`interface`
SLCanvas
top-left 17 252

SLButton
turtle-or-observer? turtle
top-left 60 6
width-height 71 33
name "infectbutton"
line-to-run "infect"
forever? true
button-number 5
show-name? false
whichip 8

SLMonitor
top-left 187 137
width-height 80 36
name "monitor0"
list-to-run "infected-%"
digits 0
delay 0.5
monitor-number 1
show-name? false
whichip 13
onewhichip 14

SLSlider
top-left 239 17
width-height 102 25
name "slider2"
variable "recover-rate"
min-value 0
max-value 10
current-value 1
slider-number 2
show-name? false

SLSlider
top-left 145 17
width-height 102 25
name "slider0"
variable "number"
min-value 0
max-value 1500
current-value 1000
slider-number 0
show-name? false

SLButton
turtle-or-observer? turtle
top-left 60 89
width-height 71 33
name "recoverbutton"
line-to-run "recover"
forever? true
button-number 6
show-name? false
whichip 9

SLSlider
top-left 192 17
width-height 102 25
name "slider1"
variable "init-infected"
min-value 0
max-value 700
current-value 198
slider-number 1
show-name? false

SLButton
turtle-or-observer? observer
top-left 8 89
width-height 71 33
name "button2"
line-to-run "go"
forever? false
button-number 3
show-name? false
whichip 10

SLButton
turtle-or-observer? observer
top-left 8 172
width-height 71 33
name "button3"
line-to-run "stop-it"
forever? false
button-number 4
show-name? false
whichip 11

SLButton
turtle-or-observer? observer
top-left 8 6
width-height 71 33
name "button1"
line-to-run "setup"
forever? false
button-number 2
show-name? false
whichip 12

SLLineWidget
top-left 277 15
width-height 190 118
id 3
order 3
type 1
title "Population vs Time"
delay-string "1.0"
xlabel ""
ylabel ""
grid false
connected true
autoscaletrue
location 0 0
whichip 15
onewhichip 16
wizard-on true
lineset-id 1
lineset-name "sick"
lineset-order 3
lineset-type 1
lineset-color -65536
lineset-displayed? true
lineset-instruction "( count-turtles-with [ color = red] )"
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with? true
extrainfo-with-text " color = red"
extrainfo-xy? false
extrainfo-xval? false
lineset-end 1
lineset-id 2
lineset-name "healthy"
lineset-order 3
lineset-type 1
lineset-color -11418368
lineset-displayed? true
lineset-instruction "( count-turtles-with [ color = green] )"
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with? true
extrainfo-with-text " color = green"
extrainfo-xy? false
extrainfo-xval? false
lineset-end 2
lineset-id 3
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -6262704
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 3
lineset-id 4
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -256
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 4
lineset-id 5
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -11418368
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 5
lineset-id 6
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -16711936
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 6
lineset-id 7
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -16711738
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 7
lineset-id 8
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -16711681
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 8
lineset-id 9
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -16744449
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 9
lineset-id 10
lineset-name "<name>"
lineset-order 3
lineset-type 1
lineset-color -7434610
lineset-displayed? false
lineset-instruction "( count-turtles) "
extrainfo-extra? true
extrainfo-instruction "number of"
extrainfo-breed "turtles"
extrainfo-var "Xcor"
extrainfo-with false
extrainfo-xy? false
extrainfo-xval? false
lineset-end 10


`turtle shapes`
[encoded data, 7345 characters]

`template`
null

`settings`
patch-size 8
num-shapes 256
screen-half-width 25
screen-half-height 25
interface-window-xcor 343
interface-window-ycor 97
interface-window-size 684 442
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 190
info-window-ycor 121
info-window-width 500
info-window-height 419
control-center-xcor 16
control-center-ycor 94
control-center-width 319
control-center-height 511
turtle-command-center-height 150
observer-command-center-height 150

`string table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`symbol table`
H4sIAAAAAAAAAGNgYGBiYCkpKk1lYE1LzClOBQBgXN0IEQAAAAAAABE=

`double table`
H4sIAAAAAAAAAGNgYGBx8G5gAAEHPTDFYP8ASn+A0ADuygccJAAAAAAAACQ=

`list table`
H4sIAAAAAAAAAHVOQQ6AMAyCLlMv/tL/v0FIWfSgBwajhBbACWCnHqEEjtYQ04z2
p7B9aGcv0WEOGH/1ID1z5b3r1c96OFbfor9HzjF3jviMLgeq12x/8xt1uxzj6AAA
AAAAAOg=

`bytecodes`
H4sIAAAAAAAAAL1UTVODMBDdQBMK7RSs4vco0w899eStJ8eznr2qbWwZtTht6oz/
Uf+TISxJgaI3M9NsFt7bfdldCq2Hp0/BJ8mUrx6u4Std3wCwA3TFxfpdHq9Ar578
kexIBnI7bABYqXcJ5NQCEjBpbWUhZIiVW3gBJNxD31JcEuwj1wNwUuuYPApno5U5
ukS5RTwr4SlaZvC+ndm+fDY8l34KkmFmidzdEl+uQcNoTs9+FtRZieR9FIsaEt0g
USRZ4MWLZz4RfDoayneB4Vl4qbyQXU+5Vt8FctSUhbF1PBJIsE8wpg0si4mdKOrI
in60wU39Y110CNu6sCqn0tExRS4XkWBTuqzaIFVcC3U1wFnKCfrgS/n0rCpMJwuL
4uqmYVv3yx3PBRSEUGi/Pb7w0Zw/vor5J1RnJBURIJqBq9CrePLyB9QB/2YtRLIY
R5FugYuKKaprlNQxfNmEQJNNncpsWstuabYa25xAYGOV0ph5zdFWBd0xaPzQaaHF
m9jdu2QRi2Q5jgpD7WPcllHj5BfANTDDDL5XuptbF7j5e0BF9qBzGy94dB9PZ1yM
o/RvqoeCzgw/T47FJmHHDF5woL88GA6rg1fh0BoO23K51hZ9J/+nS2lo/wBn+dlq
3wUAAAAABd8=

`observer world`
H4sIAAAAAAAAAGMQSMhPKk4tKkstUiguSSxJTXBggAMrBq6CnPyS8syU9NQSIJ+F
gS0nNS+9JAPI5mBgB8kVpOaBlXKDNSPJQgAjCAMA+OWZc2QAAAAAAABk

`patch world`
[encoded data, 7276 characters]

`turtle world`
[encoded data, 15600 characters]
a596sN2fCaP4v1+SL8DP7QcZt+f1f/8H32obizbrAAAAAOs2

