Run update21 to get the starting point files for this
week's lab, which will appear in cs21/labs/04. The program
handin21 will only submit files from this directory.
1. Drawing a face
Open the file drawFace.py and create a program that draws a
face using the graphics library. Here are some guidelines to
follow:
-
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: Hello Kitty by Angela Meng and Charles Darwin by Elliot
Padgett.
2. Drawing a Sailboat with mouse clicks
Open the file drawBoat.py and create a program that draws
a sailboat in the graphics window. You should start with a blue
rectangle at the bottom to represent the water. The location and size
of the sailboat will be based on the user's mouse clicks as follows:
- The first two clicks will indicate the opposite corners
of the rectangular body of the boat (called the hull). 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 top of the mast for the
boat. The mast is the pole that holds up the sail. You should draw a
narrow rectangle for the mast and a triangle for the sail. The three
corners of the sail should be (a) the top of the mast, (b) the back of
the boat just above the hull, (c) and the bottom of the mast just
above the hull. See example images below.
- The fourth click will indicate the center of the
sailor's head, and the fifth click will indicate the radius of her
head. You should also draw in a body for the sailor.
- The sixth click should start some sort of animation, such as
a cloud that moves across the sky or a fish that swims through the
water.
Be sure to include a Text box at the top of the graphics
window to explain each step to users of your program so that they
know what each mouse click means.
Below are some examples of the output that might be produced by
this program. Feel free to choose your own color scheme and to add
more detail to the scene. Just be sure that your picture includes all
of the required parts: text description, water, hull, mast, sail,
sailor, and animation.
Submit
Once you are satisfied with your programs, hand them in by typing
handin21 in a terminal window.