Python乌龟将乌龟的方向设置为另一只乌龟 [英] Python turtle set direction of a turtle to another turtle

查看:41
本文介绍了Python乌龟将乌龟的方向设置为另一只乌龟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python 3.6 和乌龟模块.我在另一个坐标中有两只乌龟.如何将turtle_1的角度设置为turtle_2的方向?

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?

推荐答案

turtle_1.setheading(turtle_1.towards(turtle_2))

如果您希望 turtle_1 chase turtle_2,通常会使用此方法.towards() 的参数是灵活的.除了另一个海龟,它也可以是单独的 X 和 Y 参数,或元组坐标对.如果您只是想让 turtle_1 指向与 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())

这篇关于Python乌龟将乌龟的方向设置为另一只乌龟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