CS21 Lab 4: Graphics

Due 11:59pm Friday night, Feb 22

First run update21, if you haven't already, to create the cs21/labs/04 directory. 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.

For this lab we will be using the Zelle graphics library. Please refer back to the documentation if you don't know how an object is constructed or how a method works.

1. flags

Write a program called flag.py that draws either a simplified version of the US flag, the flag of another country, or your own made-up flag.

The requirements for this program are:

Some examples of acceptable flags are:







Some countries with flags that are too simple for this assignment: Japan, France, Austria, Poland.

2. landscape design

Write a program called yardcrashers.py to help Ahmed create backyard landscape designs. All designs will have a pool, trees, and a path through the backyard (add more if you want).

Your program should:

Note: your program does not have to check the user's mouse clicks to make sure they are valid. If the user wants to put a tree in the pool, they can.

yardcrasher movie

3. bouncing off the walls

Write a program called bounce.py that draws and animates a moving circle in the graphics window. When the circle reaches any edge in the window, the circle should "bounce" off of that edge and start moving in the opposite direction.

Initially, draw the circle and tell the user to "click" to start the animation. After the mouse click, start the circle moving in a randomly-chosen direction. Use the sleep() function to make the animation smooth and not too fast. Animate the bouncing circle for at least a few seconds (using a for loop).

4. random-colored squares

Write a program called squares.py that displays a 400x400 window with random-colored squares. Your program should ask the user for the number of squares in each direction. For example, if the user enters 10, the program should generate 10 rows with 10 squares in each row. Your program should also choose a random color for each different square. You may pick any color scheme you want.



Submit
Once you are satisfied with your programs, hand them in by typing handin21 at the unix prompt.

You may run handin21 as many times as you like, and only the most recent submission will be recorded. This is useful if you realize, after handing in some programs, that you'd like to make a few more changes to them.