0% found this document useful (0 votes)
3 views12 pages

201 Turtle Module

The document provides an overview of the Python turtle module, which allows for drawing graphics. It covers various functionalities such as moving the turtle, changing speed, naming the turtle, altering direction, and using preset shapes. Additionally, it includes exercises and tips for using the turtle module effectively, including managing coordinates and pen settings.

Uploaded by

phoopwintthit19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views12 pages

201 Turtle Module

The document provides an overview of the Python turtle module, which allows for drawing graphics. It covers various functionalities such as moving the turtle, changing speed, naming the turtle, altering direction, and using preset shapes. Additionally, it includes exercises and tips for using the turtle module effectively, including managing coordinates and pen settings.

Uploaded by

phoopwintthit19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Drawing Graphic

Secondary 1

Hein Thu Aung


Turtle Module
• turtle.Turtle is the python module in python
that works like a drawing board.
• Do not give the file name to turtle.py

import turtle
turtle.Turtle()

Hein Thu Aung


Steps
• turtle.forward(steps) function makes the
turtle move.
• Steps are measured in pixels.

import turtle
turtle.Turtle() [not working
in web version]
turtle.forward(100)

Hein Thu Aung


Speed
turtle.speed() – turtle’s speed lies in the range 1-
10.
• 0 is the fastest. 1 is slowest.
import turtle
turtle.Turtle() [not working in web version]
turtle.speed(1)
turtle.forward(100)

• Try turtle moving in backward direction.

Hein Thu Aung


Naming Turtle
• Let’s give a name to turtle.
• After giving name, you can use name for turtle
function.

import turtle
Try name.fd and name.bk
name = turtle.Turtle()
in place of name.forward
name.speed(1)
and name.backward.
name.forward(100)

Hein Thu Aung


Changing Direction
turtle.direction(degree) changes the direction of
the turtle.
• The turtle always face to right at the start.

import turtle
name = turtle.Turtle() Move the turtle for 100
name.speed(1) pixels, turn left and move
name.forward(100) again for 100 pixels.
name.right(90)

Hein Thu Aung


Exercise
• Using loop, draw a square in turtle module.
• Draw a circle. [Hint: Distance should be 1]

Instead of right and left, try rt and lt.

• Draw pentagon, hexagon and decagon using


turtle module.
• Draw a pentacle (star-shape).

Hein Thu Aung


Preset Shapes
There are some preset shapes you can use in
Python.

import turtle import turtle


name = turtle.Turtle() name = turtle.Turtle()
name.circle(radius) name.dot(radius)

Try turtle.done() at the end of the code.

Hein Thu Aung


Getting Screen & Changing Background
• Sometimes, you need to get a screen to create turtle project.
• screen_name = turtle.getscreen() lets you open a new window.
• turtle.bgcolor(“color name”) changes the color of the screen instead of
white.
• Try “blue”, “green”, “yellow”, “red” or different colors.
• This might not work in web versions.

import turtle
import turtle
screen_name = turtle.getscreen()
screen_name = turtle.getscreen()
turtle.bgcolor(“blue”)
name = turtle.Turtle()
name = turtle.Turtle()

Hein Thu Aung


Coordinates
• The center of the screen is noted as (0, 0).
• All the coordinates are noted in (x, y) fashion.
• name.goto(x, y) makes your turtle to the
location of coordinates x and y.

import turtle
name = turtle.Turtle()
name.goto(100, 100)
name.goto(100, -100) Try name.home()
name.goto(-100, -100)
name.goto(-100, 100)

Hein Thu Aung


Pen
• Python uses pen to draw things on screen.
• Pen size can be changed by using
name.pensize(size).

import turtle
name = turtle.Turtle()
name.pensize(5) Try name.pencolor(“green”)
name.speed(1)
name.forward(100)

Hein Thu Aung


Up & Down
• Sometimes we need to move the turtle without drawing
anything.
• penup is used to stop drawing on screen like moving up pen
on a paper without touching the paper.
• pendown is used to draw again on screen.

import turtle
name = turtle.Turtle()
name.penup()
Draw an “X” on the screen.
name.goto(100, 100)
name.pendown()
name.goto(-100, -100)

Hein Thu Aung

You might also like