Unit 2 Flashcards
By the end of the unit, you will be able to: Use the functions in Python’s built-in drawing library (turtle) to draw a variety of colourful lines and simple shapes that combine to reproduce a graphical image.
What is a module?
A module provides a set of useful code to be used by another program.
What is the use of the turtle module?
The turtle module allows you to draw objects using Python.
Before we can do anything with the turtle module, we ___________.
Before we can do anything with the turtle module, we need to import it. Open up IDLE and type in: import turtle
After you‘ve typed that in, press “enter”. This tells Python that you want to use the turtle module.
What are the two lines of code to import turtle?
import turtle
t=turtle.Pen()
What happens when you press enter after typing these lines of code:
import turtle
t=turtle.Pen()
You should see the drawing canvas pop up. The turtle might look like just a black triangle, but that’s your turtle.
Why is the black triangle called a turtle even though it does not look like one?
It is because it is a reference to the Logo programming language, which has been helping kids learn programming for a very long time - over 50 years!
Can you change the appearance of the turtle?
Yes
How do you change the shape of the turtle into a circle?
import turtle
t= turtle.Pen ()
t.shape (“circle”)
How do you change the shape of the turtle into a turtle?
import turtle
t=turtle.Pen()
t.shape (“turtle”)
What are the different shapes that you can change the turtle into?
Arrow
Turtle
Circle
Square
Triangle
Classic
What is the correct way to create a turtle object named fred?
fred= turtle.Pen()
When we are entering numbers for our turtle to move, the unit we are using is ______.
The unit we are using is pixels. These are the tiny dots that your computer screen is made up of. You might have heard of a term called the “resolution” of your monitor, which could be something like 2304 by 1440. That means that the computer monitor has 2304 pixels the long way and 1440 pixels the short way. So pixels are pretty tiny!
How do you move a turtle forward?
t.forward(30)
Let’s say if you want to move the turtle forward by 30 pixels
When the turtle moves, there will be a black line (by default) connecting from where it began to where it is now.
How do you move the turtle backward?
t.backward(30)
This command makes the turtle go back to where it came.
Let say the turtle is the shape of an arrow. Which direction would the arrow of the turtle be facing when there is a command to move it backwards?
The arrow will look like that
>