CS 2010 Homework 1   - Due August 26

This homework is due August 26, 11:59 PM. Handin all programs at once.

Setup

hw1-extras.plt
Install these extra primitive operations to be used in the assignment. To install, download hw1-extras.plt, open hw1-extras.plt using DrScheme's Open menu item, and allow DrScheme to install the package.
hw1-teachpack.ss
Download and select this teachpack for the assignment. To select the teachpack, use the Add Teachpack... menu item in the Language menu. (Do not use DrScheme's Open menu item for hw1-teachpack.ss.)

The teachpack adds the following primitive operations:

image=?    contract is   image image -> bool
Takes two images and returns true if the images are the same, false otherwise.
image-width    contract is   image -> num
Takes an image and returns its width in pixels.
image-height    contract is   image -> num
Takes an image and returns its height in pixels.
image+    contract is   image image -> image
Takes two images image and produces an image where the second is placed on the first. The top-left of the result image corresponds to the top-left of the given images.
offset-image+    contract is   image num num image -> image
Like image+, but with two number arguments inserted between the image arguments. The first number is the number of pixels right to shift the second image, and the secnd number is the number of pixels down to shift the second image.
offset-masked-image+    contract is   image num num image image -> image
Like offset-image+, but with an extra image argument inserted before the last argument. This image must be the same size as the last image, and pixels are copied from the last image to the result only where the extra image has non-white pixels.
solid-box    contract is   num num symbol -> image  [Not needed for HW 1]
Takes two numbers and a symbol and produces an image. The first number determines the width of the result image and the second number determines the height. The symbol determines the color that fills the entire result image. See also the list of available colors.
outline-box    contract is   num num symbol -> image  [Not needed for HW 1]
Like solid-box, except that only the border of the image uses the specified color, and the rest of the image is white.
solid-dot    contract is   num num symbol -> image  [Not needed for HW 1]
Like solid-box, except that only a circle bounded by the image is filled with the specified color, and the corners of the image are white.
outline-dot    contract is   num num symbol -> image  [Not needed for HW 1]
Like solid-dot, except that only the circle edge bounded by the image is draw with the specified color, and the rest of the image is white.

See the lecture slides from August 20 for examples.

Assignment

Exercise 1.1, Warm-Up

HtDP exercise 2.2.5 (page 11) (in the textbook) . Name the first program g, the second h, and the third w.

Exercise 1.2, Numbers

HtDP exercise 2.3.1 (page 12).

Exercise 1.3, You

Define the constant me to be a 128x128-pixel image of yourself.

If you cannot obtain a picture of yourself in electronic form, find or create any 128x128-pixel image. We ask for a picture of you to help us learn your name and match it with a face.

For best results with the following exercises, choose your image so that your eyes are centered in the image, and with the distance from the centers of your eyes at about 64 pixels.

Exercise 1.4, Disguises

Define the function add-glasses that takes two images: a 128x128-pixel person image, and an image (of any size) reprsenting glasses. The result should be an image with the given person wearing the glasses, which is constructed by centering the glasses image on top of the person image, and using the glasses image as its own mask.

Here are some glasses images that you can use for testing:

Example:

Exercise 1.5, More Disguises

Define the function add-beard that is like add-glasses, but the second image is a beard image. The beard should be centered horizontally, but bottom-aligned with the person image.

Here is a beard image that you can use for testing:

Exercise 1.6, Recogniztion

Define the function wearing-glasses? that takes two person images and a glasses image. It returns true or false. The result is true if the second image matches the first image plus glasses (so the result is true only when the second image already includes glasses).

Exercise 1.7, Disguises

Define the function same-person-maybe-disguised? that takes four images: a source person image, a target person image, a glasses image, and a beard image. It returns true or false. The result is true if the second image is that same as the first, possibily with glasses and/or beard added.

Hint: for the last problem, write an additional function that is can be used to define same-person-maybe-disguised?.

Example:


Last update: Wednesday, August 27th, 2003
mflatt@cs.utah.edu