CS21 Lab4: Graphics

Due 11:59pm Tuesday night, February 16

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):


$ update21
$ cd cs21/labs/04
$ pwd
  /home/your_user_name/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 follow:

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 a file drawBoat.py and create a program that draws a sailboat into positions in the graphics window determined by the user's mouse clicks as follows:

  1. You should start with a blue rectangle at the bottom to represent water.
  2. 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.
  3. 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 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.
  4. The fourth click will indicate the center of the sailors head, and the fifth click will indicate the width (radius) of the her head. You may also want to draw in a body for the sailor. Be creative.
  5. The sixth click should start some sort of animation. (See below for details.)
Be sure to include a Text box at the top of the graphics window to explain each step to the user of your program so that s/he knows what the next mouse click means.

Below is an example of the output that might be produced by this program. Feel free to choose your own color scheme and to make your boat parts (hull, mast, sailor) to be more interesting than mine. They should, however, consist of these basic parts: water, hull, mast, sail, sailor, text.

As you solve this problem, keep in mind that the point of the mouse click is not always an (x,y) coordinate that you can directly use to create the object. For example, you may need to shift the (x,y) coordinate values by some amount or you may need to use the distance formula to find the distance between two (x,y) coordinate values.

Once you have completed the above requirements, add an animated feature to the scene. Some ideas could be a cloud that drifts across the screen, the boat sailing out of the screen, a fish swimming in the water, ...

Here are window dumps from parts of a run of my solution:

Submit

Once you are satisfied with your programs, hand them in by typing handin21 in a terminal window.