PSU CS199 — Introduction to Computer Science

Homework 1: Have a Nice Day!

Due 27 July 2009

Language Level: Beginning Student
Teachpacks: image.ss

This homework will give you practice writing and composing functions in the Scheme language and working in the DrScheme programming environment. Furthermore, you will gain experience with DrScheme's image.ss teachpack, which provides a collection of functional utilities for building images. Homworks are due before class on Monday mornings: email your Scheme files (as saved from DrScheme) to CS199Homework. You must hand in your work before that time to receive credit, as solutions will be discussed in class.

Preliminaries

Start DrScheme.

Set the language level to Beginning Student.

Add the image.ss teachpack.

The image.ss teachpack provides functions such as rectangle, circle, ellipse, etc. You can put images on top of one another by using overlay and overlay/xy. You can find documentation on the available functions by searching DrScheme's help system for "image.ss". We suggest you find the image.ss documentation and leave it open on your screen while you are working on the hoemwork.

On colors: DrScheme understands HTML's named colors, a huge assortment including darksalmon, papayawhip and blanchedalmond. These (often whimsical) color names can be freely used, as symbols, with image.ss, as in

    (circle 100 'solid 'dodgerblue)

Google "HTML named colors" for a list of available colors and experiment with what you find.


Part 1

Write the function

;; face: num -> image

to produce an image similar to the following:
The number consumed by the function face is the radius of the image produced.

Be careful and attempt to match the proportions of the example closely. Your face need not match the face above exactly, but the main part of the face must be a circle and the eyes must be ellipses.

No matter what radius is given, the image of the face should never be distorted; that is, its proportions must remain true at any size. Note how all three of the following faces are similarly proportioned:

These faces are the results of applying face to 40, 80, and 120 respectively.

Part 2

Cheer up!

Write a second function

;; happy-face: num -> image

and leave the original face function intact.

A hint: in my creation of the smile, I used the image.ss function shrink-bl, which crops in image from the bottom-left

Make sure that happy-face, like face, scales correctly.


How to hand in your work.

Save your file from DrScheme, attach it to an email message. Put the names of both partners in the body of the email. Submit your email to CS199Homework

Acknowledgements

This homework is based on a lab used in the University of Chicago's CS105 Class, originally designed by Adam Shaw.