CS21 Lab 4: Graphics

Due 11:59pm Tuesday, 28 September

Run update21, if you haven't already, to create cs21/labs/04. Then cd into your cs21/labs/04 directory and edit the python programs for lab 4 in this directory (handin21 looks for your lab 4 assignments in your cs21/labs/04 directory):

$ update21
$ cd
$ cd cs21/labs/04
$ pwd

Your programs are graded on both correctness and style. Please review the comments regarding programming style on the main page.

1. Draw a Jack-o'-lantern

Use the Zelle graphics library to draw a Jack-o'-lantern for Halloween!

Open the file pumpkin.py and create a program that draws a Jack-o'-lantern using the graphics library. Here are some guidelines to follow:

Be creative! Two examples are shown below (the second example includes images from an animation).

2. Draw a stack of bricks

Use the Zelle graphics library to draw a vertical stack of bricks (Rectangles!).

Open the file stack.py and create a program that draws a stack of 10 rectangles or "bricks". We will use mouse clicks to determine the top, bottom, and width of the stack. If the users clicks very high in the window, then very low, and picks a narrow width, your program will draw a tall stack of thin bricks. If instead the user clicks in the middle of the window, then very close below that, and picks a large width, your program will draw a short stack of fat bricks. Here are some guidelines to follow:

Feel free to choose your own colors and instructions.

3. Draw a pyramid (OPTIONAL!!)

This problem is an optional bonus problem, is not required, and you should not attempt it until you are completely finished with the required lab problems. It is just for fun if you want to write more programs!!

In the file pyramid.py, write a program that draws a pyramid of bricks. Have the user click once for the top of the pyramid and once for the bottom right side, then draw a 10x10 brick pyramid as shown:

Note: your pyramid should scale based on where the user clicks the mouse. If they click very high and then low, you should get a tall pyramid like this:

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.