CS151 – Project 03
The goals of this project are to use loops and conditional statements to make the algorithmic flow of your program more dynamic. You’ll use loops to improve the efficiency, organization, and adaptability of your shape library. You’ll use conditional statements to help functions change their behaviors based on the values of their parameters and to give your program the ability to adapt to user input. Then you’ll use loops to design your own animation.
Now let’s extend the principles that you applied to your block code to the rest of the shapes in your library!
Make sure your aggregate shapes still work with your new and improved basic shapes! For instance, they now need to pass fill parameters.
Write a testShapes() function that draws each of your updated shapes twice: with and without fill. You should only need to change a single parameter to get the two versions of your shape collage (we will look for this when grading). Make sure they don’t overlap too much so that each shape is visible at the end.
At the bottom of your program, use the if __name__==”__main__”: condition from lab so that better_shapelib.py’s testShapes() will only execute if better_shapelib is run directly from the Terminal, not when better_shapelib is imported into another program.
Include this test image (required image 1) in your writeup and explain it in your text.
Create a new scene inspired by your trip to the museum that takes advantage of your “better” shapes’ fill and color parameters. Make sure your scene is in a function with a descriptive name and docstring.
It may be helpful to create a few additional shapes to create your museum scene. If you do, be sure to implement them as “better” shapes (i.e. use loops where possible, x,y, and scale parameters, fill and color optional parameters).
Add a call to your scene function in the if __name__==”__main__” condition at the bottom of your program, then execute better_shapelib.py to verify that your scene works.
Our goal for this task is to use for loops to animate a shape within your scene.
Start a new file called animation.py in your project3 directory, and import your bettter_shapelib as well as Python’s time package.
Hint: You can import better_shapelib as bsl to save yourself from having to type better_shapelib a bazillion times.
Create a main() function that uses a for loop to first draw your museum scene and then add at least one additional shape (doesn’t need to be a brand new shape). You can animate this shape by adding or subtracting a small amount from its x, y, or scale parameter in each iteration of the loop, gradually changing its position and/or size as the loop progresses. Your animation must include at least 100 frames. In other words, the loop must have at least 100 iterations.
Hint: To cover up old versions of your animated shape, call your scene function at the beginning of the loop, then redraw the shape with its new position or size. (In project 6, we’ll explore a more computationally elegant approach to animation with object-oriented design.)
You can control the amount of time between frames of your animation by calling the turtle.update() and time.sleep() functions at the end of the loop, so that each time the object is redrawn the turtle will update the window and then pause before starting the next iteration of the loop.
Hint: Pausing is important because humans can’t perceive change as fast as the turtle can draw it! If you’d like some help getting a feel for how many milliseconds to sleep between iterations, the Wikipedia article on frame rate might help.
Make sure your docstring explains the animation, and that your file header is helpful.
Include at at least two images in your writeup that show the shape changing, and explain your animation in the text.
Congratulations on completing the core tasks! With the writeup (below) and the code you’ve already written, you’ve already earned up to 26/30 points for this project. If you’re exhausted or running out of time, this is a perfectly respectable place to stop. If you’re up for it, the remaining 4/30 points are our way of encouraging you to dig into the design challenge of your choice. To earn all 4 extension points, concentrate on one design challenge, and really dig into it both computationally and creatively. What will you create?
Here are some examples to help you start thinking of the unlimited ways in which you could extend the project:
No matter what you choose to do, remember the importance of efficiency and code organization. Try to solve your design challenge with as little code as possible, and comment it well so that we can appreciate your brilliance.
Be sure to discuss your motivation, design process, implementation, and results in the writeup, or else we won’t know what you did. Always include a screenshot of your extension results!
Turn in your code by putting it into your private handin directory on the Courses server. All files should be organized in a folder titled project3. Include only those files necessary to run the program. We will grade all files and only the files in the project3 directory, so please do not turn in old, non-working, versions of your code.
Make a new Google Doc page and attach it to your assignment on Google Classroom. Put the label cs151s19project3 in the label field on the bottom of the page, and give the page a meaningful title (e.g. Caitrin's Project 3).
In general, the intended audience for your writeup is a peer who hasn’t yet taken a CS course. Your goal is to be able to use your writeup to explain to friends what you accomplished in this project and -- even though they aren’t CS students -- to give them a sense of how you did it. What do they need to know in order to appreciate your results and the elegance of your code? You can assume they have read your prior project reports. The outline below lists the specific sections we consider when grading: