Java StarLogo
2.0
english
`turtle`
turtles-own [happiness] 

to go 
  check-patches 
  scale-color 65 happiness 0 20            
  friends-meet                       
  move
  wiggle
  wait .05
end

to check-patches       ;increase or decrease happiness based on slider settings and patch colors
  if (pc = blue or pc = 109)
       [sethappiness ((1 + (school / 100)) * happiness)]  
  if (pc = red or pc = 19)
       [sethappiness ((1 + (cinema / 100)) * happiness)]
  if happiness < .1 [sethappiness .1]       ;don't let happiness go below .1
  if happiness > 20 [sethappiness 20]       ;or above 20
end

to friends-meet   
  ifelse count-turtles-here > 1        ;see if you are on the same patch with another turtle
  [  sethappiness (happiness * 2)      ;if true, double happiness  
     if happiness > 20 [sethappiness 20]     ;but not above 20 
  ]
  [  sethappiness (happiness * .992)    ;if false, lose a little happiness
     if happiness < .1 [sethappiness .1]     ;but not below .1
  ]
end

to wiggle
  lt random 10
  rt random 10
end

to move  
  rt happiness      ;turn right based on happiness
                    ;happy turtles make a circle and sad turtles keep moving
  fd happiness / 5 
end


`observer`
to setup
  ask-turtles [die]
  crt number
  ask-turtles 
      [sethappiness random initial-happiness      ;set intitial happiness to a random number
       scale-color 65 happiness  0 20
       setxy random screen-width random screen-height
      ]
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 6: Shiny Happy Turtles 1  
This project builds on the principles introduced in the Energizer  Turtles project from Challenge 5. The turtles in this project are  born with a state of happiness (a turtle variable similar to  energy in Challenge 5). Turtles’ happiness can increase or decrease as they interact with their environment and with other turtles.   

Two turtle-environment interactions are modeled in this project.  When turtles are in the red "cinema" patches, they gain or lose happiness based on the settings in the "cinema" slider.  Similarly, turtles gain or lose happiness in the blue "school" patches based on the value of the "school" slider.   

Turtle-turtle interaction is also modeled in this project. When the turtles find themselves alone on a patch, they lose a small amount of happiness. But, when turtles find themselves sharing a patch with another turtle, they double their happiness. The assumption underlying this model is that turtles are happier when they are in contact with other turtles.  

Turtles express their happiness in three ways. 
First, happier turtles move faster. 
Second, happier turtles are lighter in color (very light green as compared to dark green). 
Finally, happier turtles tend to circle to their right, aiming to get back to the place that made them happy, while unhappy turtles tend to keep moving in a straight line as they look for a more pleasant environment.  

To start the simulation, click "setup" to create the number of turtles indicated on the "number" slider. Each turtle is created with a random level of happiness. You can adjust the maximum value using the "initial-happiness" slider. Click "go" to watch the turtles interact with each other and with their environment.  

You can change the influence exerted by the movies and the school  by increasing or decreasing values of the "school" and "cinema" sliders. The slider values control the percentage increase or decrease in happiness of a turtle when it occupies the school or cinema patches.


`interface`
SLCanvas
top-left 21 235

SLButton
turtle-or-observer? turtle
top-left 63 9
width-height 68 30
name "button2"
line-to-run "go"
forever? true
button-number 2
show-name? false
whichip 6

SLSlider
top-left 143 90
width-height 103 25
name "slider4"
variable "school"
min-value -50
max-value 50
current-value -2
slider-number 4
show-name? false

SLSlider
top-left 23 90
width-height 103 25
name "slider2"
variable "number"
min-value 0
max-value 200
current-value 50
slider-number 1
show-name? false

SLSlider
top-left 103 90
width-height 103 25
name "slider3"
variable "cinema"
min-value -50
max-value 50
current-value 5
slider-number 3
show-name? false

SLSlider
top-left 63 90
width-height 103 25
name "slider2"
variable "initial-happiness"
min-value 0
max-value 20
current-value 5
slider-number 2
show-name? false

SLButton
turtle-or-observer? observer
top-left 23 9
width-height 68 30
name "button1"
line-to-run "setup"
forever? false
button-number 1
show-name? false
whichip 7


`turtle shapes`
[encoded data, 5330 characters]
qqqqqqqaoR8DO5wb3dkOFQAAFQ7Z

`template`
null

`settings`
patch-size 8
num-shapes 256
screen-half-width 24
screen-half-height 22
interface-window-xcor 229
interface-window-ycor 107
interface-window-size 671 391
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 219
info-window-ycor 391
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`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`symbol table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`double table`
H4sIAAAAAAAAAGNgYGC1XzkTBGY5RDkwgICDHphisN8JEbd/v6/sxBbLCABE/U7N
LAAAAAAAACw=

`list table`
H4sIAAAAAAAAAG2OwQqAMAxDs25D8OJB8X/8F6/+/3WpjbKJhUehadICmEASkIgR
kEPd2djqd2a4a7fwXfIXcj57FnmrtNxr0rPF/M0VXot86P4adpRR/vIQntnBeKO6
2ABQTY3M+AAAAAAAAPg=

`bytecodes`
H4sIAAAAAAAAAHVU7U7CMBS9XbcB22BjMgElkUTjP17AH8b4Gv5BoSJRGHFD4zvq
O3m73a1dgSbs9uOee05PW8Cfv/zkYpEuRTZ/gF/Z/gCgDU4m8v0Ou7dQN4s+Iwwc
f9cuACuX2A1+RjblDGmeFfMsqvJwMWbU5xRtYLFHfYci5icxsIlVYNmElzUSV/GG
MhkrrlL8TpXGVi2UhOmRaVyW0oFcJY4bdRxjbBt1cRx6pIVBd/EmFu+z3XOOnQyX
n1T2QElh0VAbs3IcXZHq/oG8wtrKqkhaAbVdcjssspRt0l65i9DSOFoGZ/sEZ4ei
p3H6BmdgcHYbnOVcT7M5xNxz4qmuQUSxfwQba9gzxCYGdkAxaWKLI7AgeP1ci+0y
m22EyHHpXp3ApX4CVdXx0Yuhdse1C9u8qIfK3NrthjIOBldbq9PRuDyNy9dygiMO
dmunD7hCTm5wcL/Xq9WHKOopIyoP5IO60G6hHI8Ja4O9Sb9EyWAipbLklHPyOQVU
xQH/cZ/n6fZuOi3eaYe24dB7Yqp4Id2lRRd6NbD6H6owjSZz/wHwA6HbxAQAAAAA
BMQ=

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

`patch world`
[encoded data, 6305 characters]
Of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