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
/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 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:
- Your program should first draw a Jack-o'-lattern in the graphics
window and wait for a mouse click to end the program. Be sure to:
- Use color and several different types of shapes, such as circles,
polygons, and rectangles. Jack-o'-lanterns must at least have eyes,
mouth, stalk, and one other feature.
- For symmetrical features (such as eyes or ears), remember to use
the clone method to make a copy of the original shape. Then
draw the cloned shape in the window and move it to
the desired location.
- Once you are satisfied with your Jack-o'-lattern, add a simple
animation to your program, such as moving a moon, a bat, a witch, or a ghost.
Be sure to:
- Use a Text object to display a message in the graphics window
that instructs the user when to click the mouse.
- If your animation includes multiple objects, put all of the
relevant objects together in a list, and use a for loop over
the list to move each object for the animation.
- Use the sleep function from the time library to
put in brief delays so that your animation is visible to the
user.
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:
- Use a Text object to display instructions to the user about where
to click the mouse, as shown below.
- The first mouse click will define the top of the stack. Display
a Text object containing the string "top" where ever the user
clicks.
- The second mouse click will define the bottom of the
stack. Display a Text object containing the string "bottom"
where ever the user clicks. Here's how your window might look after
the first two mouse clicks:
- The third mouse click will define the left side of the stack.
Display a Text object containing the string "left" where ever
the user clicks:
- The fourth mouse click will define the right side of the stack.
Display a Text object containing the string "right" where
ever the user clicks, and then draw the stack of 10 rectangles to fit
the chosen dimensions:
- The final mouse click will end the program.
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:
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.