Homework 1Due Wednesday, October 7 by 3pm.SetupUse 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 -> imagemode 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 -> widthor image-height : image -> heightwhere 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 -> imagewhere 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 -> imageto 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 ... -> imageThis will create an image by overlaying all images on their pinholes. Exercise 1, Surface areaDevelop 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, SumDevelop 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 colorsDefine a function face that accepts an eye color and returns a face with that eye color. For example, (face 'blue) could be Exercise 4, BullseyeDefine 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, BesideWrite 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, StackDevelop 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. |