Complete as much of this prelab as possible before lab on Thursday / Friday.
From within the Thonny application, create a single Python file username_hw9.py with all your work for this assignment in it. Include a comment at the top with your name, the date and homework number, and your lab section.
This week we'll use the turtle again! Recall you can import
the turtle library with the command
import turtle as t
, and then use commands such
as t.penup()
.
You can find
more information in the turtle
documentation. A quick reference is included at the bottom of this
page.
Create a Point class as we did in the class example on Thursday April 19. We'll use this to create Point objects that hold x,y coordinates of locations where we'll want to draw.
Write a drawDots(points)
function
that takes a list points
as input and
draws a dot on the drawing window for each Point.
For example, you should be able to call your function
as follows:
>>> p = Point(10, 20)
>>> q = Point(20, 30)
>>> points = [p, q]
>>> drawDots(points)
For the prelab portion, you should have
completed code for a basic Point
class
as well as a drawDots(points)
function.
Your class, methods, and functions should each have a docstring,
and the top of the file should include a comment listing (at a
minimum) your name, the date and homework number, and your lab section.
You will continue working on this same Python file and add more
function definitions when you continue working on the rest of Homework 9.
Python includes a
library called turtle
, which allows us to draw some
simple graphics with a turtle that can draw wherever it walks. So, we
issue commands to tell the turtle where to go, and a drawing appears
as it moves. Here are the most important commands. More can be found
in the online
documentation.
forward(distance)
distance
in the direction it is facing.backward(distance)
distance
in the opposite direction to where it is facing.right(angle)
angle
. Note that this can be any angle, not the four cardinal directions we had with LightBot.left(angle)
angle
.goto(x, y)
pendown()
penup()
pencolor(colorstring)
fillcolor(colorstring)
begin_fill()
end_fill()
tracer(state)
True
or False
to turn the tracing on or off.update()
window_width()
window_height()
dot()