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.  

Step 1:

To start using the module type:

import turtle.

Step 2:

Now let’s create a place we will be drawing with our turtle by issuing the command:

box=turtle.Screen()

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
box.title(‘The Sandbox’)

We can change the measurements of the screen
By putting floats, you get a percentage of the screen.
By putting integers you get pixels

box.setup(height=1.0,width=1.0)

You can set a background color for your screen if you want.

box.bgcolor(‘cyan’)

 

learn python coding for kids

Step 3:  

Let’s bring in our turtle now:

pet=turtle.getturtle()

Again, I made up the variable pet.  

 

Step 4:

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:


print(pet.position())

And you’ll see that it’s located at the center of a coordinate plane.

learn python coding for kids

Step 5:

Let’s make our turtle move!

pet.forward(50)

We can abbreviate this as:  pet.fd(50)

We can check to see what the coordinates of our turtle are now:
print(pet.position())

 

 

Step 6:

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:

pet.shape(“arrow”)

pet.shape(“classic”)

pet.shape(“square”)

pet.shape(“turtle”)

 

learn python coding for kids

 

STEP 7:
We can make the turtle go to a certain location:


pet.goto(100,100)

A command to make him go back to his “home” of (0,0) is:

pet.home()

 

STEP 8: 

You can change the turtle’s speed.

An option is to put in an integer from 0 to 10


pet.speed(1)

pet.fd(50)  #watch him move now

 

Step 9:

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.fd(100)
pet.right(45)        #We can abbreviate this as pet.rt(45)
pet.fd(100)
pet.left(90)           #We can abbreviate this as pet.lt(45)
pet.home()

 

STEP 10:

To clear what you’ve done type:

pet.clear()

 

learn python coding for kids

STEP 11:

Let’s draw shapes.  Let’s start with a square:

pet.forward(50)
pet.right(90)
pet.forward(50)
pet.right(90)
pet.forward(50)
pet.right(90)
pet.forward(50)
pet.right(90)

 

STEP 12:

Turtle can also go backwards. 


pet.backward(50)
pet.right(90)
pet.backward(50)
#abbreviation is pet.bk(50)
pet.right(90)
pet.backward(50)
pet.right(90)
pet.backward(50)
pet.right(90)

pet.clear()

 

STEP 13:

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

pet.penup()
pet.home()
#tells it to put the
#pen back down
pet.pendown()
pet.forward(50)
pet.rt(90)
#pet.clear()

STEP 14:

We can draw a circle.

Specify a radius.
pet.circle(50)
pet.clear()
pet.circle(100)
pet.clear()

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.

pet.circle(50, 180)
pet.clear()

learn python coding for kids


STEP 15:

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)
pet.clear()

This will draw a pentagon:
pet.circle(50,steps=5)
pet.clear()

 

STEP 16:

We can fill in shapes with color.

We specify the pen color and the color that will be used to fil in the shape. 
pet.pencolor(“blue”)
pet.fillcolor(“red”)

Here we are telling it that what we are about to start will be filled later.
pet.begin_fill()
pet.circle(50, steps =3)
#now the shape will be
#filled
pet.end_fill()
#pet.clear()
pet.penup()
pet.backward(100)
pet.pendown()

STEP 17:

We can specify the pencolor and fill color in one line:
pet.color(“blue”, “red”)
pet.begin_fill()
pet.circle(50, steps=8)
pet.end_fill()
#pet.clear()

 

Note, the fill color will also be the inside color of the turtle or square, etc. that you’re using to draw with.

 

STEP 18:

Using for loops to draw shapes

Example 1:
for i in range(4):
   pet.fd(50)
   pet.right(90)


pet.clear()

 

learn python coding for kids

Are you ready to see a cool picture??

Example 2:

for i in range(36):
   pet.circle(50, steps=5)
   pet.rt(10)

 

**Thanks to Robert Crowder.  Someone who has been mentoring me in learning python.  He provided me with the basic code for Example 2. 🙂 **

learn python coding for kids

Exercise

Take what you’ve learned and use the for loop to draw a cool picture. 

  1. Ask the user if they want to see a cool picture drawn.
  2. If they do, ask them what color they want the cool picture to be.
  3. Ask them what color they want the turtle to be.
  4. Ask them what background color they would like.


#Try the exercise before looking at a possible answer below.

kids learning python coding

learn python coding for kids

 

 

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().  

learn python coding for kids

learn python coding for kids

 

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!

Recommended Posts

Leave a Comment

0
Pinterest
fb-share-icon
Instagram
learn python coding for kids