Project 2: A shape collection

In this project, you will practice using functions to make a gaming scene made up of simple and compound shapes that you design. You have wide latitude in your choice of subject, and the scene can be as simple or complex as you like. What is important is to properly structure your code and include good comments.
To help you flexibly use your shapes in your dream gaming scene, you will take advantage of functions with offsets and scales to place your shapes in any position and at any scale.
The goals of this project reinforce those from lab:
- Practice Python and functions.
- Use parameters.
- Use best practices for code organization.
Extension points are awarded for complex scenes, especially those that show me that you can integrate concepts from lecture into making your scenes and take things to the next level!
1. Create your project files
1a. Create shapelib.py: it will store all the functions that you write to draw different shapes
- Make a COPY of Lab2.py and name it shapelib.py. This will be your shape library — it will store all the functions that you write that draw different shapes. You will need to turn in Lab2.py so that it can be graded; do not modify your code from lab without making a copy!
- Remove all main code from shapelib.py so that it only has import statements and function definitions.
1b. Reset turtle heading in the goto function
In shapelib.py, add a call to the setheading turtle function so that the turtle always faces east when you call goto (We are using "standard mode").
This may be helpful when you create your scene because you will know the turtle is always facing east when it moves to draw a new shape.
1c. Create the main.py file: it will store functions that you write to draw your scene
- Make a new file called main.py.
- At the top, add your usual header comments (e.g. your name, course, project name, date, etc).
- Import turtle.
- Add an import statement so that you can access the shape functions in your shape library (i.e. import shapelib).
Tip: If you do not want to write shapelib.<function> every time you want to call a shape function, you can instead use the import shapelib as <something> trick to use an abbreviated name. - Make a function called testScene. As the name suggests, this function is only a test to make sure you are able to access your shapes in another file. Call one of your shape functions in the function (e.g. triangleStack).
Remember: the shape is in shapelib.py, not main.py! - Put a single call to the testScene function at the end of the file as main code, followed by a call to exitonclick.
- Run main.py and make sure that the turtle draws the expected shape. You don't need to save this image; it is only a test.
2. Make two more simple shape functions in shapelib.py
They could be shapes like a rectangle, circle, non-equilateral triangle, n-gon, etc. Each function should minimally take parameters for:
- x location
- y location,
- necessary size information. For example, if you were making a function that draws a rectangle, you would have two parameters for the width and height, in pixels.
Some important guidelines:
- Plan ahead: these will be the building blocks that you use to make gaming-themed compound shapes. For example, if you eventually want to make a playing card, what simple shapes (e.g. circle, rectangle, triangle) do you need to make it?
- You want to make sure that your shapes draw properly no matter where they are drawn on the screen, what the size parameter is, or what the heading of the turtle happens to be when the shape function executes.
- Grading of your shape functions will take your for loop usage into account: use for loops wherever appropriate to eliminate redundant lines of code. For example, you should only need 3 lines of code to draw a hexagon, not 12. Of course, you are only expected to use loops when possible and it makes sense. Try designing your shape without loops first and if you find yourself typing the same lines over and over again, think about converting them to a loop.
Test out each of your functions one-by-one as you make them. This means calling your two shapes in main code at the bottom of main.py several times to draw each in a few different positions and sizes.
Take a screenshot. This is Required Images 2 and 3 that you should include and describe in your written report.
3. Make two compound shape functions in shapelib.py
These should be gaming themed. The objects should be built from at least two of your simple shapes (e.g. triangles, rectangles, circles, etc.) from your shape library.
Just like triangleStack from lab, your compound shape functions should take at least three parameters:
- x position
- y position
- scale
Remember the process for designing complex shapes:
- Hard-code all parameter values in your function with actual numbers to make something that looks good.
- Replace the position of your first shape with (x, y). Convert the remaining shape positions to offsets.
- Multiply the scale parameter to sizes and offsets, not positions.
Your shapes should draw properly at any scale, location, or turtle orientation.
Take a screenshot of both compound objects. This is Required Images 4 and 5 that you should include and explain in your written report.
4. Make a gaming scene!
Write your code in a function called gaming1 in main.py. It should use the simple and compound shapes that you have made — drawing them in different positions and sizes. You can also use color, the random module, and for loops to make your scene more complex and interesting.
Take a screenshot. This is Required Image 6 that you should include in your report.
Check reproducibility
In order to grade your project, we need to be able to run your code and get the same results as you do! Here is a summary of the expected outputs from each of the source code files that you created (i.e. by running python3 <filename>.py):
- Lab2.py: A stack of triangles drawn in different positions and at different sizes.
- main.py: Your gaming scene.
Extensions
Congratulations on completing the core tasks! If your code and report meet the above expectations, you’ve already earned up to 26/30 points for this project.
The remaining 4/30 are a chance for you to earn credit for exploring parts of this project and digging deeper to express your creativity! This is entirely optional; 26/30 is a B and is a perfectly respectable place to stop. Extensions are open-ended and exist to compliment the structured core project. Explore and learn something new that interests you! Concentrating your energy on 1-2 "deep" extensions that challenge you will earn you more points than many small, "shallow" extensions.
You can pick your own topics that interest you. Here are a few examples:
- Creative or complex scenes above and beyond the basic expectations count as extensions
- Make additional basic or complex shape functions that make use of your other shape functions.
- Make additional scenes that show creative use of functions, loops, or randomness.
- 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.
Submission checklist
To turn in your project, make sure you do all of the following:
- Check the rubric in Google Classroom and make sure your report and code contain all the required parts.
- Move your lab folder inside your project folder (i.e. drag the Lab01 folder inside Project02).
- Drag and drop the lab and project files to your shared directory on Google Drive.
- Make a copy of the rubric and move it to the shared directory on Google Drive.
- Make sure you can see your lab, project, report, and rubric in the project directory on Google Drive.