8.12

Lecture 7: big-bang for interactive animations🔗

This assignment is due on Sunday, January 28 at 11:59pm. Submit it using Handin as assignment lecture7.

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.

The code written in the video above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

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 6: 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.

The diagrams below illustrate how you are supposed to enrich the animation in this exercise. In the first diagram, each arrow represents an example for how the handlers [to-draw draw-tl] and [on-tick next-tl] should behave. In the second diagram, the three additional (orange) arrows represent examples for how your new [on-key reset-to-red] handler should behave.

Optional: Enjoy another example of big-bang. Then, learn how to handle different key events differently and how to handle different mouse events differently.