0% found this document useful (0 votes)
41 views13 pages

Turtle Graphics

Turtle graphics is a popular way to teach programming to kids using a turtle to draw graphics. It was introduced in the original Logo programming language in 1967. The document discusses how to import the turtle library, set up a drawing window, and control a turtle by setting its position, heading, and pen attributes to draw shapes and move around the screen. It also covers string operations like length, slicing, indexing, and methods to analyze, modify, and manipulate string content.

Uploaded by

ELAVARASI M
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)
41 views13 pages

Turtle Graphics

Turtle graphics is a popular way to teach programming to kids using a turtle to draw graphics. It was introduced in the original Logo programming language in 1967. The document discusses how to import the turtle library, set up a drawing window, and control a turtle by setting its position, heading, and pen attributes to draw shapes and move around the screen. It also covers string operations like length, slicing, indexing, and methods to analyze, modify, and manipulate string content.

Uploaded by

ELAVARASI M
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/ 13

Turtle graphics

Turtle attributes
Turtle graphics
• Turtle graphics is a popular way for
introducing programming to kids. It was part
of the original Logo programming language
developed by Wally Feurzeig, Seymour Papert
and Cynthia Solomon in 1967.
• Create graphics with a graphics window x,y
coordinates.
Create a turtle
• 1. import turtle
• 2.create turtle control
• 3. draw around using the turtle methods
• 4.run turtle.done()
Import turtle
from turtle import *
or
Import turtle
-> the turtle library make all the turtle functions
and drawing board, and a turtle
Ex:
Import turtle
Turtle.setup(800,600)
W=turtle.screen()
w.title(“python”)
w.bgcolor(‘red’)
w=turtle.getturtle()
Turtle attributes
• Position
• Heading
• Pen attribute

1.Position
It return turtle current position. The position
change by using setposition() specify the x,y
coordinates.
Heading/relative positioning
• It is also used to change the positioning
1. left(angle)
2. right(angle)
3. forward(distance)
4. backward(distance)
Pen attribute
a) penup()- the pen move without line drawn
b) pendown()- the pen ready to draw line
c) Pensize(pixels)-width of the drawing
d) Pencolor(0-255)
Additional attribute
1)Turtle visibility
Showturtle() & hideturtle()
2)Size
resizemode(‘user’)
turtlesize(size)
3)Shape
shape()-arrow,turtle,circle,square,triangle, classic
4)Fillcolor
fillcolor(color)-shape fill color
5)Speed
Speed(0to10)
Normal=6
string
• String - Set of characters (or) sequence of
characters.
(letter, digit, special character)
• String processing – operation performed in
string. i.e accessed, analysed, updated.
String operation
• Length- length of the string
s=‘string’
print(len(s))->6
• Select-select the char at position
print(s[5]) -> n
• Slice- slice the string
print(s[2:5]) -> trin
• Index – give the index of character
print(s.index(r)) -> 3
• Count – count number of values
print(count(‘s’)) -> 1
• Membership – check the char is in that string
print(‘i’ in s) -> True
• Concatenation- added more string to original
print(s+’char’) -> stringchar
• Maximum value – maximum character in string
print(max(s)) -> t
• Minimum value- minimum value of string
print(min(s)) -> a
• Comparision – compare twostring
print(s==e)
String methods
• Check the content of the string
isalpha(), isdigit(), isupper(), islower(), upper(), lower()
• Searching the content
find(w)
• Replace the content
replace(w,t)
• Remove the content
strip(w)
• Splitting the content
Split(w)

You might also like