Java StarLogo
2.0
english
`turtle`
turtles-own [speed]

to go 
  check-patches 
  fd speed 
  wiggle 
  check-speed 
end

to check-patches 
  if pc-ahead = red [rt 180 setc red]
  if pc-ahead = blue [rt 90 setc blue check-patches]
  if pc-ahead = green [lt 90 setc green check-patches]
end

to check-speed         ;set speed based on what color you are
  if color = red [setspeed (red-speed / 500)]
  if color = blue [setspeed (blue-speed / 500)]
  if color = green [setspeed (green-speed / 500)]
end

to wiggle
  rt random 5
  lt random 5
end


`observer`
to setup 
  ask-turtles [die]  
  crt number 
  ask-turtles 
   [setc yellow
    seth random 360
    setspeed 1]
end

to clear-path 
  ask-patches [if not (pc = 15 or pc = 65 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 4: Speeding Bumper Turtles  

This project introduces the simple use of sliders to control how the turtles react to obstacles in their environment. In any  model, sliders control values that anyone can easily change.  Often, even a small change in a slider will cause a noticeable change in how the whole system looks or behaves.  

Speeding Bumper Turtles is similar to the Bumper Turtles project in the previous Challenge, except that in this project the turtles’ speeds change every time they bounce off of a colored obstacle. The speed associated with each obstacle is determined by the corresponding slider value. Take a look at the procedures to see how this behavior is implemented. Remember, every time you see "red-speed", "green-speed", or "blue-speed" in the procedures code, the program is reading the current value from the corresponding slider.  

Click the "setup" button to set up the turtles at their initial positions. Click the "go" button to start the simulation. At any time, you can change the value of each of the speed sliders, "green-speed", "red-speed", and "blue-speed". The value of each  slider determines the speed that the turtles assume after they  bounce off of a colored patch. You can also set the "number" slider to determine the number of turtles in the project. This change only takes effect when you setup the simulation again. 

If  you want to draw a new set of obstacles, press "clear-graphics" and draw new obstacles using the Paint Tools. According to the existing procedures, the obstacles need to be blue, red, or green for the turtles to react to them, but you can make the obstacles in any shape or location that you wish.


`interface`
SLCanvas
top-left 11 227

SLSlider
top-left 120 120
width-height 90 25
name "slider4"
variable "blue-speed"
min-value 0
max-value 500
current-value 200
slider-number 3
show-name? false

SLSlider
top-left 56 120
width-height 90 25
name "slider2"
variable "red-speed"
min-value 0
max-value 500
current-value 487
slider-number 1
show-name? false

SLButton
turtle-or-observer? observer
top-left 118 19
width-height 85 30
name "clear-graphics"
line-to-run "cg"
forever? false
button-number 2
show-name? true
whichip 6

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

SLSlider
top-left 88 120
width-height 90 25
name "slider3"
variable "green-speed"
min-value 0
max-value 500
current-value 3
slider-number 2
show-name? false

SLButton
turtle-or-observer? turtle
top-left 13 120
width-height 90 30
name "button1"
line-to-run "go"
forever? true
button-number 1
show-name? false
whichip 7

SLButton
turtle-or-observer? observer
top-left 13 15
width-height 90 30
name "button2"
line-to-run "setup"
forever? false
button-number 3
show-name? false
whichip 8


`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 380
interface-window-ycor 166
interface-window-size 643 425
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 117
info-window-ycor 310
info-window-width 500
info-window-height 419
control-center-xcor 71
control-center-ycor 264
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`
H4sIAAAAAAAAAE2OUQqAMAxD09bhj+CZvIYn0Pt5NA9gwlJwkGV5DXQAVgAjeCUV
iIvvUOZZ6Dt1ULdZz8Shbk722Jsl/bQ3K7Mi2tyn4vV+deuX1c/OmHP9dSh8EDvR
u7wAAAAAAAC8

`bytecodes`
H4sIAAAAAAAAAHWUbU/CMBCAr937BmNRFl4ikShf/eoHPxjjLwFHM4hEFjZi/I/6
n7yt17Wb2IS2d717ei8dEK3fviqRHbeiXL/Adz1+ACAApxTVucDtDbSD0zTFxcLf
vQvA5BFb4TS1yWZIepzShPYcWIL26ZRki1b0uWKaNwKn1obZQWxOD8Wm2qG06MUw
ATZm+u7ElJmUk1tDx7UuWRDD1nGMbXn/iFMcNsXBgOdHVFzr+z3yUUPFcBVibgM6
d3r2tpYbLodhthPZe50fbkrUP/9BtumM404aMnxPh5/OdCnrcqtUGIXSrK7B8QxO
RDrf4ASS00+1ww1pjQzuwOD6pMOnkM5pH0uub7CaclgQyXKUhRBbPHnUtUjjTp8l
PNTFWYFRHEsXRb0pvEQz7AsMx2C4BsP7h+FfYAQGIzQYUYchk7XB/dzn+UHI817T
5Tcy0/k18px8HZi8nqvq+PG0XMoPJD9tit0+K5sCwJ1quQtRa9i84IAidqitvNdW
t3WMW0f1D6B8OqO2/QWON4SgPgQAAAAABD4=

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

`patch world`
[encoded data, 31395 characters]
ff9/uwnjpZ37BAAABPud

`turtle world`
H4sIAAAAAAAAAKXY+XMTZQDG8bfSg0tAxAuqBqggN3KjlUaEotbSIlehgJsmS5M2
JNvupgUPXAVB7iJyeBJA5fAA5VA5dBX43T8hfwJ/As+2gRnnmdFnxnS+ze40n7xv
902y25ohlpfr9NJ2xPVinm1Fzf3bcVOetjOtXhLb1aaspdO2E9isMgOddNbrTiVa
bQ/7s0xFuO/YGexMNWXxbDrbic1KU7ol3rs12AzqffL7zzbP9MfDE9nujIO9GabM
TcYcG5sTTenmPlNq+nUns73zKHeTxUfONBVJO5ZIZVqxMwKVgDp907p3a0G30S10
E/2F/kQB+gP9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