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. We'll continue to create shapes using turtle graphics, just like we did in lab.
Open up your shapes.py file from lab in a text editor. Most of this
assignment has to do with adding new functions to the shapes.py file.
The first task is to create a new function that draws a square. Like the block function, we also want to be able to specify the location of the square. Therefore, the definition of the function needs three parameters.
def square( x0, y0, dx ):The commands in the square function will be identical to those in the block function, except that dx will be used for the length of all of the sides.
In the shapes.py file, make 3 more 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.
In at least one of your shape functions, use one or more of the other shape functions to draw the shape. For example, a house might use the block and square functions to draw elements of the house.
- Copy the file step3.py from lab to a new file (e.g. proj2.py). Using the functions you created in steps 1 and 2, make an outdoor scene by telling python to draw 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.
- When you have a scene you like, make a screen capture of it on a mac using the key combination command-shift-4. Then hit space bar to get the camera icon and click the mouse to take the picture. The picture will automatically be saved to a file called Picture 1.png on your Desktop. You can then move and rename it to a more approrpriate location.
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 at least one extension. The difficulty and quality of the extension or extensions will determine your final grade for the assignment. One extension, done well, is typical.
- Make additional shape functions that make use of your other shape functions.
- Make one or more additional outdoor scenes that show creative use of functions.
- Make use of the for loop control structure from the first 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
import randomThen 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.
- 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.
Hand in your code for this assignment using the Moodle drop box. There will be a drop box for each week's assignment.
For this week you will hand in at least two files: your shapes.py file that defines your shape functions and your lab2.py file that draws the scene. If you implemented additional scenes, you will have an additional file for each scene.
To make submission easier, please create a zip file with all of your python files for handin. On a mac, you simply select the files you want to zip together in the Finder and then select 'Compress' from under the File menu. Hand in the resulting zip file.
In the unlikely (we hope) event that Moodle is down when you need to hand in your assignment, please email the zip file to Professor Maxwell.
Please do not place code anywhere public. Do not include it in your writeups on the wiki, for example.
Each of you should create your own wiki page for your writeup. The writeup can be brief, but should include the following components.
- A brief abstract (200 words or less) describing the project.
- A more detailed description of what you did. For this project, give a description of each shape for which you made a function and highlight any interesting features, such as one shape function calling another.
- Include any images or other output your program created. For this project, include a picture of your scene or scenes.
- Describe any extensions you implemented and show results for them.
- Give a brief (1 paragraph) description of what you learned.
Please put the label cs151s09proj2 on your writeup page (down below the editing window on the edit tab). Please make sure you type the label exactly as given above.