CS21 Lab 4: graphics...

Due 11:59pm Tuesday, 15 Feb

Run update21, if you haven't already, to create 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
$ 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. Draw a Valentine

Use the Zelle graphics library to draw a Valentine for Valentine's Day!

Open a file called valentine.py and create a program that draws a valentine using the graphics library. Here are some guidelines to follow:

Be creative (not all features can be circles!). One example is shown below.


2. Draw a target

Use the Zelle graphics library to draw a target, where the user clicks the mouse to define the center of the target and the outer edge.

Open a file called target.py and create a program that draws a target, made up of concentric circles of alternating colors. Have the user click once to define the center of the target and once to define the outer edge of the target. Then draw 5 rings of alternating color to make your target.

Note: your target should scale based on where the user clicks the mouse. Also, you should display helpful messages in the graphics window, telling the user when to click and what each click is for (center of target, outer edge, close the program).

Below are some example images. The first image tells the user to click for the center of the target. The second image shows the point where the user clicked and tells the user to click for the edge of the target. The third image shows the resulting target.







Math Help: given two points, the center and the edge of the circle, you can find the radius of the circle using the distance formula. If the center point is p1 and the edge point is p2, here is one way to calculate the radius:


      radius = sqrt( (p1x - p2x)**2 + (p1y - p2y)**2 )

Remember to include from math import * in your program if you want to use the sqrt() function. You will also need the getX() and getY() Point methods to get the x and y coordinates of the p1 and p2 points.

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:



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.