turtle.setpos() and turtle.goto() functions in Python
Last Updated :
17 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.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
import turtle
turtle.forward(100)
turtle.stamp()
turtle.up()
turtle.setpos(-50,50)
turtle.down()
turtle.forward(100)
turtle.stamp()
turtle.up()
turtle.goto(-50,-50)
turtle.down()
turtle.forward(100)
|
Output :

Example 2 :
Python3
import turtle
def draw(rad):
turtle.circle(rad)
turtle.up()
turtle.setpos(0,-rad)
turtle.down()
for i in range(5):
draw(20+20*i)
|
Output :

Share your thoughts in the comments
Please Login to comment...