Project 5: 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 an animated version of project 4. The complex objects will all be collections of Zelle graphics primitives and have the same organization as the saucer 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 4 is that your scene should be animated, with objects moving or changing colors.
- Develop two new complex objects
Design two new complex objects for this week. While they don't have to be the objects you animate, think about how you might animate them as part of the design process. Add the objects to your complex_objects.py file from the last project. In comments, identify them as new objects for project 5.
Include a picture of the two new complex objects, where each object is drawn at least twice in a different location and scale.
- Develop a design for your animation
Think about the animated scene you want to create. You can use the scene that you created in project 4 or a new scene.
Choose at least two complex objects to animate. Animation can involve motion, changing color, or any other visible change you want to make.
Create a timeline for your scene that highlights important frames where things change. Think about how you will identify or define those moments in code.
Include some type of design document in your report showing your animation timeline.
- Design your complex objects' animation
Create an animation function for each complex objects that will move or change in your scene (at least 2). Use the same naming scheme of putting _animate after the object's name. For example, we created saucer_animate for the saucer. You would create stoplight_animate for a stoplight.
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 saucer_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.
The animate functions should not include their own loops over time or use the time.sleep() function. The animate functions should execute only the action necessary at the given frame.
For each animated complex object you create, make a test function. The test function should create a window, create the complex object, then loop for some number of steps, calling the object's animate function inside the loop, just like we did for the saucer.
Capture and submit a short video of each of the complex objects animating. You can submit them with your code on Courses. Quicktime Player has a feature that allows you to do a screen capture of all or part of your screen and save it as a movie.
- 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 lab5test.py main function from lab. Note that in the lab, we put the saucer 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 a video or several pictures of your scene animating in your report. You can create 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 role does the time module play in this project?
- What method of a graphics objects returns the coordinates of the middle of the object?
- 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? Please show code.
- What is your favorite animated movie or TV show?
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 two.
- 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.
- Make use of command-line arguments to control some aspect of your scene or animation.
Submit your code
Turn in your code (all files ending with .py) by putting it the appropriate 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. Within that is a directory for each week's project where you should submit your code. 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?
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. Please use the CS 151 template. Put the label
cs151s20project5 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. Please include a header for each section.
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. Each assignment will have both a core CS purpose--such as using loops and conditionals--and an application such as making images in the style of an artist.
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 (e.g. making images)?
- Does it describe your the solution or how it was developed (e.g. what code did you write)?
- 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?
For each task, If you completed the task, include an image of the completed task and write a few sentences describing the image/what you did. 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.
If you didn't complete the task insert an image showing how far you got. Write a few sentences describing how much you completed, where you got stuck and what what solutions you tried.
You may want to incorporate code snippets in your description to point out relevant features. Code snippets should be small segments of code--usually less than a whole function--that demonstrate a particular concept. If you find yourself including more than 5-10 lines of code, it's probably not a snippet.
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.
- Follow-up Questions
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.
A list of any resources that you used. This includes textbooks, lecture notes, python documentation, library documentation or forums. If you used a specific website, please link to it.
- Put the label cs151s20project5 on your wiki page.