Run update21, if you haven't already, to create the
cs21/labs/04. Then cd into your cs21/labs/04
directory and create the python programs for lab 4 in this directory
(handin21 looks for your lab 4 assignments in your cs21/labs/04 directory):
$ cd cs21/labs/04
Your programs are graded on both correctness and style. Please review
the comments regarding programming style on the main page.
1. Drawing a face
Open a file drawFace.py and create a program that draws a
face using the graphics library. Here are some guidelines to
Your program should keep the drawn face on the graphics window until
the user clicks the mouse. Then the graphics window should close and
your program should end.
Use color and several different types of shapes.
For symmetrical features (such as eyes or ears), remember to use the
clone method to make a copy of the original shape. Then
draw the cloned shape in the window and move it to
the desired location.
You may want to use the setCoords method of the
GraphWin object to adjust the coordinates of the window. You
can read about this method on page 152 of the textbook.
Be creative! For inspiration, here are two example faces from previous
cs21 students Madeleine Abromowitz and Jonathan Stafstrom.
2. Drawing a house with mouse clicks
Open a file drawHouse.py
and create a program that draws a
house with 5 mouse clicks as follows:
The first two clicks will indicate the opposite corners of the
rectangular frame of the house. The first click should be the lower
left corner and the second click should be the upper right corner.
The third click will indicate the center of the top edge of a
rectangular door. The door should have a total width that is one
fifth of the width of the house frame. The sides of the door should
extend down to the bottom of the house frame.
The fourth click will indicate the center of a square window.
The window should be half as wide as the door.
The fifth click will indicate the peak of the roof. The edges of the
roof will extend from the point at the peak to the corners of the top
edge of the house frame.
Be sure to include a Text
box at the bottom of the graphics
window where you can explain each step to the user of your program.
Below is an example of the output that might be produced by this
program. Feel free to choose your own color scheme.
Once you have completed the above requirements, add one of the
following animated features to the scene: a cloud that drifts across
the sky, a sun that rises or sets, or an animal or person that moves.
Once you are satisfied with your programs, hand them in by typing
handin21 in a terminal window.