Skip to main content Link Menu Expand (external link) Copy Copied

Shapes: Design Recipe

Here is a data definition for shapes:

;; A Shape is one of:
;; - "circle"
;; - "square"
;; - "triangle"
;; and represents a kind of shape
  1. Complete the data design recipe for shapes. (Some examples and a template.)

  2. Design a function draw-scene which overlays the image of a Shape on blank image. Do you need to follow the Shape template here? How many tests does it need?

  3. Design a function next-shape which consumes a Shape and outputs the “next” shape (any order is fine, so long as next-shape “cycles through” all the shapes.)

At this point, the lab instructors will introduce a new topic.

Shapes: Animations

Switch pair programming roles

  1. Use the draw-scene and next-shape functions in a big-bang animation that cycles through all of the shapes. Ask a member of the course staff for help if you’re stuck on big-bang Using big-bang takes some practice, which is why we’re here!

  2. Is your animation headache-inducingly fast? Slow it down by giving your on-tick clause a number that follows next-shape to slow it down to that rate of seconds per frame (the default is 1/28 seconds per frame).

  3. Wrap your call to big-bang in a main function, which takes a Shape and uses that shape as the initial state. Don’t forget to give it a signature and purpose statement, but you cannot write tests for the main function. Why not?

  4. Launch your animation by calling your main function from the interactions window.

Door Simulator

You are to design a small door-simulator program…

  1. A door can either be open, closed, or locked. Design data to represent the door and a function to draw the door.

  2. The user can open a closed door by pressing the “o” key on their keyboard. You cannot open a locked door, and attempting to open an already open door will do nothing.

  3. The user can close an open door by pressing the “c” key on their keyboard. Attempting to close an already closed (or closed and locked) door will do nothing.

  4. The user can lock a closed door by pressing the “l” key on their keyboard. Attempting to lock an open door or an already locked door will do nothing.

  5. The user can unlock a locked door by pressing the “u” key on their keyboard. Attempting to unlock a closed door that is already unlocked, or an open door, will do nothing.