Lecture 6: Multiple cases
This assignment is due on Tuesday, September 6 at 11:59pm. Submit it using Handin as assignment lecture6.
1 Booleans and conditionals
; Exercise 1 (cond [(< 100 32) "solid"] [(<= 32 100 212) "liquid"] [(> 100 212) "gas"]) ; = ??? ; = ... ; = "liquid" (cond [(< -40 32) "solid"] [(<= 32 -40 212) "liquid"] [(> -40 212) "gas"]) ; = ??? ; = ... (cond [(< 450 32) "solid"] [(<= 32 450 212) "liquid"] [(> 450 212) "gas"]) ; = ??? ; = ...
Optional: Learn about more features of the Stepper.
The code written in the videos 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.
2 Intervals
Exercise 3. Let’s design an animation of a rocket landing. This animation should have two parts: first, the rocket falls from the sky; second, the rocket stops at ground level and stays there.
So, design a function called land-rocket that takes a time t as input and returns a scene that contains a rocket. The scene should be an image that is 200 tall. Horizontally, the rocket should be centered in the scene. Vertically, the distance between the rocket and the top of the scene should be t. But if t is greater than 200, then the rocket should have landed so it should be at the bottom of the scene.
Hint: to begin with the design recipe, write a new data definition for what a Time is.
3 Enumerations
Exercise 4. Design a function called next-tl that takes a traffic light as input and returns the next traffic light. Hint: you can reuse the data definition and template written in the video above.
; A MouseEvent is one of: ; - "button-down" ; - "button-up" ; - "move" ; - "drag" ; - "enter" ; - "leave"
Hint: The data definition for a MouseEvent is an enumeration. Review how to write a template for an enumeration by watching this additional video.
Optional: Read Chapter 4 of the textbook.