Python turtle set direction of a turtle to another turtle

限于喜欢 提交于 2021-01-29 13:40:25

问题


I am using python 3.6 and turtle module. I have two turtles in another coordinates. how do i set the angle of turtle_1 to the direction of turtle_2?


回答1:


turtle_1.setheading(turtle_1.towards(turtle_2))

This is typically used if you want turtle_1 to chase turtle_2. The argument to towards() is flexible. Besides another turtle, it can also be separate X and Y arguments, or a tuple coordinate pair. If you simply want turtle_1 to point in the same direction as turtle_2:

turtle_1.setheading(turtle_2.heading())


来源:https://stackoverflow.com/questions/53893541/python-turtle-set-direction-of-a-turtle-to-another-turtle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!