turtle module in python code example
Example 1: how to import turtle in python
import turtle
whateverYouWantToCallIt = turtle.Turtle()
whateverYouWantToCallIt.forward(10)
whateverYouWantToCallIt.color("purple")
whateverYouWantToCallIt.left(90)
whateverYouWantToCallIt.right(90)
Example 2: turtle python
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
Example 3: python turtle tutorial
>>> turtle.position()
(0.00,0.00)
>>> turtle.backward(30)
>>> turtle.position()
(-30.00,0.00)
Example 4: python turtle tutorial
>>> tp = turtle.pos()
>>> tp
(0.00,0.00)
>>> turtle.setpos(60,30)
>>> turtle.pos()
(60.00,30.00)
>>> turtle.setpos((20,80))
>>> turtle.pos()
(20.00,80.00)
>>> turtle.setpos(tp)
>>> turtle.pos()
(0.00,0.00)
Example 5: python turtle tutorial
>>> turtle.heading()
22.0
>>> turtle.right(45)
>>> turtle.heading()
337.0
Example 6: python turtle tutorial
>>> turtle.heading()
22.0
>>> turtle.left(45)
>>> turtle.heading()
67.0