Learning Turtle for Kids
We can draw 2-dimensional graphics in python using a module in Python called turtle. To see more documentation about Turtle visit this website.
To start using the module type:
Now let’s create a place we will be drawing with our turtle by issuing the command:
Here I made up the variable box. You can think about it like a sandbox for our turtle to play in. 🙂
We can add different things to our screen:
We can set a title for our screen
We can change the measurements of the screen
By putting floats, you get a percentage of the screen.
By putting integers you get pixels
You can set a background color for your screen if you want.
Let’s bring in our turtle now:
Again, I made up the variable pet.
Where is our turtle??
You can think of your turtle as being located at the position (0,0) in the coordinate plane.
We can check what its position is by doing:
And you’ll see that it’s located at the center of a coordinate plane.
Let’s make our turtle move!
We can abbreviate this as: pet.fd(50)
We can check to see what the coordinates of our turtle are now:
Wait a MINUTE! What’s moving does not look like a turtle? What’s up with that??
We can change the shape. Here are some of the options:
We can make the turtle go to a certain location:
A command to make him go back to his “home” of (0,0) is:
You can change the turtle’s speed.
An option is to put in an integer from 0 to 10
pet.fd(50) #watch him move now
Let’s make him turn:
As shown below, when we use right or left and specify a number, we are telling it to turn the turtle
right (or left) that number of degrees clockwise
pet.right(45) #We can abbreviate this as pet.rt(45)
pet.left(90) #We can abbreviate this as pet.lt(45)
To clear what you’ve done type:
Let’s draw shapes. Let’s start with a square:
Turtle can also go backwards.
#abbreviation is pet.bk(50)
What if we want the turtle to move but not draw when he’s moving?
We can make the pen go up so the turtle isn’t drawing.
#tells him to pick the pen up
#tells it to put the
#pen back down
We can draw a circle.
Specify a radius.
Something else we can specify is something called extent. If we specify extent, we get the number of degrees of the circle that will be drawn.
The following draws half a circle.
We can use the circle command to draw other polygons by specifying the number of steps to draw the “circle”
This will draw a triangle:
pet.circle(100, steps =3)
This will draw a pentagon:
We can fill in shapes with color.
We specify the pen color and the color that will be used to fil in the shape.
Here we are telling it that what we are about to start will be filled later.
pet.circle(50, steps =3)
#now the shape will be
We can specify the pencolor and fill color in one line:
Note, the fill color will also be the inside color of the turtle or square, etc. that you’re using to draw with.
Using for loops to draw shapes
for i in range(4):
Are you ready to see a cool picture??
for i in range(36):
**Thanks to Robert Crowder. Someone who has been mentoring me in learning python. He provided me with the basic code for Example 2. 🙂 **
Take what you’ve learned and use the for loop to draw a cool picture.
- Ask the user if they want to see a cool picture drawn.
- If they do, ask them what color they want the cool picture to be.
- Ask them what color they want the turtle to be.
- Ask them what background color they would like.
#Try the exercise before looking at a possible answer below.
Here’s a possible picture. Play around with the steps used in statement pet.circle. You can also play around with the angle in pet.rt().
See what cool picture you can come up with in python! Tag me on instagram using @bridgingfundamentals or on facebook!
Keep experimenting to see what cool pictures and shapes you can draw!