CS 5010: Problem Set 03: Iterative Design

Out: Monday, February 1, 2016

Due: Monday, February 8, 2016 at 5pm EST

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). The physics marketing department at a nearby university has not yet found a money-making application for the Perpetual Goofball, but they hope to attract more interest by using a screensaver to demonstrate its behavior. Your job is to build that screensaver, which is specified as follows:

    Here's a crude demo showing the screensaver's behavior at the southeastern corner:

    demo for problem 1

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

    ;;; screensaver : PosReal -> WorldState
    ;;; GIVEN: the speed of the screensaver, in seconds per tick
    ;;;     (so larger numbers run slower)
    ;;; EFFECT: runs the screensaver, starting with the initial state as
    ;;;     specified in the problem set
    ;;; RETURNS: the final state of the world
    ;;; EXAMPLES:
    ;;;     (screensaver 1) runs the screensaver at normal speed
    ;;;     (screensaver 1/4) runs at a faster than normal speed
    ;;; initial-world : Any -> WorldState
    ;;; GIVEN: any value (ignored)
    ;;; RETURNS: the initial world specified for the screensaver
    ;;; EXAMPLE: (initial-world -174)
    ;;; world-after-tick : WorldState -> WorldState
    ;;; GIVEN: any WorldState that's possible for the screensaver
    ;;; RETURNS: the WorldState that should follow the given WorldState
    ;;;     after a tick
    ;;; world-after-key-event : WorldState KeyEvent -> WorldState
    ;;; GIVEN: a WorldState and a KeyEvent
    ;;; RETURNS: the WorldState that should follow the given WorldState
    ;;;     after the given KeyEvent
    ;;; world-goofball1 : WorldState -> Goofball
    ;;; GIVEN: a WorldState
    ;;; RETURNS: the Goofball (as specified in Problem Set 02)
    ;;;     that's present in the WorldState
    ;;; world-paused? : WorldState -> Boolean
    ;;; GIVEN: a WorldState
    ;;; RETURNS: true iff the WorldState is paused
    ;;; goofball-at : Integer Integer Integer Integer -> Goofball
    ;;; goofball-radius : Goofball -> Integer
    ;;; goofball-x : Goofball -> Integer
    ;;; goofball-y : Goofball -> Integer
    ;;; goofball-vx : Goofball -> Integer
    ;;; goofball-vy : Goofball -> Integer
    ;;; The six functions named above behave as specified in problem 3
    ;;; of Problem Set 02, except the vx and vy components of velocity
    ;;; are interpreted as cm per tick instead of cm per second.
  2. (screensaver-2). The physics marketing department is afraid that first screensaver might be too boring, so they want you to build a second screensaver that's just like the first screensaver except it adds these new features:

    Here's a demonstration of smooth dragging in which the decreasing radius of both dragged goofballs eventually causes the dragging mouse to lie outside a goofball's circle, which allows the goofball to escape the dragging mouse and assume its undragged (red) appearance and behavior:

    demo of smooth dragging

    You are to deliver a file named screensaver-2.rkt that provides all the functions provided for problem 1 above, modified to behave as specified in this problem 2. (That means you'll probably have to change your definitions of initial-world, world-after-tick, and world-after-key-event.) The goofball-at function should behave as before, but return an unselected Goofball.

    You must also define and provide the following new functions:

    ;;; world-goofball2 : WorldState -> Goofball
    ;;; GIVEN: a WorldState
    ;;; RETURNS: the second Goofball that's present in the WorldState
    ;;; 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.
    ;;; goofball-selected? : Goofball -> Boolean
    ;;; RETURNS: true iff the given Goofball is selected.

Last modified: Sun Feb 07 2016