In this project you will design a program and a beautifully artistic scene painted painstakingly on your screen, and ours, by our little turtle
friend.
Before beginning this project, you should complete the Turtle Graphics Introduction Tutorial.
The scene you choose to create should have some element in it that repeats / is reused at least three times. Perhaps it’s a forest of trees, or a house with many windows, or a flock of birds scattered in the distance, maybe it’s stars in the night sky, or snowflakes floating fancily about. Pick a scene that sparks joy and transports you to a place of hygge and happiness.
If you need inspiration, look no further. Remember, when learning how to program there are no mistakes, just happy, little accidents.
This is an open-ended project and we encourage both exploration and pushing yourself. The rubric applied to your project is as follows:
20 points - Define at least four separate procedures purpose is to draw visual components of your scene and are meaningfully named to describe what component they’ll draw. These procedures must make use of at least two float
parameters for x
and y
coordinates of where to start drawing the component on the canvas. You are free to implement other “helper” procedures that abstract simpler ideas for use in your required procedures (for example, a procedure that draws a line
between any two coordinates or a rectangle
procedure).
10 points - Have a draw_scene
procedure whose purpose is to make use of the component procedures described in the previous requirement to place the componenets of your scene. It does not need to take any parameters, but can. After your functions are all defined, including draw_scene
, you should call the draw_scene
function as the last line of your program file.
5 points - Call at least one of your four required component procedures twice to place that component twice in your scene in different locations.
10 points - Use a while
loop to avoid repetitive code in some part of your scene.
5 points - Fill at least one shape in your scene with a color other than white.
5 points - Change the marker’s tracing color for at least one shape in your scene to something other than black.
15 points - Static Types - Be sure to specify each function’s parameter’s types as well as each procedure’s return type (None
).
15 points - Linting: Good, Pythonic style (remember: two blank lines between each function definition!) and presence of doccstring
documentation at the top of the module (file) as well as in each function.
5 points - Effortful and meaningfully descriptive docstring
documentation.
Hitting the low bar on the minimum requirements with the minimal effort possible will result in a maximum score of 90%. To earn beyond 90%, we will look for the following criteria and ask that you use the file’s docstring
to document which of these points you are attempting and tell us where to look in your program to find them.
5 points - Avoid any single function from becoming too complex. When programming in general, if you find yourself writing a very complex function, it’s likely you should break it down further into simpler functions. To earn credit for this, break your most complex procedure besides draw_scene down further into simpler, but still meaningfully named procedures.
5 points - Impress us by trying out something you find interesting! Describe what you are attempting here in the file’s docstring
so we know what to look for. Remember, a docstring
can span more than one line, it just ends with the """
. Some ideas you could try for here:
turtle
documentation page to find a function to use that we did not make use of in the turtle tutorial and make use of it in your project: https://docs.python.org/3.8/library/turtle.htmlrandom
module: https://docs.python.org/3.8/library/random.htmlIt is worth noting it is very ok, and perhaps expected, for your scene to look like a drawing you might have been proud of in kindergarten. Such is the nature of doing art on a medium you’re new to. The end visual result is less interesting than the process by which you got there. Your grade will not be impacted by the ultimate beauty of your creation. With that said, drawing 5 lines on the screen with as little effort as possible and calling it “art” may very well be art, but will likely not result in full credit. We should be able to look at your program and appreciate that you put effort into it.
In your course workspace, expand the comp110
directory and then projects
. Right click in projects
and add a file named turtle-scene.py
.
You can use the following template to begin your program. Unlike the tutorial, which implicitly imports all functions, this example explicitly imports those used in the tutorial one-by-one. This is generally a best practice so that you know exactly which names in your program are bound to what.
We’ll begin by adding a draw_scene
function that takes no parameters and, since it is a procedure has a return type of None
.
"""TODO: Describe your scene program."""
__author__ = "Your PID"
from turtle import forward, left, right, goto, setheading
from turtle import color, pencolor, fillcolor, colormode
from turtle import penup, pendown, begin_fill, end_fill
from turtle import speed, done, hideturtle
def draw_scene() -> None:
pass
# TODO: Define procedures for other components in your scene here.
speed(10)
draw_scene()
done()
The pass
keyword is what’s called a “non-operation” or “noop” that has no effect and is just a placeholder that allows us to define the function without having any meaningful statements in its body.
To give you an example of what is expected in your four “component” procedures, consider this one that draws a square and adds an additional parameter for you to control the width of the square:
def draw_square(x: float, y: float, width: float) -> None:
"""Draw a square of the given width whose top-left corner is located at x, y."""
i: int = 0
penup()
goto(x, y)
setheading(0.0)
pendown()
while i < 4:
forward(width)
right(90)
i = i + 1
The setheading
function takes a float
value that is the degrees to face the turtle in. So, in the example above, each time the draw_square
procedure is called the turtle’s heading is reset to head toward 0.0
degrees (along the x-axis headed in a positive direction). Since your component procedures do not know the starting position of the turtle or the direction it is heading in, you will likely benefit from using goto
and setheading
to move it and face it in the direction you’d like.
After defining this procedure we could call it from the body of the draw_scene
function to draw a few squares. For example, by replacing pass
with the following calls:
def draw_scene() -> None:
draw_square(-5, 5, 10)
draw_square(-10, 10, 20)
draw_square(-15, 15, 30)
draw_square(-20, 20, 40)
# Challenge: Try rewriting those four repeated calls in a loop
# and using arithmetic expressions to calculate each of the arguments
# based on your counter variable's value rather than hard coded int
# literals. For example, the first argument could be: (i + 1) * -5
To prepare your scene for submission, be sure to add a docstring to your module (at the top of the file) and a global __author__
variable set to a string which contains your 9-digit PID. If you are attempting the final 10% of the project, also be sure to describe what to look for in your program per the instructions above. Add that description to your docstring.
The programmer’s job is not done merely by achieving some desired functionality. Programming is a craft and a programmer’s work should be documented and adhere to common stylistic rules. Autograding for this assignment performs checks for the 30 points dedicated to such concerns: linting and static type checking. These checks are focused on nit-picky improvements. Developing good habits around fixing these concerns as you move through your programming career will pay dividends, just like brushing your teeth.
Here are a few suggestions for cleaning up your code in anticipation of static type checking:
None
)turtle
project explicitly. For more on this refer back to the Getting Started section which contains a sample code listing that explicitly imports functions from the turtle
module by name.Here are a few suggestions for cleaning up your code in anticipation of linting (style checking):
draw_square
function in the sample code above.#bad
lacks a space while # good
includes a space.On your first submission, you are likely to see a number of lint and type checking issues arise. Don’t be dismayed! Remember, each is telling you the line number to find the issue on and describes what the issue is. Many of these rules the linter will teach you through some trial and error and by the end of the course you will be in the practice of writing code in a good, Pythonic style.
To build your submission, run python -m tools.submission comp110/projects/turtle-scene.py
to build your submission zip for upload to Gradescope. Don’t forget to backup your work by creating a commit and pushing it to GitHub. For a reminder of this process, see the previous exercises.