fbpx Placeholder canvas

Turtle programming

Meet Tina

Tina is a Turtle that you control with code. Press run to see what this program does, and see if you can figure out what line tells Tina to say,"Why, hello there!"

Don’t worry if you don’t understand all of the code. it will become familiar to you as you keep going.

Moving

As we saw in the last example, Tina can move! When she moves, she draws a line. She can move forward and backward and turn right or left a certain number of degrees.

Run this example to see her move:

Assignment:

She’s almost made a square! Can you help her complete it? What other shapes can you help Tina draw?

Saying Hello

Tina’s already said hello but you can tell her your name and she’ll say hello to you. Find the line where Tina says "Why, hello there!". Next, change it so that she’s saying hello to you. My name is Ajay, so I’d change what she says to "Why, hello Ajay!".The program you wrote above is great for people that have the same name as you, but what if someone has a different name? We can write a program that asks for your name with the input function, so that Tina can get it right for anyone’s name. Run this program and enter your name:

The input function is what makes the program ask you for your name. Whatever you type in is then stored in a variable. Tina uses this variable to remember and then say your name!

Assignment:

We can teach Tina to say anything we want using input. Can you add input to this program so that anyone who runs it can tell Tina what to say?

Hint: you can make the say_what variable is which Tina says in this program.

Color

Tina can change into lots of colors! We can tell her to change into blue by typing tina.color("blue").

Click run to see:

Each color segment in the picture is created by three lines of code:

tina.forward(20)
tina.color("blue")
tina.write("What color am I now?")

Assignment:

Add two more colors to her list by adding another three lines like this but with "blue" replaced with your favorite color.

Tina’s pen

Turtles like Tina have a pen that draws when they move. We can tell them to pick the pen up, so that they can move without drawing a line. Then we can tell them to put the pen down, and they’ll draw again. We tell them this with the penup() and pendown() commands.

Tina’s grid

Tina’s world is a grid of squares like the one we sometimes use to graph in Algebra and Geometry.

We can tell Tina to go directly to a specific point on the graph. This makes it easy to teach her to draw something!

Assignment:

Play around drawing with Tina. Send her to other points on the grid with a new line like this:

tina.goto(37,-50)

You can pick whatever numbers you want, but they must be between -200 and 200 for you to see them.