Fall 2018", 'http://cs.colby.edu/courses/F18/cs151'); ?>

Project 6: Animated Scene

The purpose of this project is to give you experience with both top-down design and efficient coding practices that take advantage of things with similar structures.


The result of this assignment will be similar to project 3. You'll create a scene that is a collection of complex objects. The complex objects will all be collections of Zelle graphics primitives and have the same organization as the spaceship you created in lab. Each complex object will have a function that initializes it and any complex object that changes will have a function that animates it.

The big difference from project 3 is that your scene can be animated, with objects moving or changing colors.

  1. Think about a scene you want to create. Design the scene on paper as a collection of complex objects like buildings, streets, stoplights, and cars. Keep it simple. Come up with at least 2 complex objects of your own that you want to create for your scene. At least one of them will need to animate in some way. Animation can involve motion or changing color.

    For each of the complex objects, create a new init function in complex_shape.py. For the spaceship we created spaceship_init. Follow the same convention for your other complex objects. For a stoplight, for example, create stoplight_init.

    The init function should always take an x, y, and scale, which you should use just as in project 3 so that the object can be placed anywhere at any scale. The init function should return a list of the primitive objects that make up the complex object, just like we did with the spaceship_init function.

    If your complex object should animate, create an animation function for the complex object. Use the same naming scheme, putting a _animate after the object's name. We created spaceship_animate for the spaceship. You would create stoplight_animate for a stoplight.

    You need to animate at least one of your new complex objects, even if it means just changing colors. The animate function should take in at least three parameters: the list of objects in the shape, the frame number, and the window, just like our spaceship_animate function. You can give the animate function any number of other parameters necessary for it to work properly. For example, you may want to include the scale used to create the image, so that movement can scale with the size of the shape.

    For each complex object you create, make a test function in complex_shape.py, just like we did with test_spaceship. The test function should create a window, create multiple versions of the complex object, and then wait for a mouse click to quit. If your animate function does something interesting, test that out as well.

    Include a small picture for each complex object in your writeup.

  2. Make a file scene.py and import your complex_shape package, the graphicsPlus package, and the time package. This file should have at least a main function (you can create other functions as you see fit to organize the code).

    The main function should initialize the complex objects in the scene and draw them. It should then execute a loop and animate the complex objects that change (i.e. the ones with animate functions). It will be similar to the lab6test.py main function from lab. Note that in lab6test.py, we put the spaceship complex objects in a list. You may want to use lists if you have multiple copies of the same object. But if you have one copy of each type of object, then you may want one variable for each object. The important thing is to make your code both succinct and readable.

    Do something creative within this framework.

    Include several pictures of your scene animating in your writeup.

  3. Alternatively, you can create an animated gif to post (this is preferred but not required).

    Note, you can use the time.sleep() function to make your animation slow enough that you can do a screen capture on each frame. If you do that, then you can create an animated gif using the following command in Terminal inside the directory where your screen shots are saved.

    convert -delay 60 *.png myanimation.gif

    The file myanimation.gif will be an animated gif that you can put on a web page.

    In lab6test.py is also another way to save your screen using postscript files. To do that, see the notes at the bottom of this page.

    You can also create movies of your screen using the Quicktime Player application.

Extension Examples

These are just examples, not necessarily recommendations. Please feel welcome and encouraged to design your own. A great extension genuinely interests you, pushes your understanding of CS, and inspires you to learn something new.

Hand-in and Report

  1. Put the python files you wrote on the Courses server in your private directory in a folder named Project6.
  2. Make a new wiki page for your assignment. Put the label cs151f18project6 on the page.

    In general, your report should follow the outline below.

    • Title includes your name and clearly describes the project.
    • Section headings are used to delineate distinct sections of the report.
    • Abstract identifies key lecture concepts (e.g. code structres, data types, and libraries) relevant to the project.
    • Abstract explains why key lecture concepts are important to achieving project goals.
    • Abstract identifies program output(s), giving context to the project tasks.
    • Solutions to tasks are described, focusing on how you used key lecture concepts to solve each task.
    • Required images/outputs are present and clearly labeled.
    • Reflection at the end of the report addresses how the lecture concepts mentioned in the abstract made this project possible. If you can think of a more elegant way to achieve the same results, please share!
    • Sources, imported libraries, and collaborators are cited, or a note is included indicating that none were referenced.
    • Don't forget to label your writeup so that it is easy for others to find. For this project, use cs151f18project6

Making a GIF from PS files

In order to make a GIF from PS files created using the saveFrame function, you need to first convert the PS files to PNGs in a way that removes the alpha channel and sets the background color to white. You can do that using the following python file.


If you have a set of .ps files in your directory, you can run it using the following.

python ps2png.py *.ps

This will create a whole bunch of png files, one for each ps file. Then you can make your animated gif using the command:

convert *.png -delay 30 myanimation.gif

Note that if your files are numbered in such a way that typing ls does not list them in order, then you will need to re-number them. You can do that by creating filenames using the following code.

filename = "frame%03d.ps" % (frame_num)