SlideShare a Scribd company logo
Turtle Graphics
The turtle MODULE
Python allows you to import extra modules,
specifically written for Python users.
One of them is called turtle. You must import it
to use it. You can then open a graphics window.
import turtle # so we can use
the turtles library of commands
win = turtle.Screen()
# creates a graphics window
The Turtle CLASS
A Turtle is an example of class. ( turtle.Turtle())
When you create a new turtle it is called an
INSTANCE. You can also call it an OBJECT.
import turtle
win = turtle.Screen()
#make an instance of a turtle and we
will call it delia
delia = turtle.Turtle()
Turtle attributes
Now you have an object called delia, you can
give the turtle unique characteristics or
ATTRIBUTES like shape and speed.
The list of attributes you give to the
Turtle will make delia a unique
turtle.
Example
Predict the shape that the Turtle delia will draw
following the algorithm below.
Examples of some more attributes and instructions
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
import turtle
skk = turtle.Turtle()
for i in range(4):
skk.forward(50)
skk.right(90)
turtle.done()
star = turtle.Turtle()
star.right(75)
star.forward(100)
for i in range(4):
star.right(144)
star.forward(100)
turtle.done()
wn = turtle.Screen()
wn.bgcolor("light green")
skk = turtle.Turtle()
skk.color("blue")
def sqrfunc(size):
for i in range(4):
skk.fd(size)
skk.left(90)
size = size + 5
sqrfunc(6)
sqrfunc(26)
sqrfunc(46)
sqrfunc(66)
sqrfunc(86)
sqrfunc(106)
sqrfunc(126)
sqrfunc(146)
Class Task
• Create two instances of a turtle.
• Call them delia and arthur.
• delia is to go to position (50,50) and draw a square with
that as centre. She then has to go to these 3 points,
without leaving a trail, and stamp the 3 points …(-30,30),
(100,-50), (0,0)
• arthur is to draw two circles. One of radius 50 centre(0,0) and
another of radius 40 centre (100,-50). Also the circles are to be
filled with colours.
Challenge
• Ask the user for the coordinates of the centre of a
circle, a radius and a fill colour.
• Get these properties for both delia and arthur
and instruct them to draw the circles.
• Finish with a stamp on the centre.
• Write on each circle the properties given by the user.
• For example “This is a red circle, centre (30,-30) and radius 45.”

More Related Content

Similar to Graphic programming using Turtle class in Python (20)

DDU Workshop Day-2 presentation (1).pptx
DDU Workshop Day-2 presentation (1).pptxDDU Workshop Day-2 presentation (1).pptx
DDU Workshop Day-2 presentation (1).pptx
ritu23mts5729
 
Pa1 turtle
Pa1 turtlePa1 turtle
Pa1 turtle
aiclub_slides
 
1. Python Turtle.pptx
1. Python Turtle.pptx1. Python Turtle.pptx
1. Python Turtle.pptx
PreranaVarshney
 
An Introduction To Python - Graphics
An Introduction To Python - GraphicsAn Introduction To Python - Graphics
An Introduction To Python - Graphics
Blue Elephant Consulting
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Learning shape with python
Learning shape with pythonLearning shape with python
Learning shape with python
MichelleShie
 
434832905-392582079-python-turtle-cheat-sheets.pdf
434832905-392582079-python-turtle-cheat-sheets.pdf434832905-392582079-python-turtle-cheat-sheets.pdf
434832905-392582079-python-turtle-cheat-sheets.pdf
DurgaDeviP2
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
MODULE III.pptx
MODULE III.pptxMODULE III.pptx
MODULE III.pptx
Sangeeth39
 
Shivam PPT.pptx
Shivam PPT.pptxShivam PPT.pptx
Shivam PPT.pptx
ShivamDenge
 
NPTEL complete.pptx.pptx
NPTEL complete.pptx.pptxNPTEL complete.pptx.pptx
NPTEL complete.pptx.pptx
HimanshuKushwah38
 
