Project 2: A Shape Collection
The goal of this assignment is to give you practice in creating and using functions and function parameters in python. You'll continue to create shapes using turtle graphics, just like we did in lab.
The end result of the assignment should be an iconic, but interesting outdoor scene.
Tasks
-
Make a copy of your lab2.py file and rename it shapes.py. Delete the
main code from the file so that only the import statements and the
functions remain.
Your first task is to create a main.py file that imports your shapes.py functions. To do this, create a file called main.py in a text editor, and at the top put the following.
import shapes
In your main.py file, make a function called scene1. For top-level code, Put a single call to the scene1 function at the end of the file, followed by a call to raw_input().
Write some python code in your scene1 function that calls some of the functions from your shapes.py file to draw a simple image. Note that to call a function from your shapes file you have to prepend shapes. in front of the function name. For example, to call the block() function:
shapes.block( 10, 10, 20, 30 )
Remember, you run your main.py file using:
$ python main.py
You don't need to save this image, as you'll be replacing the code in the scene1 function later on.
-
In your shapes.py file, make 2 more functions like the block
function that take in at least an x location, y location, and a scale
factor (or two). For example, you could make a triangle function or a
hexagon function. Put a print statement at the beginning of each
function and test them out by calling the functions in your main.py
function.
All of your shapes should draw properly no matter where it is drawn on the screen, what the scale factor is, or what the orientation of the turtle happens to be when the shape function executes. Test this out for all of your functions. In your writeup, include a picture demonstrating that your shapes function properly.
When you have a scene you want to save, make a screen capture of it on a Mac using the key combination command-shift-4. Then hit the space bar to get the camera icon and click the mouse on the scene window to take the picture. The picture will automatically be saved to a file on your Desktop named after the time the picture was taken. You can then move and rename the picture to a more appropriate location.
-
In the shapes.py file, make 2 functions that draw iconic versions of
standard outdoor objects (e.g. houses, bushes, trees, park benches,
cars). When you define these functions, they should all take at least
three parameters. The first two (x0, y0) will define the starting
location for the shape and the third should define the size of the
shape. Feel free to add additional parameters as you like to control
other aspects of the shape. As with the basic shapes, your shapes
should draw properly at any scale, location, or turtle
orientation.
For a little more detail on making aggregate shapes, see the geometric thinking page.
In both of of your new functions, use one or more of the basic shape functions to draw the shape. For example, a house might use block and triangle functions to draw elements of the house. Test out your new functions before proceeding. In your writeup, include a picture demonstrating that your shapes function properly
- Using the functions you created in steps 1 and 2, make an outdoor scene by writing code in the scene1 function in your main.py file that draws the shapes in appropriate locations. In your scene, make use of the fact that your functions can draw the shapes with different sizes in different locations. You can also use the random package and for loops to make more complex scenes. Save the image and include it in your writeup.
- Make a second outdoor scene in a function scene2 in your main.py file. Save the image and include it in your writeup.
Extensions
Each assignment will have a set of suggested extensions. The required tasks constitute about 85% of the assignment, and if you do only the required tasks and do them well you will earn a B+. To earn a higher grade, you need to undertake one or more extensions. The difficulty and quality of the extension or extensions will determine your final grade for the assignment. One complex extension, done well, or 2-3 simple extensions are typical.
- Make additional basic or complex shape functions that make use of your other shape functions.
- Make additional outdoor scenes that show creative use of functions, loops, or randomness.
- Make use of the for loop control structure from the lab (you can also read ahead in the book).
-
Make use of the random package to make your scene more
interesting. For example, if you import the random package into your
program:
import random
Then you can use it to generate random integers using the following expression, where a and b are the upper and lower bounds of the random numbers you want.
random.randint(a, b)
- Make use of other turtle properties such as line width, color, and fill capability to make your shapes more interesting.
- Add additional parameters to your shapes to control properties like line width and color.
Writeup
Remember, there are two components you need to hand in: your code and a writeup. Put the Python files you wrote (shapes.py, main.py) on the Academics server in your handin directory. In Finder, press command-k to mount a network drive. Enter the following in as the Server Address:
smb://fileserver1/Academics/COMP/cs151/<username>
where you replace <username> with your user name. Copy your project 2 directory out to this handin directory. (Note that if you keep all your project 2 code in its own directory, you can just drag and drop this directory. Otherwise, you'll need to create a new directory for project 2 within your handin directory, then copy each individual file over to this directory.)
Make a new wiki page for your assignment. Because you are working on your own, each of you needs to make your own writeup this week. Add the following label to the page:
cs151f10proj2
The purpose of the writeup is threefold. First, it gives you the opportunity to organize your thoughts about the project and see the larger purpose of the various tasks. In the case of this project, for example, the purpose was to introduce you to making use of functions as abstrations that let you create more and more complex graphical designs.
The second purpose is to give you practice with communicating the process and algorithms you developed to others. The writeup should capture the key points of the code you wrote. In the case of this project, describe how you divided up the task of making a scene. Did the division make sense? What program elements—functions, loops, variables—did you use to complete the task? Don't focus on the syntactic details, but on the overall structure and process your code uses to solve the problem. The best writeups are tutorials on the subject that would be appropriate for your peers not in the course.
The third purpose is to communicate to us that you understood the project and to show off any extensions or extra things you did to make it more interesting. We're also interested in knowing the primary things you learned from the project.
In general, your writeup should follow the outline below.
- A brief summary of the task, 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.
- A description of your solution to the tasks, including any images you created. This should be a description of the form and functionality of your final code. You may want to incorporate code snippets in your description to point out relevant features. Note any unique computational solutions you developed.
- A description of any extensions you undertook, including images demonstrating those extensions. If you added any modules, functions, or other design components, note their structure and the algorithms you used.
- A brief description (1-3 sentences) of what you learned.
-
Don't forget to label your writeup so that it appears in the listing
on the main wiki page for the course. For this lab, use:
cs151f10proj2