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

to go 
  check-patches 
  scale-color 65 happiness  0 20
  friends-meet 
  set-avghappy
  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 
  if count-turtles-here > 1 
                    ;if more than one turtle on patch
                    ;set avghappy to the average happiness of you and another turtle
                    ;if more than one other turtle, pick one to average with
     [setavghappy    ;set avghappy variable
          (((happiness-of one-of-turtles-here) + happiness) / 2)
     ]
end

to set-avghappy       ;use avghappy variable to calculate and set happiness variable
  ifelse count-turtles-here > 1       ;if there is another turtle here
     [ sethappiness avghappy * 1.1      ;set happiness to average plus 10%
       if happiness > 20 [sethappiness 20]      ;but not above 20
     ]
     [ sethappiness (happiness * .992)         ;if not, lose a little happiness
       if happiness < .1 [sethappiness .1]     ;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 initial 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 2  
The interface and most of the principles of Shiny Happy Turtles 2 are exactly the same as those in Shiny Happy Turtles 1. 

Play with  Shiny Happy Turtles 2 for a little while. Can you tell what is different about this project based on your observations of the turtle-turtle and turtle-environment interactions? What unique  patterns can you identify in this project?  

In Shiny Happy Turtles 2, when two turtles share a patch they average their two happiness values (and add 10 percent for good fortune). These turtle-turtle interactions can lead to noticeably different patterns than the kind you observed in Shiny Happy Turtles 1. Watch what happens when a really happy turtle meets a really unhappy turtle. A good place to look for this is in a patch that causes turtles to lose happiness. 

What other kinds of interactions can you see in Shiny Happy Turtles 2?


`interface`
SLCanvas
top-left 17 231

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 7

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

SLSlider
top-left 143 90
width-height 103 25
name "slider4"
variable "school"
min-value -20
max-value 20
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 -20
max-value 20
current-value 5
slider-number 3
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 8


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

`template`
null

`settings`
patch-size 8
num-shapes 256
screen-half-width 23
screen-half-height 22
interface-window-xcor 195
interface-window-ycor 102
interface-window-size 679 415
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 234
info-window-ycor 268
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`
H4sIAAAAAAAAAGNgYGC3XzkTBGY5RDkwgICDHphisN8JEbf/AOV/hPLf7ys7scUy
AgC6A/1vPAAAAAAAADw=

`list table`
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