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

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


`observer`
to setup   
  ct  
  clear-path 
  crt number        ;create turtles based on number slider  
  ask-turtles    
    [setc yellow    
     seth (random 4) * 90    
     pd]
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: Big 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.  

If you are having trouble visualizing the difference between turtles and patches, this project is a particularly good example to explore. In this project, the patch size (and therefore the turtle size too) is larger. All of the obstacles are only a single patch big, and the turtles only walk in the cardinal compass directions.   

Click the "setup" button to set up the turtle in its initial  position. Then click the "go" button to start the simulation.  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.  

As you are exploring this project, try using the "clear-graphics" button and then drawing your own obstacles. You can do this by  using the Paint Tools as described in Challenge 2. Just remember that in the check-patches procedure, the turtles only look for red, green, and blue obstacles (colors 15, 55, and 105 respectively).


`interface`
SLCanvas
top-left 12 235

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 4

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 5

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 6

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

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 7

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 8

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 9


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

`template`
null

`settings`
patch-size 32
num-shapes 256
screen-half-width 6
screen-half-height 6
interface-window-xcor 342
interface-window-ycor 92
interface-window-size 697 442
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 128
info-window-ycor 210
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`
H4sIAAAAAAAAAGNgYGB1cGtgAAH7kzNBYJaDHpjL4BDlAKG9IfIAC2wAbCwAAAAA
AAAs

`list table`
H4sIAAAAAAAAAGNgYGBlYGBgYQQSTEDMCGFHQcX4gdgciDNB8iAlQJqRCayMgYcR
oh7EB4lvQeIzg8xA4sPMZAAAxyG72nAAAAAAAABw

`bytecodes`
H4sIAAAAAAAAAG1S206DQBCdXW4WbMEItmoam+prE599Mn5JkW6K0QApNMZ/1H9y
FobdLXQTlrmcs3MmMxBs338akZU7UW9f4VeePwDwwalFc6zQvAd11haAJw2mY2Sy
J7wWNgCX3iXF8UoisjmwyCXbQhuByQK/RLoAj5gLwZFZP/sS6WFTpU2O3lLXat+e
A4uZrhuZPuv86MGIcR2LlvSGrXRAbHf1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