Turtle is a special feature of Python. Using Turtle, we can easily draw in a drawing board.
First, we import the turtle module. Then create a window after that we create turtle object and using turtle object we can draw in the drawing board.
Some turtle method
Example Code 1
# import turtle library
import turtle
my window = turtle. Screen ()
my window. bgcolour ("blue") # creates a graphics window
my pen = turtle. Turtle ()
my pen. Forward (150)
my pen. Left (90)
my pen. forward (75)
my pen. Colour ("white")
my pen. pen size (12)
Output 1
Example Code 2
# import turtle library
import turtle
colours = [ "red", "purple", "blue", "green", "orange", "yellow"]
my pen = turtle. Pen ()
turtle. bgcolor ("black")
for x in range (360):
my pen. pen colour (colours [x % 6])
my pen. width (x/100 + 1)
my pen. forward (x)
my pen. left (59)
Output 2
Example Code 3
# import turtle library
import turtle
my_wn = turtle. Screen ()
turtle. speed (2)
for i in range (30):
turtle. circle (5*i)
turtle. circle (-5*i)
turtle. left (i)
turtle. exitonclick ()
Output 3
Comments