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.
- Develop a design for a scene
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.
- Design your complex objects
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 report.
- Design your scene
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. Butif 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 report.
Alternatively, you can create an animated gif or a video (this is preferred but not required). The easiest way to capture your animation is to do a screen capture video using the Quicktime Player application.
+ (more detail)
If you want to capture individual frames, 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 below.
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)
- What is your understanding of what an object is (e.g. a gr.Rectangle, gr.Point, or gr.Image)?
- If the variable box holds a gr.Rectangle object, how do you set its fill color?
- If you have a list of graphics objects shapes, how would you loop over the list and move each object 5 in the x direction?
- What is your favorite animated movie?
Extensions are your opportunity to customize your project, learn something else of interest to you, and improve your grade. The following are some suggested extensions, but you are free to choose your own. Be sure to describe any extensions you complete in your report. Include pictures.
- Make additional complex objects beyond the required 2, or animate more objects than the required one.
- Set up a system that creates a scene out of complex objects based on a list that gives the name, location, and scale of each complex object in the scene.
- Make an animation with multiple sequential events that make a coherent story.
- Make the trailer for your favorite movie.
Submit your code
Turn in your code (all files ending with .py) by putting it in a directory in the Courses server. On the Courses server, you should have access to a directory called CS151, and within that, a directory with your user name. Within this directory is a directory named private. Files that you put into that private directory you can edit, read, and write, and the professor can edit, read, and write, but no one else. To hand in your code and other materials, create a new directory, such as project1, and then copy your code into the project directory for that week. Please submit only code that you want to be graded.
When submitting your code, double check the following.
- Is your name at the top of each code file?
- Does every function have a comment or docstring specifying what it does?
- Is your handin project directory inside your Private folder on Courses?
Write Your Project Report
If you haven't already made a new page for this report on the wiki, then make one now (Log into the wiki, goto your Personal space by selecting "Personal Space" on the menu under the Person icon, then make the page using the "Create" button. Put the label
cs151f19project6 in the label field on the bottom of the page. But give the page a meaningful title.
Your intended audience for your report is your peers not in the class. From week to week you can assume your audience has read your prior reports. 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.
Your project report should contain the following elements.
A brief summary of the project, in your own words. This should be no more than a few sentences. Give the reader context and identify the key purpose of the assignment.
Writing an effective abstract is an important skill. Consider the following questions while writing it.
- Does it describe the CS concepts of the project (e.g. writing well-organized and efficient code)?
- Does it describe the specific project application?
- Does it describe your the solution or how it was developed (e.g. what code did you write/circuits did you build)?
- Does it describe the results or outputs (e.g. did your code work as expected)?
- Is it concise?
- Are all of the terms well-defined?
- Does it read logically and in the proper order?
- A description of your solution to the tasks, including images you created (including the required images or videos mentioned above). This should be a description of the form and functionality of your final code. Note any unique computational solutions you developed or any insights you gained from your code's output.
- A description of any extensions you undertook, including text output or images demonstrating those extensions. If you added any modules, functions, or other design components, note their structure and the algorithms you used.
- The answers to any follow-up questions (there will be 3-4 for each project).
- A brief description (1-3 sentences) of what you learned. Think about the answer to this question in terms of the stated purpose of the project. What are some specific things you had to learn or discover in order to complete the project?
- A list of people you worked with, including TAs and professors. Include in that list anyone whose code you may have seen, such as those of friends who have taken the course in a previous semester.
- Put the label cs151f19project6 on your wiki page.