Lecture 6: big-bang for interactive animations
This assignment is due on Tuesday, September 10 at 11:59pm. Submit it using Handin as assignment lecture6.
Remember to follow the design recipe whenever you design or write a function. In particular, every type mentioned in a signature must be introduced by a data definition, except for these well-known types: Number, Image, String, Color, Boolean.
Troubleshooting While following along the video above or working on the exercises below, if the Run button brings you the error message “string=?: expects a string as 1st argument, given #<image>”, you probably made a mistake in the next-tl function you designed in Lecture 5: Multiple cases. There you’re supposed to design a function that “returns the next traffic light”, so in step 2 of the design recipe, your signature should say “-> TrafficLight” (or “-> World”, because in this lecture a World is a TrafficLight), not “-> Image”. Then, in step 3 of the design recipe, the expected outputs should be TrafficLights (Worlds), not Images. Review the video above at the 1-minute mark.
Exercise 1. Design a function called reset-to-red that takes a TrafficLight and a KeyEvent as inputs and always returns the TrafficLight "red".
Exercise 2. Change the big-bang in the video above so that the traffic light still changes every 2 seconds but, whenever any key is pressed, the traffic light becomes red immediately.
Optional: Enjoy another example of big-bang. Then, learn how to handle different key events differently and how to handle different mouse events differently.