CS21 Lab4: Graphics

Due 11:59pm Tuesday night, September 29

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 Madeleine Abromowitz and Edward Kim.
2. Drawing a car with mouse clicks
Open a file drawcar.py and create a program that draws a car into positions in the graphics window determined by the user's mouse clicks as follows:
  1. The first two clicks will indicate the opposite corners of the rectangular body of the car. The first click should be the lower left corner and the second click should be the upper right corner.
  2. The third click will indicate the center of the top edge of a rectangular roof of the car. The roof should have a total width that is one third of the width of the car body. The sides of the roof portion of the car should extend down to the top of the car body.
  3. The fourth click will indicate the center of one circular car wheel, the fifth click will indicate the width (radius) of the wheel.
  4. The sixth click will indicate the center of the other circular car wheel, the seventh click will indicate the width (radius) of the wheel.
Be sure to include a Text box at the bottom 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 car parts (body, roof, and wheels) to be more interesting than mine. They should, however, consist of these basic parts (rectangular body and roof, and two circular tires).

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 car driving out of the screen, an animal or person that moves through the screen, ...

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.