Java StarLogo
2.0
english
`turtle`
to go 
  check-patches
  fd 1
end

to gowiggle 
  check-patches
  fd 1
  wiggle
end

to check-patches       ;turn based on patch color
 if pc-ahead = red [rt 180]
 if pc-ahead = blue [rt 90 check-patches]
 if pc-ahead = green [lt 90 check-patches]
end

to wiggle              ;change direction a little randomly
  rt random 5 
  lt random 5
end


`observer`
to setup 
  ct 
  crt number        ;create turtles based on number slider
  ask-turtles 
   [setc yellow
    seth random 360]
end

to clear-path       ;set patch colors black unless part of obstacles
  ask-patches [if not (pc = 15 or pc = 55 or pc = 105)
               [setpc black] ]
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 3: Bumper Turtles  
In this project the turtles change direction every time they bounce off of an "obstacle". Depending on the color of the obstacle, the turtle will turn either to the right, to the left, or all the way around.  

Click the "setup" button to set up the turtle in its initial position. Then click the "go" button to start the simulation. If you want to, try adding some randomness to the turtle's path, stop the "go" button and then press the "go and wiggle" button.  

By using the "pen-down" and "pen-up" buttons you can control whether or not the turtle marks the path that it follows by drawing on the patches with its pen. To erase the turtle's path use "clear-path", which clears only the yellow path drawn by the turtle.


`interface`
SLCanvas
top-left 10 228

SLButton
turtle-or-observer? observer
top-left 141 23
width-height 72 30
name "button5"
line-to-run "clear-path"
forever? false
button-number 6
show-name? false
whichip 6

SLButton
turtle-or-observer? turtle
top-left 99 23
width-height 72 30
name "pen-down"
line-to-run "pd"
forever? false
button-number 7
show-name? true
whichip 7

SLSlider
top-left 15 116
width-height 90 25
name "slider1"
variable "number"
min-value 1
max-value 99
current-value 1
slider-number 0
show-name? false

SLButton
turtle-or-observer? turtle
top-left 99 120
width-height 78 30
name "pen-up"
line-to-run "pu"
forever? false
button-number 2
show-name? true
whichip 8

SLButton
turtle-or-observer? observer
top-left 141 120
width-height 78 30
name "clear-graphics"
line-to-run "cg"
forever? false
button-number 5
show-name? true
whichip 9

SLButton
turtle-or-observer? turtle
top-left 54 112
width-height 96 30
name "go and wiggle"
line-to-run "gowiggle"
forever? true
button-number 3
show-name? true
whichip 10

SLButton
turtle-or-observer? turtle
top-left 54 27
width-height 61 30
name "button1"
line-to-run "go"
forever? true
button-number 4
show-name? false
whichip 11

SLButton
turtle-or-observer? observer
top-left 15 19
width-height 81 30
name "button2"
line-to-run "setup"
forever? false
button-number 1
show-name? false
whichip 12


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

`template`
null

`settings`
patch-size 4
num-shapes 256
screen-half-width 50
screen-half-height 50
interface-window-xcor 338
interface-window-ycor 134
interface-window-size 643 425
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 310
info-window-ycor 231
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`
H4sIAAAAAAAAAGNgYGBxcGtgAAEHPQYIHeUAob0h4gDjROjiJAAAAAAAACQ=

`list table`
H4sIAAAAAAAAAE2M0QkAIBBCvavoJ2icdmmC2q8B0/ooOE+eggAygGB8Thls0CK5
Uo2a6lSZ6uflAM9vtj52ev9Y+x03T5IGN9P6fpp8AAAAAAAAfA==

`bytecodes`
H4sIAAAAAAAAAI1TyW7CMBAdmzgsKSQVhKUSakS5cuylp6pfQhqsgIqSiASh/mP7
T/VuB1qpc7A8M++9WeJAsH3/bGhW7mi9fYUvbt8AMARS0+ZcsesYjK06AEhe0Zod
cw8Ac6+n4uyII3XHgCKf+XMARoMndg+B8MwgO9L0tKnSZs+8pdUXWjNAE2TrRK6P
pB89OjFsY9FSaXgqxwpPPFk/xKoPT/WBAOcl78bW7yquNtUDxHeKg6GXl5dDnh8p
C4/+xxQ5YnNCqQPDbE+zD74FdqlZ/PmWroeejFrD3gwZL+yQyM0Rh+s7XP3BupJ7
3X5LS2P7jtbA0SIqFjCtBwE3fDGqB75ZWXAzo3wkC+cD+1JHcAmM385NUxYvSdJ6
NUQ1jcAxwoe8N4SKFptdeSnE3iCODSRsQcQr54CpAcyuiuantNofsloCV8gApwaY
l0la7BIzad9up6tX6m7XNxqBo/ELEf9JHBmi/lc1p2Uc+wNOmqQy6AMAAAAAA+g=

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

`patch world`
[encoded data, 31395 characters]
BPud

`turtle world`
H4sIAAAAAAAAAG2Ouw6CQBBFL5GHUWNlaWFBZWGhFpZUfgfITliSze4G1qAdf+Kn
6rioMdHbzDmZRwbz3J0bp2jVusJRnuGTG2JFunKS+YDo1BAJxhQTq4zralGRY98j
ebolzbJBVBplGsYlwmvpaYapP/51bczjwnTasm0RtbKwxLhGeBl2Qow6afwfcStf
kzskkgpR64pl8f7zzuES4E+yuh/qsf9tBn4neABcInliAwEAAAAAAQM=

