Saturday, December 28, 2024
Google search engine
HomeLanguagesturtle.home() function in Python

turtle.home() function in Python

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 package
import turtle
  
  
# check turtle position
print(turtle.position())
  
# motion
turtle.forward(100)
  
# check turtle position
print(turtle.position())
  
# set turtle to home
turtle.home()
  
# check turtle position
print(turtle.position())
  
# motion
turtle.right(90)
turtle.forward(100)
  
# check turtle position
print(turtle.position())
  
# set turtle to home
turtle.home()
  
# check turtle position
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 package
import turtle
  
  
# set turtle speed to fastest
# for bettrt understandings
turtle.speed(10)
  
# method to draw a part
def fxn():
    
  # motion
  turtle.circle(50,180)
  turtle.right(90)
  turtle.circle(50,180)
  
# loop to draw pattern
for i in range(12):
  fxn()
    
  # set turtle at home
  turtle.up()
  turtle.home()
  turtle.down()
    
  # set position
  turtle.left(30*(i+1))


Output :

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments