将 Python 乌龟指向特定坐标

Point a Python Turtle towards certain coordinates

有什么方法可以让海龟指向某个坐标

如有任何帮助,我们将不胜感激。

正如我在评论中所建议的,您可以使用一些三角函数来前往特定点:

target = (100,50)
d = math.degrees(math.atan2(*(target - turtle.pos())))
turtle.setheading(d)

您正在寻找的是 turtle.towards() 方法,该方法 returns 从乌龟的位置到目标的角度。可以和turtle.setheading()方法结合使用:

turtle.setheading(turtle.towards(x, y))

turtle.towards() 方法在参数方面是灵活的。它可以采用单独的 xy 值,一个组合的 (x, y) 元组,或者另一个目标位置的海龟。

这是一个普遍被忽视的方法,人们重新实现,以及 turtle.distance()