Java StarLogo
2.0
english
`turtle`
to go 
repeat 4 [check-color] fd 1 
end

to check-color           ;turn based on patch color
  if pc-ahead = 14 [rt 180]
  if pc-ahead = 54 [lt 90]
  if pc-ahead = 104 [rt 90]
  if pc-ahead = 44 [die]
  if pc-ahead = violet [rt 90]
end

to random-color           ;set color randomly, but don't pick color used in setup
  setc random 140  
  if (color = violet or color = 104 or color = 44)
      [random-color]
end


`observer`
to setup1          ;code for setup first turtle button
  ask-turtles [die]
  crt 1
  ask-turtles
   [sety 4
    setc violet
    seth 0
    pd]
end

to setup2          ;code for setup second turtle button
 ask-turtles [die]
 crt 1
 ask-turtles
  [sety 3
   random-color
   seth 90
   pd
   sety 2
  ]
end

to clear         ;set patches black except ones used in setup
ask-patches
   [if not (pc = 104 or pc = 44)
     [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: Follow the Leader  
This project starts off like Bumper Turtles with a turtle checking patch color and turning accordingly. The first turtle in this project, however, draws with its pen down, leaving a path behind it. When a second turtle is created, it begins in a slightly different location than the first turtle. Notice that when this turtle starts moving it winds up following the path of the first turtle. 

This demonstrates a simple way that the first turtle can influence the environment and subsequently affect the behavior of another turtle. You will explore this idea more extensively in the next Challenge.  

To use this project, click on the "setup first turtle" button. Then click the "go" button to see the first turtle draw its path. Now, click "setup second turtle" and then "go" and watch what happens. Try clicking the "setup second turtle" button and pressing go several times. 

What happens if you press the "clear" button and then setup the second turtle?


`interface`
SLCanvas
top-left 7 206

SLButton
turtle-or-observer? observer
top-left 19 38
width-height 102 30
name "setup first turtle"
line-to-run "setup1"
forever? false
button-number 1
show-name? true
whichip 6

SLButton
turtle-or-observer? observer
top-left 62 37
width-height 102 30
name "setup second turtle"
line-to-run "setup2"
forever? false
button-number 2
show-name? true
whichip 7

SLButton
turtle-or-observer? turtle
top-left 111 48
width-height 80 30
name "start"
line-to-run "go"
forever? true
button-number 3
show-name? false
whichip 8

SLButton
turtle-or-observer? observer
top-left 151 49
width-height 80 30
name "some-random-buttom"
line-to-run "clear"
forever? false
button-number 4
show-name? false
whichip 9


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

`template`
null

`settings`
patch-size 8
num-shapes 256
screen-half-width 26
screen-half-height 24
interface-window-xcor 456
interface-window-ycor 119
interface-window-size 675 410
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 241
info-window-ycor 173
info-window-width 500
info-window-height 421
control-center-xcor 155
control-center-ycor 216
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`
H4sIAAAAAAAAAGNgYGB0iDnAAAIAto2usAwAAAAAAAAM

`list table`
H4sIAAAAAAAAAGNgYGBnYGBgYWRgYARiFiYgB0gzIIkxA3EUEIOkQOwMINaBqmFi
hKoDsoUZIXpBeviAeAsS3wxqBoyfgcbXgbGh9kdB7e+B8sF2giwEALg5FCWwAAAA
AAAAsA==

`bytecodes`
H4sIAAAAAAAAAJVTTVODMBDdAMFSKmCHjG21IzOePejRk+PZH9FK8WOsxYH04H/U
/2QSlhACFzOTZJPN2/ey2UC4ef7mRV7uinrzAD+y/QLAFPy64MevW2EvQTcHh4WY
XNGvfQCCvoWH/hD3xMAo2sLBErQFkIkAjHUxYqDS03DeCWv9T864z3kibdrF0BqQ
V+uglgYCNN8X2woaPlPCHEhKNDVJzo01adbJlehrPO91tKnX0MQO0nlI54DzWoqN
xJLacrZX8Tq/ihMY151hLBfC/K3IP27ycl/KCzwNg7Zi00iLk8L7gmVelp1gYvqo
gfVHsEItW1nYCc6BgZ2OYMMR3hnOpwY2MrBGXWhMWwuJgTkb4Zv3+VQSPZhV28Ou
/NRZXA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