9More Turtle Graphics

Image

Let’s return to the turtle module we began using in Chapter 4. In this chapter, we’ll learn that Python turtles can do a lot more than draw plain black lines. 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 previously used the turtle module to draw simple shapes. Let’s import the turtle module and create the Turtle object:

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

We used the following code in Chapter 4 to create a square:

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

Get Python for Kids, 2nd Edition 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.