CPS 49s: StarLogo Traffic

Anthony Kang & Betsy McDonald

Steps and Instructions:

The general idea is to click the buttons in order(they are lined up in the correct and logical order)
  1. Click on #1 Setup
  2. Click on #2 to make the cars on the highway move; you can adjust the speed of the cars on the highway with the slider; you can either leave the cars running (since it's a "forever button") or click the button again to stop them.

  3. This is the picture at the very beginning. There is a intersection of a main road and a smaller road. There is also a highway on the left of the picture.

  4. click on #3, the cars on the main(black) road have the green light. Note: while the car is still running, click on #4 to turn the light to yellow.
  5. click on gray-go; the cars on the smaller road now have the right of way. Note: same as the last step, click on the next button while the cars are still going.
  6. click on black-go-2; this is a forever button; you can again adjust the speed of the cars with the slider; click the button again to stop the cars

  7. cars on the black road have the green light; cars on the smaller road stopped at the red light.

  8. click on black-go-3; cars on the black road still have the green light.
  9. click on crash-red-car; the red car pulls out from the driveway in front of the house; click on crash-purple-car; the purple car pulls out from the parking lot but turn into the wrong direction. (Extra Credit!)
  10. click on crash; two cars crash at the middle of the intersection.
  11. click on tow-truck; a tow truck comes from the right side. (Extra Credit!)

  12. the purple car that came out of the parking lot the wrong way crashed into the red car at the middle if the intersection

  13. click on tow-truck-go; the tow truck drives to the scene of the accident.
  14. click on tow-truck-tow; the tow truck removes the damaged cars; the intersection is cleared. this is the picutre at the very end.


Our Code:
    turtle -
;;Anthony Kang & Betsy McDonald

to black-yellow
setc-of 0 black
setc-of 1 yellow
end

to gray-go
setc-of 1 black
setc-of 2 red
setc-of 5 black
setc-of 4 green
cars-go-gray
end

to gray-yellow
setc-of 4 black
setc-of 3 yellow
end

to black-go
setc-of 3 black
setc-of 5 red
setc-of 2 black
setc-of 0 green
cars-go-black
end

turtles-own [speed2]

to black-go-2
setc-of 3 black
setc-of 5 red
setc-of 2 black
setc-of 0 green
if who > 5 and who <= 55 [fd speed2]
if who >= 56 and who <= 95 [fd speed2]
end

to black-go-3
setc-of 3 black
setc-of 5 red
setc-of 2 black
setc-of 0 green
if who > 5 and who <= 55 [fd 606]
if who >= 56 and who <= 95 [fd 606]
if who > 5 and who <= 55 [setcolor 0]
end
 

to cars-go-black
if who > 5 and who <= 55 [fd 1010]
if who >= 56 and who <= 95 [fd 1010]
end

to proper-direction
if who >= 96 and who <= 125 [lt 90]
if who >= 125 and who <= 165 [rt 90]
end

to cars-go-gray
if who >= 96 and who <= 125 [fd 1010]
if who > 125 and who <= 165 [fd 1010]
end

to crash-red-car
if who >= 166 and who <= 175 [seth 270 fd 5]
if who >= 166 and who <= 175 [rt 90 fd 30 lt 90 fd 5 rt 90 fd 20]
end

to reset-red-car
if who >= 166 and who <= 175 [seth 180 fd 50]
if who >= 166 and who <= 175 [lt 90 fd 10]
end

to crash-purple-car
if who >= 176 and who <= 186 [seth 180 fd 4 rt 90]
if who >= 176 and who <= 186 [fd 35 lt 90 fd 40]
end

to reset-purple-car
if who >= 176 and who <= 186 [seth 0 fd 40 rt 90]
if who >= 176 and who <= 186 [fd 35 lt 90 fd 4]
end

turtles-own [speed]

to highway-move
if who >= 187 and who <= 279 [fd speed]
end

to crash
if who = 186 [seth 270 fd 3]
if who = 182 [seth 220 fd 4]
if who = 176 [seth 290 fd 2]
if who = 168 [seth 190 fd 2]
if who = 169 [seth 90 fd 3]
if who = 170 [seth 20 fd 2]
end

to tow-truck
if who >= 96 and who <= 125 [setcolor 7]
if who >= 280 [seth 180 fd 6]
end

to tow-truck-go
if who >= 280 [seth 270 fd 40]
end

to tow-truck-tow
if who >= 280 [seth 270 fd 30]
if who = 186 [die]
if who = 182 [die]
if who = 176 [die]
if who = 168 [die]
if who = 169 [die]
if who = 170 [die]
if who >= 172 and who <= 175 [die]
if who >= 166 and who <= 175 [seth 270 fd 30]
if who >= 176 and who <= 186 [seth 270 fd 30]
end

    observer -
;;Anthony Kang & Betsy McDonald

to setup
setc-of 0 green
setc-of 1 black
setc-of 2 black
setc-of 3 black
setc-of 4 black
setc-of 5 red
end

to cars-black
crt 10
end