17.1. History of Turtles

The idea of a virtual turtle, dates back to the 1960’s. Seymour Papert and his group at MIT created the programming language LOGO which could control a robot turtle with a physical pen in it. Kids would steer the robot around, and it would draw as it moved. Seymour said that the Turtle was, “an object to think with”. Many modern programming languages support Turtles, including Python.

Children playing with a Logo turtle robot that can draw with a pen

Figure 3: Children playing with a Logo turtle robot that could draw with a pen

Today, we can play with virtual turtles in a fully-graphical and non-robotic way. Below is a Python program that first creates a Screen object (object of the Screen class) for the turtle to draw on and then creates a Turtle object (object of the Turtle class). The program asks the turtle object to perform some of its behaviors (methods) like moving forward a set amount and turning. The turtle draws as it moves.

Click the Run button to see what this code does. The drawing will happen below the code.

Note

Notice that we tell alex the turtle what to do in the code above using dot notation: alex.forward(150), alex.left(90), and alex.forward(75). That is how you communicate with an object. You use the name of the turtle object followed by a . and then the name of the method that you want to execute.

Just by going forward and turning we can have a turtle object draw many things.

17.1.1. What does a left turn of 90 mean?

When we ask a turtle to turn left, it will turn left based on the direction it is currently heading. A turtle object keeps track of its heading (direction it is facing). Use the figure below to help you understand how much the turtle will turn if asked to turn left 90 degrees and it is currently heading east (0 degrees).

shows what a turn of each degrees means for left and right turns

Figure 1: The amount of turn for specified degrees for left and right turns

17.2. Practice with Turtles

Note

The following problems have a Help Me button. You can click on the Help Me button after you have made at least 3 full and distinct attempts to solve the problem to make the problem easier.

The following program uses a turtle to draw a capital L as shown below, but the lines are mixed up. The program should do all necessary set-up: import the turtle module, get the screen/space to draw on, and create the turtle. The turtle should turn to face south, draw a line that is 150 pixels long, then turn to face east, and draw a line that is 75 pixels long. We have added a compass to the picture to indicate the directions north, south, west, and east. Drag the needed blocks of statements from the left column to the right column and put them in the right order. There may be additional blocks that are not needed in a correct solution. Then click on Check to see if you are right. You will be told if any of the lines are in the wrong order or are the wrong blocks.

../_images/TurtleL4.png

The following program uses a turtle to draw a checkmark as shown below but the lines are mixed up. The program should do all necessary set-up: import the turtle module, get the screen/space to draw on, and create the turtle. The turtle should turn to face southeast, draw a line that is 75 pixels long, then turn to face northeast, and draw a line that is 150 pixels long. We have added a compass to the picture to indicate the directions north, south, west, and east. Northeast is between north and east. Southeast is between south and east. Drag the needed blocks of statements from the left column to the right column and put them in the right order. There may be additional blocks that are not needed in a correct solution. Then click on Check to see if you are right. You will be told if any of the lines are in the wrong order or are the wrong blocks.

../_images/checkMark.png

Click the Run button to see what this code does. The drawing will happen below the code.

The following example has 4 errors. Can you fix the errors so that the code runs correctly to print a capital L?

Fix the code below. Error messages will shown up below the code. The drawing will also happen below the code.

The following example has 4 errors. Can you fix the errors so that the code runs correctly to print a capital C?

Fix the code below. Error messages will shown up below the code. The drawing will also happen below the code.

Note

Case matters in Python so screen is not the same as Screen. Also the open and close parentheses are required after every function and procedure call, even if it doesn’t take any input.

Use the area below to try to draw a letter or number. Use block style rather than curves.

You have attempted of activities on this page