For all the programming assignments, be sure to follow the design recipe. Write your function contract, examples, and function definition in the Definitions Window, save it to a file, and send me this file. Also test your program: since you've already included examples in the Definitions window, you should be able to hit the Execute button and see all the results (along with what you said they "should be"). Save the resulting Interactions window to a text file and send me this file too. Be sure to choose meaningful names for functions and parameters, and watch for opportunities to re-use functions you (or the textbook) have already written.
Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description).
This assignment is to be done in pairs, just like previous homeworks (but with a different partner).
random
that
produces random numbers. Read about it in the DrScheme
Help Desk. Try some examples in the Interactions window.
Develop a function named random-posn
that
takes in two numbers (max-x and max-y) and returns a
posn whose x coordinate is chosen at random between 0 and max-x,
and whose y coordinate is chosen and random between 0 and max-y.
Note: In your examples, you won't be able to predict
exactly what answer comes out, but you can say something like
"should be a posn with 0 ≤ x < 20 and 0 ≤ y < 50".
add-colored-dot
which takes a posn, a color, and an image, and returns the same image with
a dot of the specified color added at the specified location.add-smart-dot
which
takes a posn and an image, and returns the same image with either a green
dot or a red dot added at the specified position; the dot should be green
if the position is above the main diagonal, and red otherwise. You may
assume that the image is square. add-random-smart-dot
which takes an image and returns the same image with a randomly chosen dot
added to it, either green or red depending on whether it's above the main
diagonal as above. You may assume that the image is square, but you do
not know in advance how large it is.show-world
function is incredibly easy); it starts
with a box, and at each tick of the clock, it updates the world using
add-random-smart-dot
. Turn in not only the
Scheme code you used to run the animation, but also a screen shot
showing the animation after at least twenty or thirty clock ticks.
moving-posn
which
contains a posn and a symbol (either 'right
, 'left
,
'up
, 'down
, or 'not-moving
).
moving-posn
as the world, representing the current position
and direction of motion of a colored dot on the screen.
Every time the clock ticks, the dot moves a few pixels in the current
direction. Every time the user presses an arrow key, the current direction
(but not the location) changes ('left
for the left arrow key,
'up
for the up arrow key, etc.
If the user presses the 'home
key,
the direction should change to 'not-moving
.
Error log: /30
Function name | Contract | Examples | Definition | Test results |
---|---|---|---|---|
random-posn |
/5 | /5 | /10 | /5 |
add-colored-dot |
/5 | /5 | /10 | /5 |
add-smart-dot |
/5 | /5 | /10 | /5 |
add-random-smart-dot |
/5 | /5 | /10 | /5 |
animation | /30 | |||
moving-posn struct |
/10 | /10 | /10 | /10 |
auxiliaries for animation | /10 | /10 | /20 | /10 |
animation | /30 |
Following directions | /20 |
Writing contracts from word problems | /20 |
Choosing examples | /20 |
Choosing names | /20 |
Coding | /20 |
Code re-use and choice of auxiliaries | /20 |