Due: Friday, March 17, 2017, 11:59 pm

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 (shape groups). The shape groups will all be collections of Zelle graphics primitives and have the same organization as the steam plant you created in lab. Each shape group will have a function that initializes it and any shape group that you want to animate will need 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 shape groups like buildings, streets, stoplights, and cars. Keep it simple. Come up with at least 2 shape groups 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, but cannot involve rotation (sorry, Zelle doesn't allow for it).

    For each of the shape groups, create a new init function in shape_group.py. For the steam plant we created steam_init. Follow the same convention for your other shape groups. 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 shape group, just like we did with the steam_init function.

    If your shape group should animate, create an animation function for the shape group. Use the same naming scheme, putting a _animation_frame after the group's name. We created steam_animation_frame for the steam plant. You would create stoplight_animation_frame for a stoplight.

    You need to animate at least one of your new shape groups, even if it means just changing colors. The animation_frame function should take in at least three parameters: the list of objects in the shape group, the frame number, and the window, just like our steam_animation_frame function. You can give the animation frame 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 shape group you create, make a test function in shape_group.py, just like we did with test_steam. The test function should create a window, create multiple versions of the shape group, 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 shape group in your writeup.

  2. Make a file scene.py and import your shape_group package, the graphics 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 shape groups in the scene and draw them. It should then execute a loop and animate the shape groups that change (i.e. the ones with animation frame functions). It will be similar to the lab6test.py main function from lab. Note that in lab6test.py, we put the steam plant shape groups 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.

    Alternatively, the PS files created in lab6test.py can be converted to PNG files and then used in creating a GIF. See the end of this assignment for instructions on converting PS files to PNG files and creating gifs from them. You can also create movies of your screen using Quicktime.


Write-up and Hand-in

Turn in your code by putting it into your private hand-in directory on the Courses server. All files should be organized in a folder titled "Project 6" and you should include only those files necessary to run the program. We will grade all files turned in, so please do not turn in old, non-working, versions of files.

Make a new wiki page for your assignment. Put the label cs151s17project6 in the label field on the bottom of the page. But give the page a meaningful title (e.g. Ying's Project 6).

In general, your intended audience for your write-up is your peers not in the class. Your goal should be to be able to use it to explain to friends what you accomplished in this project and to give them a sense of how you did it. Follow the outline below.

Making a GIF from PS files

In order to make a GIF from PS files created using the saveFrame function in lab6test.py, 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)

© 2017 Ying Li. Page last modified: .