CS21 Lab 4: Graphics

Due 11:59pm Tuesday night, September 27

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 (we are not giving you starter files this time). And remember, handin21 looks for your lab 4 assignments in that cs21/labs/04 directory!

$ update21
$ cd cs21/labs/04
$ vim grid.py

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

1. Grid

Write a program called grid.py that asks the user to specify a line spacing, and then draws (using the Zelle graphics library ) a grid of horizontal and vertical lines with that spacing in a graphics window with dimensions 500x500.

Below are some screenshots from such a program.

$ python grid.py

   This program draws a grid of lines on the graphics
   window. Please enter the spacing you want below.
        
grid spacing: 100
$ python grid.py

   This program draws a grid of lines on the graphics
   window. Please enter the spacing you want below.
        
grid spacing: 25
$ python grid.py

   This program draws a grid of lines on the graphics
   window. Please enter the spacing you want below.
        
grid spacing: 78


2. Draw a snowman

Winter is coming! :) Use the Zelle graphics library to draw a snowman.

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

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


3. Soccer Field

Write a program called soccer.py that draws a soccer field, based on mouse clicks from the user. Have the user click once for the left side of the field and once for the right side. Then draw a soccer field to scale. Also have the user click a few times to place some player positions (x's and o's) on the field (see images below).

Hints and tips:

Here are some screenshots from our soccer.py program.



Extra Challenges...

Note: Extra Challenge Problems are not a part of the graded lab assignment, and are not required. Please do not attempt these problems until you have completed the required parts of this lab. Feel free to hand them in, but again, they are not graded.

For the grid program, write another program (subgrid.py) that divides each grid box into a 4x4 subgrid, using thinner lines and color. Also, allow for different x and y grid spacings.

For the soccer program, include all field markings.

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.