How to get the position of the turtle?

30,844

Solution 1

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

Solution 2

The turtle documentation says that turtle.pos() gets the position as a Vec2D vector.

Solution 3

I wanted to know if turtle1 and turtle2 were on the same coordinate I would do if turtle1.pos() == turtle2.pos()

Yes, but since the turtle plays on a floating point plane, this might cause you trouble when they are close but not exactly atop each other. You'll probably be better off with a test like:

turtle1.distance(turtle2) < 0.1

I.e. is the distance between centers less than some fuzz factor that you determine. If you want to know if any turtle parts overlap (e.g. legs touching) then your fuzz factor may be as high as 10.0

Share:
30,844
User9123
Author by

User9123

Updated on February 20, 2022

Comments

  • User9123
    User9123 over 2 years

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

    For example, if the turtle is located at (200, 300), how would I retrieve that position?