Shapes: Design Recipe
Here is a data definition for shapes:
;; A Shape is one of:
;; - "circle"
;; - "square"
;; - "triangle"
;; and represents a kind of shape
-
Complete the data design recipe for shapes. (Some examples and a template.)
-
Design a function
draw-scene
which overlays the image of aShape
on blank image. Do you need to follow the Shape template here? How many tests does it need? -
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
-
Use the
draw-scene
andnext-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 onbig-bang
Using big-bang takes some practice, which is why we’re here! -
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). -
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?
-
Launch your animation by calling your main function from the interactions window.
Door Simulator
You are to design a small door-simulator program…
-
A door can either be open, closed, or locked. Design data to represent the door and a function to draw the door.
-
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.
-
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.
-
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.
-
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.