Java StarLogo
2.0
english
`turtle`
to setup
  setshape termite-shape
  seth random 360 
  jump random 200
end

to go
  search-for-chip   ; find a wood chip and pick it up
  find-new-pile     ; find another wood chip
  find-empty-spot   ; find a place to put down wood chip
end

to search-for-chip
  if pc = yellow    ; if find a wood chip...
    [stamp black     ; remove wood chip from patch
     setshape termite-wood-shape     ; turn orange while carrying chip
     jump 20
     stop]           ; exit procedure
  wiggle
  search-for-chip
end

to find-new-pile
  if pc = yellow [stop]   ; if find a wood chip, stop
  wiggle
  find-new-pile
end

to find-empty-spot
  if pc = black      ; if find a patch without a wood chip
   [stamp yellow     ; put down wood chip in patch
    setshape termite-shape         ; set own color back to red
    get-away
    stop]
  seth random 360
  fd 1
  find-empty-spot
end

to get-away   ;leave the pile where you put your chip
  seth random 360
  jump 20
  if pc = black [stop]
  get-away
end

to wiggle
  fd 1
  rt random 50
  lt random 50
end


`observer`
to setup
  ca
  crt number
  ask-patches [if (random 100) < density [setpc yellow]]
  ask-turtles [setup]
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 4: Termites  
This project is an idea model that was inspired by the behavior of termites gathering wood chips into piles. Though the project does not capture all of the complexity of real termite behavior, it does allow you to visualize one simplified aspect of termite behavior -- mound building.   

Click the "setup" button to set up the termites (red) and wood chips (yellow). The "number" slider controls the number of  termites, and the "density" slider controls the initial density of wood chips. (Note: Changes in the "number" and "density"  sliders only take effect when you press "setup".) Click the "go"  button to start the simulation.   

What happens to the distribution of the wood chips? What happens to the number of piles? Over time some piles disappear as termites carry away all of the chips. However, there is no way to start a new pile from scratch, since termites always put down their wood chips near other wood chips. Therefore the number of piles has to decrease over time.


`interface`
SLCanvas
top-left 14 207

SLSlider
top-left 163 40
width-height 127 25
name "density of wood"
variable "density"
min-value 0
max-value 99
current-value 20
slider-number 1
show-name? true

SLSlider
top-left 119 40
width-height 127 25
name "number of termites"
variable "number"
min-value 0
max-value 200
current-value 109
slider-number 0
show-name? true

SLButton
turtle-or-observer? observer
top-left 27 53
width-height 104 30
name "button1"
line-to-run "setup"
forever? false
button-number 2
show-name? false
whichip 8

SLButton
turtle-or-observer? turtle
top-left 74 51
width-height 104 30
name "button2"
line-to-run "go"
forever? true
button-number 3
show-name? false
whichip 9


`turtle shapes`
[encoded data, 7991 characters]

`template`
null

`settings`
patch-size 8
num-shapes 256
screen-half-width 25
screen-half-height 25
interface-window-xcor 355
interface-window-ycor 102
interface-window-size 681 453
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 185
info-window-ycor 185
info-window-width 500
info-window-height 419
control-center-xcor 15
control-center-ycor 17
control-center-width 411
control-center-height 535
turtle-command-center-height 150
observer-command-center-height 150

`string table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`symbol table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`double table`
H4sIAAAAAAAAAGNgYGB2cGtgAAEHDgYILQChAdR1GJscAAAAAAAAHA==

`list table`
H4sIAAAAAAAAAE2MwQ3AIAwDz4FKHYBJOhMPRu1YNRCJRnIcXZwAN1DlZnVLwapi
l9Awezeixs5hD3vj5K/k/O4mKjk35V+tPc/UBzoBiI+AAAAAAAAAgA==

`bytecodes`
H4sIAAAAAAAAAI2T226CQBCG/11OVq3QBFvrRWNq0ztewKumTyLVFUlaIbKG8I7t
OxWWPSCpsXPBziz/znw7DBitPyrONtmWFes3fDf2A2AIp2D8lNfuM7Q1Lmld8lI/
ZjZAm8iX+wQkcKVPhYYE91Jjy30LCG2xwKftulR5HMCDKSLlWLpNCUcoFNbESJR6
+nqOMZ0ZFBEPZRoCmmQttjJP1erGdi92TCzyUPgFi4+bfbTLjtFmnzZgc8MVdvoV
PMg7jjQkQksDGnhLgZoeeZqgtYECsHC7Sw/b6MDKKE8/Wb1/d6U8/WdqG75Izb5y
XkVFnvH6zdOV5OPLdxM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