CS 2010 Homework 2   - Due September 3

Setup

hw1-extras.plt
Download and install hw1-extras.plt from HW 1, but only if you haven't already. For HW 2, you do not need hw1-teachpack.ss.
hw2-extras-3.plt
Install these extra primitive operations to be used in the assignment. To install, download hw2-extras.plt, open hw2-extras.plt using DrScheme's Open menu item, and allow DrScheme to install the package.
hw2-teachpack.ss (and clear hw1-teachpack.ss)
Download and select this teachpack for the assignment. To select the teachpack, first use the Clear Teachpacks menu item to clear the HW 1 teachpack. Then use the Add Teachpack... menu item in the Language menu. (Do not use DrScheme's Open menu item for hw2-teachpack.ss.)

The teachpack adds the following primitive operations, in addition to those of HW 1:

image-inside? : image image -> bool
Returns true if the second image appears somewhere in the first, false otherwise.
find-image : image image -> posn
Returns a posn reprsentating the location of the second image within the first. (If the second image does not appear in the first, an error is reported.) The result posn indicates the location of the second image's top-left corner relative to the first image's top left corner. The X part of the posn indicates the number of pixels to the right that the second image's corner is shifted, and the Y part indicates the number of pixels down that the second image's corner is shifted.

See the lecture slides from August 27 for examples.

Assignment

Exercise 2.1, Number Conditionals

HtDP exercise 4.4.2 (page 44)

Exercise 2.2, Symbol Conditionals

HtDP exercise 5.1.2 (page 49)

The teachpack part is optional. If you choose to try it, you can select both hw2-teachpack.ss and guess.ss at the same time, but beware that the handin server will try to execute your code without the guess.ss teachpack.

Exercise 2.3, Posns

Define the function double-posn which takes a posn an returns a posn. The X value of the returned posn should be double the X value of the given posn, and the Y value of the returned posn should be double the Y value of the given posn.

Exercise 2.4, Posns and Offsets

Define the function posn-masked-image+ that is like the offset-masked-image+ operator, except that it takes a posn for the offset instead of two numbers.

The contract for posn-masked-image+ is    image posn image image -> image.

Exercise 2.5, I Was Framed!

Define the function frame-person that we considered in lecture.

Note: if you construct your own image set for testing, see warnings in the FAQ.

The FAQ also contains sample pictures you can use, if you prefer not to create your own.

Exercise 2.6, Checking for Suspects

Define the function frame-person-if-present that is like frame-person, except that the second image provided to the function may not appear in the first image. In that case, the first image should be returned unmodified.


Last update: Wednesday, September 3rd, 2003
mflatt@cs.utah.edu