CS1400 Assignment 3: Virtual Pet Graphics
You should pass each part of this assignment off to a lab assistant before the end of the day on each due date.
In addition, each part must be submitted electronically before 11:55 pm on the due date. Use the assignment submission system discussed in class to submit your homework.
If necessary, your instructor will give you more detailed instructions for passing off and submitting your work.
Learn to use the
Learn to interact with simple objects
Define and use functions
Practice incremental program development and functional decomposition
In this assignment, you will draw 6 virtual dogs, each with a different mood. The six moods are happy, angry, sleepy, bored, hungry and dead. The program window has buttons across the bottom that correspond to each of the moods. When the mouse is clicked in a button, the dog’s picture will change to the corresponding mood. If the quit button is selected, the program will exit.
Your program should make the different pictures reflect the moods of the dog. The pictures will be drawn with the vector graphics primitives available in the pygame module. The use of images is not allowed. If you have questions, discuss them with your instructor.
Before you begin writing code, you should sketch the six pictures you want to draw of the dog in different moods. Keep in mind that you will have lines, rectangles, circles, ellipses, arcs and polygons as your primary drawing primitives. Some students have used Adobe Illustrator, or other drawing programs to create their initial designs. Also keep in mind that your job will be easier, if there are similarities between the different pictures. For example, the shape of the dog’s head will probably be the same in most of the pictures.
Look at these example sketches drawn on graph paper to make it easy to calculate the coordinates. Notice that the sketches re-use several shapes, such as the head, the talking bubble, etc. Think modular decomposition :).
Download the starter kit:
- Python 2.7.x vpet-graphics-starter-kit-2-7.zip
After downloading this file, extract the folder inside.
Run the starter code (open vpet_main.py and run it). You should see a window that looks like the image below. If you click any of the mood buttons, the text in the middle of the screen will change. To exit the program, click on the “Quit” button.
Next, choose one of your images to draw first. For example, you may
choose to draw the happy dog first. This means that you need to add
code to the
drawHappy function. Your sketch may show a dog with
four legs, a tail, a body, and a head with eyes, ears, nose and
Do not write all of the code to draw the entire dog before testing. Choose one feature, write the code for it, then save your changes, and run the program. Remember that you will have to click on the “Happy” button to have your picture drawn. After that feature works correctly, work on another feature. It is highly recommended that you save a backup copy of your program after each major accomplishment. A simple example of a happy dog is shown below. We expect your picture to be of much higher quality than the one shown.
After you have all of the features working correctly for the first
image choose another image. For example, you may now choose the
angry dog. Now you will add code to the
Proceed as you did with the happy dog, one feature at a time, with a
save and test for each one.
As you write the code for the second picture, you will notice that
much of the code is similar to the first picture’s code. Do not just
copy/paste the code from the first picture. Instead, you should
recognize the similar code and create another function that executes
that code. For example, you may create a function called
drawDogBody, that draws the dog’s body, since it will be the same
in most of the pictures. Then you will change your draw mood
functions to call the
You should create functions for all common elements of your pictures, such as head outline, legs, etc. Some of the images may share the same eye features, so make a function for those that share. If you follow this process, you will be able to complete the assignment much more quickly. You will also be practicing good programming principles.
The pygame module is documented on the web. There are many, many examples available as well. If your class did the Ice/Water/Steam example program in class, it will be of use for this assignment as well.
To pass off part one of the assignment, you must show at least two of your dog pictures. You must also show your drawing code, and demonstrate where you have used functions to reuse some of the drawing code.
To pass off part two of the assignment, you must show all six of your dog pictures. You must also show your drawing code, and demonstrate where you have used functions to reuse some of the drawing code.
There are many extensions that can be done with this assignment. Consider the following:
- add backgrounds to the pictures,
- make your functions capable of drawing dogs of different sizes based on parameters,
- make your functions capable of drawing dogs at different locations based on parameters,
- make your functions capable of drawing dogs of different colors based on parameters,
- add animation to your dogs.
Last Updated 03/12/2013