turtle.home() function in Python
Last Updated :
21 Jul, 2020
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
turtle.home()
This function is used to move the turtle to the origin i.e. coordinates (0,0). Whatever, the position of the turtle is, it sets to (0,0) with default direction (facing to east).
Syntax :
turtle.home()
Below is the implementation of the above method with some examples :
Example 1 :
Python3
import turtle
print (turtle.position())
turtle.forward( 100 )
print (turtle.position())
turtle.home()
print (turtle.position())
turtle.right( 90 )
turtle.forward( 100 )
print (turtle.position())
turtle.home()
print (turtle.position())
|
Output :
(0.0, 0.0)
(100.0, 0.0)
(0.0, 0.0)
(0.0, -100.0)
(0.0, 0.0)
Example 2 :
Python3
import turtle
turtle.speed( 10 )
def fxn():
turtle.circle( 50 , 180 )
turtle.right( 90 )
turtle.circle( 50 , 180 )
for i in range ( 12 ):
fxn()
turtle.up()
turtle.home()
turtle.down()
turtle.left( 30 * (i + 1 ))
|
Output :
Share your thoughts in the comments
Please Login to comment...