| Due date: 9/24 @ 6pm
The goal of this problem set is to practice designing data representations
using structures and functions for processing such forms of
data. Furthermore, you must follow the design recipe and the guidelines
when you develop functions.
HtDP Problems
6.3.1, 6.4.1, 6.5.1
Problem A1
Here is a data definition for keeping track of time on a clock (which we
know is a computer with a display attached to it):
(define-struct time (hours minutes))
;; Time = (make-time Number Number)
;; Constraints:
;; The first number is always between 0 and 11;
;; the second number is always between 0 and 59.
Use these definitions for the following exercises:
-
Design the function
tock from Time to Time .
It adds one minute to the given time.
-
Design the function time->text, which converts a time to a
text. The text should look like the display of a common alarm clock,
i.e., it should separate the minutes from the hours with a colon. Hint: a
text is an image, not a string, but you will need a string
version of the time, too. See HelpDesk (image.ss) for text.
- Optional: After you have developed these functions, you may wish to add the
following lines to your program:
(big-bang 100 30 .1 (make-time 0 0))
(on-tick-event tock)
(on-redraw time->text)
If you do, be sure to delete them before you turn in
your solution. We will subtract points if you leave them in.
Problem A2
You've found a summer job with the pyschology department.
They'd like you to develop a program that helps people
control the movement of a ball across the screen. (They
wish to study brain models and reaction times and this is
just a small part of it.)
The ball can move on straight lines only, that is, up, down, left, or
right. Mouse clicks change the ball's location.
-
Develop a data representation for the current position
of the ball. The position is best described with a pair of
positive integers.
-
Develop a data representation for velocity of the ball.
You may assume that the ball always moves exactly 10 pixels
at a time but remember that velocity also includes the
direction of the movement.
-
Develop a data representation for the ball.
-
Design the function
ball-next , which consumes (the
representation of) a ball and create a ball that represents where it
will be after one "tick." (Hint: If a car is 100 miles from Boston's
center and travels at 60 mph in the exact direction of this point, how
close will it be after 1 hour of traveling? Now generalize this to a ball.)
-
Design the function
ball-image , which consumes
(the representation of) a ball and produces a rectangle of 300 x 300
pixels with a red dot (diameter 10 pixels) placed at the ball's
position.
-
Design a function
ball-change , which consumes a ball,
two numbers (x and y), and a symbol (s). If s is 'button-down, the function
creates a ball that moves in the direction of (x,y); otherwise, the function
returns the given ball.
- Optional: After you have developed these functions, you may wish to add the
following lines to your program:
(big-bang 300 300 (/ 1.0 28)
a-ball-inside-the-rectangle)
(on-tick-event ball-next)
(on-redraw ball-image)
(on-mouse-event ball-change)
If you do, be sure to delete them before you turn in
your solution. We will subtract points if you leave them in.
|