image

11MORE TURTLE GRAPHICS

Let’s take another look at the turtle module we began using in Chapter 4. As you’ll see in this chapter, in Python, turtles can do a lot more than just draw plain black lines. For example, you can use them to draw more advanced geometric shapes, create different colors, and even fill your shapes with color.

STARTING WITH THE BASIC SQUARE

We’ve already learned how to make the turtle draw simple shapes. Before using the turtle, we need to import the turtle module and create the Pen object:

>>> import turtle>>> t = turtle.Pen()

Here’s the code we used to create a square in Chapter 4:

>>> t.forward(50)>>> t.left(90)>>> t.forward(50) ...

Get Python for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.