0% found this document useful (0 votes)
16 views8 pages

PYTHON CHAP 4 - Drawing With Turtles

This chapter discusses using the Python turtle module to draw basic shapes and lines. It introduces importing the turtle module, creating a turtle object called t that acts as a pen, and using t's methods like forward(), left(), etc. to draw a box without corners by moving the pen around the screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

PYTHON CHAP 4 - Drawing With Turtles

This chapter discusses using the Python turtle module to draw basic shapes and lines. It introduces importing the turtle module, creating a turtle object called t that acts as a pen, and using t's methods like forward(), left(), etc. to draw a box without corners by moving the pen around the screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PYTHON CHAPTER 4

Drawing with Turtles


Turtle
The turtle is a nice way to learn some of the basics of
computer graphics, so in this chapter, we’ll use a Python
turtle to draw some simple shapes and lines.
>>> import turtle Importing a module tells Python that you want to use it

Creating a Canvas
Now that we have imported the turtle module, we need to create a
Canvas - a blank space to draw on, like an artist’s canvas. To do so,
we call the function Pen from the turtle module, which automatically
creates a canvas. Enter this into the Python shell:

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

t = turtle.Pen()

t.forward(50)

t.left(90)
import turtle t.backward(100)
t = turtle.Pen() t.up()
t.right(90)
t.forward(50) t.forward(20)
t.left(90) t.left(90)
t.forward(50) t.down()
t.left(90) t.forward(100)
t.forward(50)
t.left(90)
t.forward(50)

t.reset()
A Box Without Corners
Write a program to draw the four lines shown here (the
size isn’t important, just the shape):
TIPS
#importing turtle module
import turtle

#Initialising the turtle object


tt = turtle.Turtle()

#using built-in function to draw a circle


radius = 100
tt.circle(100)

# Finish by turtle.done() command


turtle.done()

You might also like