Python for Scientific Computing
Python for Scientific ComputingPython for Scientific Computing
Python for Scientific Computing
Albert DeFusco
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
OSU Open Source Lab
 
Government Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxGovernment Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptx
ShivamDenge
 
NPTEL_SEM_3.pdf
NPTEL_SEM_3.pdfNPTEL_SEM_3.pdf
NPTEL_SEM_3.pdf
22mc10sh584
 
Pa2 session 1
Pa2 session 1Pa2 session 1
Pa2 session 1
aiclub_slides
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Mohamed Abdallah
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptx
hothyfa
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
Mohamed Ramadan
 
ComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.pptComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.ppt
oscarJulianPerdomoCh1
 
DDU Workshop Day-2 presentation (1).pptx
DDU Workshop Day-2 presentation (1).pptxDDU Workshop Day-2 presentation (1).pptx
DDU Workshop Day-2 presentation (1).pptx
ritu23mts5729
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Learning shape with python
Learning shape with pythonLearning shape with python
Learning shape with python
MichelleShie
 
434832905-392582079-python-turtle-cheat-sheets.pdf
434832905-392582079-python-turtle-cheat-sheets.pdf434832905-392582079-python-turtle-cheat-sheets.pdf
434832905-392582079-python-turtle-cheat-sheets.pdf
DurgaDeviP2
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
MODULE III.pptx
MODULE III.pptxMODULE III.pptx
MODULE III.pptx
Sangeeth39
 
Python for Scientific Computing
Python for Scientific ComputingPython for Scientific Computing
Python for Scientific Computing
Albert DeFusco
 
Government Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxGovernment Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptx
ShivamDenge
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Mohamed Abdallah
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptx
hothyfa
 
ComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.pptComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.ppt
oscarJulianPerdomoCh1
 

More from KanadamKarteekaPavan1 (8)

Market research analysis in Fundamentals of IDE workshop
Market research  analysis in Fundamentals of IDE workshopMarket research  analysis in Fundamentals of IDE workshop
Market research analysis in Fundamentals of IDE workshop
KanadamKarteekaPavan1
 
Vehicle Number Plate Detection_ppt_Rajeev.pptx
Vehicle Number Plate Detection_ppt_Rajeev.pptxVehicle Number Plate Detection_ppt_Rajeev.pptx
Vehicle Number Plate Detection_ppt_Rajeev.pptx
KanadamKarteekaPavan1
 
Python Fundamental Data structures: Dictionaries
Python Fundamental Data structures: DictionariesPython Fundamental Data structures: Dictionaries
Python Fundamental Data structures: Dictionaries
KanadamKarteekaPavan1
 
PYTHON Data structures Fundamentals: DICTIONARIES
PYTHON Data structures Fundamentals: DICTIONARIESPYTHON Data structures Fundamentals: DICTIONARIES
PYTHON Data structures Fundamentals: DICTIONARIES
KanadamKarteekaPavan1
 
Prime finding- sieve Method- Finding Anagrams numpy
Prime finding- sieve Method- Finding Anagrams numpyPrime finding- sieve Method- Finding Anagrams numpy
Prime finding- sieve Method- Finding Anagrams numpy
KanadamKarteekaPavan1
 
Varioius types of Neural Networks- An introduction
Varioius types of Neural Networks- An introductionVarioius types of Neural Networks- An introduction
Varioius types of Neural Networks- An introduction
KanadamKarteekaPavan1
 
Introduction to Soft Computing - Presentation
Introduction to Soft Computing - PresentationIntroduction to Soft Computing - Presentation
Introduction to Soft Computing - Presentation
KanadamKarteekaPavan1
 
Chapter-1.ppt
Chapter-1.pptChapter-1.ppt
Chapter-1.ppt
KanadamKarteekaPavan1
 
Market research analysis in Fundamentals of IDE workshop
Market research  analysis in Fundamentals of IDE workshopMarket research  analysis in Fundamentals of IDE workshop
Market research analysis in Fundamentals of IDE workshop
KanadamKarteekaPavan1
 
