Get the position of the Turtle in Python

How do I find the coordinate of a turtle in python?

For example, if the turtle is in (200, 300)

, how would you get that position?

+3
python turtle-graphics


source to share


3 answers


As shown in the python documentation turtle.pos () is the best solution



+1


source to share


turtle documentation says it turtle.pos()

gets the position as Vec2D

vector.



+2


source to share


I wanted to know if turtle1 and turtle2 were at the same coordinate i if turtle1.pos () == turtle2.pos ()

Yes, but since the turtle is playing on a floating point plane, this can cause you problems when they are close but not exactly on top of each other. You will probably be better off with a test like:

turtle1.distance(turtle2) < 0.1

      

those. this distance between centers is less than a certain factor that you define. If you want to know if parts of the turtle overlap (for example touching the feet) your fuzz factor can be as high as 10.0

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics