On this page:
1 Your mission
2 The wishlist method
3 Limited
8.5

Lecture 11: More points

This assignment is due on Sunday, February 13 at 11:59pm. Submit it using Handin as assignment lecture11.

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, KeyEvent, MouseEvent, Anything.

1 Your mission

Have you finished Lecture 10: Unions of structures first? You should.

;; A EvenMorePoints is one of
;; - (make-none)
;; - (make-one Point)
;; - (make-two Point Point)
;; - (make-three Point Point Point)
(define-struct none ())
(define-struct one (first))
(define-struct two (first second))
(define-struct three (first second third))
 
;; A Point is (make-point Number Number)
(define-struct point [x y])

Exercise 1. Write the template for processing a EvenMorePoints. Make it look like a function called process-evenmorepoints, and do not put it in a comment.

2 The wishlist method

Exercise 2. Design a function draw-evenmorepoints, which takes a EvenMorePoints as input and draws it as an image.

Exercise 3. Optional: Design a function move-evenmorepoints-up, which takes a EvenMorePoints and produces another EvenMorePoints where all the Y coordinates are decreased by 1. Then, build a big-bang animation using draw-evenmorepoints and move-evenmorepoints.

3 Limited

Exercise 4. Design a function add-to-evenmorepoints, which takes a Point and a EvenMorePoints, and adds the given Point to the given EvenMorePoints to produce a new EvenMorePoints. The given Point should be the first of the produced EvenMorePoints. Because a EvenMorePoints is limited to storing 3 Points, any old third Point will have to be dropped.

Exercise 5.
;; A World is a EvenMorePoints
Design a MouseEvent handler called mouse using add-to-evenmorepoints. Then, build a big-bang animation using draw-evenmorepoints and mouse.

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.