Vehicle Number Plate Detection_ppt_Rajeev.pptx
Vehicle Number Plate Detection_ppt_Rajeev.pptxVehicle Number Plate Detection_ppt_Rajeev.pptx
Vehicle Number Plate Detection_ppt_Rajeev.pptx
KanadamKarteekaPavan1
 
Python Fundamental Data structures: Dictionaries
Python Fundamental Data structures: DictionariesPython Fundamental Data structures: Dictionaries
Python Fundamental Data structures: Dictionaries
KanadamKarteekaPavan1
 
PYTHON Data structures Fundamentals: DICTIONARIES
PYTHON Data structures Fundamentals: DICTIONARIESPYTHON Data structures Fundamentals: DICTIONARIES
PYTHON Data structures Fundamentals: DICTIONARIES
KanadamKarteekaPavan1
 
Prime finding- sieve Method- Finding Anagrams numpy
Prime finding- sieve Method- Finding Anagrams numpyPrime finding- sieve Method- Finding Anagrams numpy
Prime finding- sieve Method- Finding Anagrams numpy
KanadamKarteekaPavan1
 
Varioius types of Neural Networks- An introduction
Varioius types of Neural Networks- An introductionVarioius types of Neural Networks- An introduction
Varioius types of Neural Networks- An introduction
KanadamKarteekaPavan1
 
Introduction to Soft Computing - Presentation
Introduction to Soft Computing - PresentationIntroduction to Soft Computing - Presentation
Introduction to Soft Computing - Presentation
KanadamKarteekaPavan1
 
Ad

Recently uploaded (20)

What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Ad

Graphic programming using Turtle class in Python

  • 2. The turtle MODULE Python allows you to import extra modules, specifically written for Python users. One of them is called turtle. You must import it to use it. You can then open a graphics window. import turtle # so we can use the turtles library of commands win = turtle.Screen() # creates a graphics window
  • 3. The Turtle CLASS A Turtle is an example of class. ( turtle.Turtle()) When you create a new turtle it is called an INSTANCE. You can also call it an OBJECT. import turtle win = turtle.Screen() #make an instance of a turtle and we will call it delia delia = turtle.Turtle()
  • 4. Turtle attributes Now you have an object called delia, you can give the turtle unique characteristics or ATTRIBUTES like shape and speed. The list of attributes you give to the Turtle will make delia a unique turtle.
  • 5. Example Predict the shape that the Turtle delia will draw following the algorithm below.
  • 6. Examples of some more attributes and instructions
  • 7. from turtle import * color('red', 'yellow') begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done() import turtle skk = turtle.Turtle() for i in range(4): skk.forward(50) skk.right(90) turtle.done()
  • 8. star = turtle.Turtle() star.right(75) star.forward(100) for i in range(4): star.right(144) star.forward(100) turtle.done() wn = turtle.Screen() wn.bgcolor("light green") skk = turtle.Turtle() skk.color("blue") def sqrfunc(size): for i in range(4): skk.fd(size) skk.left(90) size = size + 5 sqrfunc(6) sqrfunc(26) sqrfunc(46) sqrfunc(66) sqrfunc(86) sqrfunc(106) sqrfunc(126) sqrfunc(146)
  • 9. Class Task • Create two instances of a turtle. • Call them delia and arthur. • delia is to go to position (50,50) and draw a square with that as centre. She then has to go to these 3 points, without leaving a trail, and stamp the 3 points …(-30,30), (100,-50), (0,0) • arthur is to draw two circles. One of radius 50 centre(0,0) and another of radius 40 centre (100,-50). Also the circles are to be filled with colours.
  • 10. Challenge • Ask the user for the coordinates of the centre of a circle, a radius and a fill colour. • Get these properties for both delia and arthur and instruct them to draw the circles. • Finish with a stamp on the centre. • Write on each circle the properties given by the user. • For example “This is a red circle, centre (30,-30) and radius 45.”