CMSC15100 Autumn 2010: Homework 1

Due Tuesday, October 5 at 10pm.

Setup

This homework requires the use of the image.ss teachpack, so you will need to include the following at the beginning of your program:

(require 2htdp/image)

Note that you should not add the image.ss teachpack using the Language|Add Teachpack... menu, since that will load an older version that has a different interface.

Documentation for the image.ss teachpack is available at use image.ss or from the Help|Help Desk menu (look at the HtDP/2e Teachpacks).

To draw a circle, you can use:

;; circle : radius mode color -> image
where radius is the circle's radius in pixels, mode specifies whether painting a shape fills or outlines the form (e.g., "solid" or "outline"), and color can be "blue", etc.

To create a rectangle:

;; rectangle : width height mode color -> image

To find out some basic properties of images, you can use:

;; image-width : image -> width
or
;; image-height : image -> height
where width and height are the width and the height of the image in pixels.

There are various functions, such as overlay, beside, and above, that you can use to compose images.

Exercise 1, Surface area

Develop a function area that takes a radius of a cylinder and its height as inputs and returns its total surface area (including the endcaps). The constant PI(=3.14) should be defined in the program.

Exercise 2, Simple recursion

Develop a function power that takes a number x and a positive integer n, and returns xn. (You have to use a conditional and a simple recursion as done in class).

Exercise 3, Eye colors

Define a function face that accepts an eye color and returns a face with that eye color.

For example, (face "blue") could return and (face "green") could return

Exercise 4, Bullseye

Define a function, bullseye that accepts two colors and makes a five ring bulls-eye, alternating between those two colors. Use overlay to combine circles.

Exercise 5, Stack

Develop the function

;; stack : image image image -> image

that takes three images and stacks its input images such that the widest one is on the bottom, the narrowest one is on top, and the middle one is in the middle.