Homework 1

Due Wednesday, October 7 by 3pm.

Setup

Use Language|Add Teachpack... and choose world.ss.

The following is a list of functions you might find useful for this homework assignment. Search in Help Desk for image.ss and world.ss or use image.ss and world.ss to find a complete list of the available functions.

To draw a circle, you can use:

circle : radius mode color -> image
mode specifies whether painting a shape fills or outlines the form. (e.g. 'solid or 'outline)
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.

Each image comes with a pinhole. For most images the pinhole is at the center of the shape. For a more detailed explanation consult image.ss. To move the pinhole you can use:

move-pinhole : image delta-x delta-y -> image
where delta-x and delta-y specify the position of the pinhole of the new image with respect to the position of the pinhole in the current image.
Alternatively, you can use
put-pinhole : image x y -> image
to put the pinhole in the location specified by x and y.

To combine images into a new image, you can use:

overlay : image image image ... -> image
This will create an image by overlaying all images on their pinholes.

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. The constant PI(=3.14) should be defined in the program.

Exercise 2, Sum

Develop a function sum that takes a positive integer n and returns the sum 12 + 22 + ... + n2. (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 be and (face 'green) could be

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, Beside

Write a helper function beside that takes two images and returns an image containing the two input images, one beside the other. Hint: think about the pinholes in the images -- and remember, they are not always in the center.

Use beside to build a dumbell using these two examples:

(beside 
 (circle 40 'solid 'black)
 (beside
  (rectangle 100 30 'solid 'black)
  (circle 40 'solid 'black)))
and
(beside
 (beside
  (circle 40 'solid 'black)
  (rectangle 100 30 'solid 'black))
 (circle 40 'solid 'black))

Exercise 6, Stack

Develop the function stack : image image image -> image. It overlays its input images such that the with the largest one is on the bottom, the smallest one is on top, and the middle one is in the middle.