CS 5010: Problem Set 03: Iterative Design

Out: Monday, September 28, 2015

Due: Monday, October 5, 2015 at 600pm local time

The goal of this problem set is to help you design functions that deal with the Universe model, and to give you practice with the Iterative Design Recipe.

You will also get experience with the Perfect Bounce and Smooth Dragging, which we will be using in many of our exercises.

You must use the HtDP Beginning Student Language to solve the problems.

For these problems, download a copy of extras.rkt and put it in the folder with your solutions. Then import this library by including the line

(require "extras.rkt")
at the top of your file with the other requires. Also, be sure to include extras.rkt in the folder that you submit. Then, for each problem, put in lines that say
(provide function)
for each deliverable function, as you have done on previous problem sets. This will allow our testing framework to import your file and do automated testing on it. You can use check-location, as you did on the preceding problem set, to double-check that your solutions are in the right place.

Remember that you must follow the design recipe. Your deliverables include the data definitions (including interpretation and templates), contract and purpose header, code, and tests. Be sure to follow our coding conventions. This will make the TA's job much easier.

Be sure to sync your work and fill out a Work Session Report at the end of every work session. Use the Work Session Report for PS03.

Note: For all universe programs, you may assume that the mouse is never dragged or moved outside of the canvas. Once the mouse enters the canvas, if the mouse ever leaves the canvas, then the behavior of your system is unspecified.

  1. (screensaver-1). Your boss has assigned you to a project to build a screensaver. The specifications for the screensaver are as follows:

    Here's a demo:

    You are to deliver a file named screensaver-1.rkt that provides the following functions:

    ;; screensaver : PosReal -> WorldState
    ;; GIVEN: the speed of the simulation, in seconds/tick
    ;; EFFECT: runs the simulation, starting with the initial state as
    ;; specified in the problem set.
    ;; RETURNS: the final state of the world
    ;; initial-world : Any -> WorldState
    ;; GIVEN: any value (ignored)
    ;; RETURNS: the initial world specified in the problem set
    ;; world-after-tick : WorldState -> WorldState
    ;; RETURNS: the world state that should follow the given world state
    ;; after a tick.
    ;; world-after-key-event : WorldState KeyEvent -> WorldState
    ;; RETURNS: the WorldState that should follow the given worldstate
    ;; after the given keyevent
    ;; world-rect1 : WorldState -> Rectangle
    ;; world-rect2 : WorldState -> Rectangle
    ;; world-paused? : WorldState -> Boolean
    ;; RETURNS: the specified attribute of the WorldState
    ;; NOTE: if these are part of the world struct, you don't need to
    ;; write any deliverables for these functions.
    ;; new-rectangle : NonNegInt NonNegInt Int Int -> Rectangle
    ;; GIVEN: 2 non-negative integers x and y, and 2 integers vx and vy
    ;; RETURNS: a rectangle centered at (x,y), which will travel with
    ;; velocity (vx, vy).
    ;; rect-x : Rectangle -> NonNegInt
    ;; rect-y : Rectangle -> NonNegInt
    ;; rect-vx : Rectangle -> Int
    ;; rect-vy : Rectangle -> Int
    ;; RETURNS: the coordinates of the center of the rectangle and its
    ;; velocity in the x- and y- directions.
  2. (screensaver-2). Your boss has now decided to build a better screensaver. This one is like the original, except for the following:

    Here's a demo:

    You are to deliver a file named screensaver-2.rkt that provides all the functions above, plus the following:

    ;; world-after-mouse-event
    ;;  : WorldState Int Int MouseEvent -> WorldState
    ;; GIVEN: A World, the x- and y-coordinates of a mouse event, and the
    ;; mouse event
    ;; RETURNS: the world that should follow the given world after the given mouse
    ;; event.
    ;; rect-after-mouse-event :  Rectangle Int Int MouseEvent -> Rectangle
    ;; GIVEN: A rectangle, the x- and y-coordinates of a mouse event, and the
    ;; mouse event
    ;; RETURNS: the rectangle that should follow the given rectangle after
    ;; the given mouse event
    ;; rect-selected? : Rectangle -> Boolean
    ;; RETURNS: true iff the given rectangle is selected.
    ;; new-rectangle
    ;; as before, but now it returns an UNSELECTED rectangle.

Last modified: Wed Oct 7 15:25:42 Eastern Daylight Time 2015 C:\Users\MWand\Dropbox\Work\cs5010\15-2-Fall\public\Problem Sets\03-screensaver-1-demo.swf