For the lab this week, we will be using the turtle graphics module to draw a picture. You will have two options, a seascape with fish and rocks, or a space scene with spaceships and planets. Here is an example drawing.
An important programming paradigm is code reuse. Rather than writing your own code, say a turtle module, you can use one that someone has already written. An important programming skill then is documentation, both reading documentation and generating it for your own programs. The documentation for the turtle module can be found at http://docs.python.org/3/library/turtle.html, and contains an overview of all of the functions available to you.
To get ready for lab you’re going to need to read a bit more about some of the functionality of the turtle module. Below are a few methods that may be useful, but that we haven’t focused on in class. Click on each of them in the documentation and make sure you understand what they do as well as what parameters they take and what, if anything, they do or return.
In addition to looking at the online documentation, also try out the
function, which takes the name of a function as an argument, and outputs the
docstring (i.e. function description) for us. Start up Thonny and use
get the documentation for some of the above two functions. Remember you will
need to import the turtle module first:
from turtle import *
Here are some more example functions using turtle for you to review in preparation for lab.
Your program this week will produce a beautiful colorful drawing, of either an underwater scene or a space scene. You will need to create functions that draw shapes you will use multiple times in your drawing. For example, you’ll want to define a function that draws an object such as a rock or a planet (e.g., an arbitrarily sized polygons), and then you’ll call that function multiple times to get various sized rocks/planets at different locations. Similarly, you’ll want to define a function that draws an object such as a fish or a spaceship (e.g., a triangle), and again you’ll call that function multiple times to get multiple fish/spaceships at different locations. Read through the entire lab assignment before starting on your plan.
Plan out the design for your drawing on paper. The screen size will be approximately 700×700 (each dimension ranging from -350 to 350, with the origin (0,0) in the center of the window). You will submit a copy of a hand-drawn rough sketch using a print-out of this template. (If you can’t print it, just draw on a blank sheet of paper.)
With these dimensions in mind, plan out on the paper where the different shapes will go, their sizes, etc. In particular:
As part of your planning, start thinking through how you will draw your shapes and how that approach influences your choice of coordinates, etc. For example, when you specify the coordinates of a triangle, which corner of the triangle do those coordinates specify?
You should plan on having at least six fish/ships and six rocks/planets (i.e., at least six each of two kinds of objects, though if you’d like to have more, that’s fine too!). Your hand-drawn sketch is just a first draft to get you thinking. Your final submission for Lab 2 does not need to look like your initial sketch for the Prelab!
Upload a PDF scan of your drawing on this template to Gradescope. Gradescope has a helpful guide for scanning assignments on a mobile device.