Python中的 turtle.seth()函数
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
海龟.seth()
此方法用于将海龟的方向设置为to_angle 。此方法只需要一个参数作为角度。
这两个是别名 - setheading , seth这个方法。
Syntax : turtle.seth(to_angle) or turtle.setheading(to_angle)
Argument:
to_angle: a number (integer or float)
Set the orientation of the turtle to to_angle. Here are some common directions in degrees (standard – mode) :
- 0 – east
- 90 – north
- 180 – west
- 270 – south
下面是上述方法的一个例子的实现:
例子:
Python3
# import package
import turtle
# set direction at 0
# angle using seth
turtle.seth(0)
# motion
turtle.forward(80)
turtle.write("East")
# back to home
turtle.home()
# set direction at 90
# angle using sethading
turtle.setheading(90)
# motion
turtle.forward(80)
turtle.write("North")
# back to home
turtle.home()
# set direction at 180
# angle using seth
turtle.seth(180)
# motion
turtle.forward(80)
turtle.write("West",align="right")
# back to home
turtle.home()
# set direction at 270
# angle using setheading
turtle.setheading(270)
# motion
turtle.forward(80)
turtle.write("South")
# hide the turtle
turtle.ht()
输出 :