HW 2 (Drawing a Picture)
Assignment overview
In this assignment, you'll write a step-by-step algorithm for drawing a picture, and then write code to draw that picture using the turtle library.
Goals
Get practice using functions and loops, as well as writing out algorithms in a step-by-step way.
Logistics
This is a partner assignment, which means you should complete all pieces of this assignment with your assigned partner. In particular, any coding must be completed side-by-side in a pair programming style. You are welcome to discuss the assignment with other classmates, course staff or Anna. Make sure to cite any help you receive in the "acknowlegdements" portion of the assignment.
You can find your partner by looking in the Moodle gradebook.
This assignment is due at 10PM on Wednesday, April 8.
Setup
Mount the COURSES drive and create a folder called hw2 in your STUWORK folder.
Open the new folder in VSCode.
If you need a refresher on how to complete these steps, refer back to the in-class
lab from the first day of class.
Next, download the starter file picture.py
from this link.
Move the file into your new hw2 folder.
You may find it useful to refer to the Turtle Documentation when working on this assignment.
Part 1: Make a plan
Start off by deciding what you are going to draw. This could be a face, a skyline with multiple buildings, a series of geometric shapes, etc. I suggest making a sketch on paper of your goal drawing so that both you and your partner know what you're trying to create. Picture requirements are listed below, and you can also see a rubric under the "Grading" header at the bottom of this page for details on how your work will be assessed.
Once you've decided what you're going to draw, you should write out step-by-step instructions for how to draw it. It will be especially helpful to identify any repeated elements, because you'll likely want to create a function that you can repeatedly call to create that element. Once you've identified the individual pieces of the drawing, you should also think about what order they should be drawn in. For example, if I'm drawing a face, I probably need to draw the head before adding eyes.
Create a text fle called blueprint.txt and put your step-by-step instructions in this file. You will submit
this text file along with your Python code that actually draws the picture. When you start programming, you
might realize that parts of your plan need to be modified. This is fine (and expected). You don't need to update
blueprint.txt with the changes (although you could note the deviations with comments in your code, if you
like).
Picture requirements
The goal of this assignment isn't to draw any picture in particular, but instead to give you practice with functions, loops, and general Python skills. To make sure you're meeting all of these goals, your picture and code needs to meet the following requirements:
- Use at least three different colors
- Include at least two functions other than
drawPicture. At least one of these functions needs to take in one or more parameters - Include at least one loop
- Call at least three distinct methods from the
turtlemodule (for instance,forwardandrightare two methods that count towards this requirement).
These requirements are just a minimum. Feel free to use additional colors, loops, functions, and methods!
If you find code (that Anna writes in class, that's in the Turtle documentation, or that's elsewhere in the
Python documentation) that does one of the above goals, you may use that code with citation, but it does not
count towards meeting the requirements listed above. For example, you may use the drawSquare() function that Anna
wrote in class, but you would still need two additional functions that you create.
Part 2: Write code to implement your plan
Working in the picture.py file that you downloaded, write code to draw the picture described in blueprint.txt.
The file calls createPicture() outside of any function, so when you run python3 picture.py your picture will
be created. Don't change the name of this function (this will make it easier for course staff to run your code
and generate the picture).
The picture.py file contains some places for you to write comments. In particular, we will use the triple quote
notation to write comments for each function. You should fill in this block for the functions I've created already,
and make sure to include it for each of the functions you creates. This comment should include a description of the
function and a list of parameters that the function takes, along with a short description of each.
For example, if I create a new function called drawRectangle, I would document the function like this:
def drawRectangle(myTurtle, height, width): """ Draws a rectangle of dimension height x width. Starts drawing at myTurtle's current location, moves up height pixels, to the right by width, and then back down/over to end at the same location where it started. Parameters: myTurtle - a turtle object height - a number indicating how tall the rectangle should be width - a number indication how wide the rectangle should be """ # Replace this line with code
After writing each function, you should test it out in the interpreter. For example, I could run the
following code from the terminal to test drawRectangle.
$ python3 >>> import picture >>> import turtle >>> t = turtle.Turtle() >>> picture.drawRectangle(t, 100, 50)
The first line imports the code that you just wrote in picture. The next two lines replicate code from picture.py
that you need in order to be able to call the new function. The final line executes your drawRectangle function
(and none of the other code in picture.py).
After creating all the functions you need, add code to the function createPicture to actually draw your
picture!
Wrap up
When you're finished, make sure to complete the usual documentation steps. This includes adding comments and filling out the acknowledgements and reflection portion of the header.
You should also think about coding style. Have you written everything in a consistent way that is easy to read? Review the style document on Moodle for the expectations for this assignment. As a bonus step (at this point in the course), also think about whether there is any reorganization that makes sense. For instance, if you have a lot of commented-out lines that you don't need anymore, consider deleting them so that the code is less visually cluttered.
Assignment submission and misc. notes
I may share some of the Turtle drawings with the class in a future lecture. If you don't want me to share your
drawing, please indicate that in the header of picture.py.
Handing in the assignment
You need to hand in blueprint.txt and picture.py on Gradescope (see Moodle for the link to Gradescope).
You can drag these files individually to the Gradescope submission window, or you can create a zip file to upload instead.
zip hw2.zip blueprint.txt picture.py
After creating your Gradescope submission, make sure to add your partner. Click "view or edit group" in the right sidebar after submitting.
Grading
This assignment is more open ended than the previous assignment, so there is no autograder. Instead, you'll be graded on the following rubric (40 points total):
- 8 points: blueprint.txt is included and the picture blueprint is described clearly. It's okay if there is some deviations from your final plan, however, the grader should be able to follow the steps in the blueprint to create exactly the drawing that you were envisioning.
- 6 points: General functionality. Does you code successfully draw a picture when we run
python3 picture.py? - 6 points: Additional functions. Do you include at least two functions that you wrote?
- 6 points: Loops. Do you use at least one loop in your code?
- 8 points: Creativity. The more complex your picture is, the higher you can score. The other picture requirements described above will be evaluated as part of this category.
- 6 points: Coding style. Does the header contain all necessary information? Did you follow the style guidelines described on Moodle? Did you make an attempt at commenting your code? (Comments will be graded generously and it is the attempt that counts. We will talk more in the coming weeks about what to include, or not include, in your comments.) Did you use functions and loops instead of typing out many copies of repeated code?
Anna's acknowledgements
Portions of this assignment were borrowed from Layla Oesper. Thanks for sharing!