turtle.setpos() and turtle.goto() functions 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.setpos()

This method is used to move the turtle to an absolute position. This method has Aliases: setpos, setposition, goto.

Syntax: turtle.setpos(x, y=None) or turtle.setposition(x, y=None) or turtle.goto(x, y=None)

Parameters:

x: x coordinate of a Vec2D-vector 



y: y coordinate of a Vec2D-vector

Below is the implementation of above method with some examples :

Example 1:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import package
import turtle 
  
# forward turtle by 100
turtle.forward(100)
  
# stamp the turtle shape
turtle.stamp()
  
# set the position by using setpos()
turtle.up()
turtle.setpos(-50,50)
turtle.down()
  
# forward turtle by 100
turtle.forward(100)
  
# stamp the turtle shape
turtle.stamp()
  
# set the position by using goto()
turtle.up()
turtle.goto(-50,-50)
turtle.down()
  
# forward turtle by 100
turtle.forward(100)

chevron_right


Output :

Example 2 :

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import package
import turtle 
  
# method to raw pattern
# of circle with rad radius
def draw(rad):
      
    # draw circle
    turtle.circle(rad)
      
    # set the position by using setpos()
    turtle.up()
    turtle.setpos(0,-rad)
    turtle.down()
  
# loop for pattern
for i in range(5):
    draw(20+20*i)

chevron_right


Output :




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.