Python中的 turtle.settiltangle()函数
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
乌龟.settiltangle()
此函数用于旋转海龟形状以指向角度指定的方向,而不管其当前的倾斜角度如何。它不会改变海龟的航向,即运动方向。
Syntax : turtle.settiltangle(angle)
Parameter:
angle: This method is similar to turtle.tilt() method ( tilt the turtle by angle as input to the current direction ) but turtle.settiltangle() method set the tilt angle as input without taking the current direction.
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# import package
import turtle
# set turtle position
turtle.up()
turtle.setpos(-100,0)
turtle.down()
# set turtle speed
turtle.speed(1)
# set tilt angle to 90
turtle.settiltangle(90)
# motion
turtle.forward(100)
# set tilt angle to 270 (not 90+270=360)
turtle.settiltangle(270)
# motion
turtle.forward(100)
Python3
# import package
import turtle
# set turtle
turtle.speed(1)
turtle.up()
turtle.setpos(-50,100)
turtle.down()
turtle.shape("turtle")
turtle.width(2)
# loop for pattern
for i in range(6):
# motion
turtle.forward(100)
# set tilt angle by 180
turtle.settiltangle(180)
# print turtleshape
turtle.stamp()
# move to right by 60
turtle.right(60)
# hide the turtle
turtle.ht()
输出 :
示例 2:
Python3
# import package
import turtle
# set turtle
turtle.speed(1)
turtle.up()
turtle.setpos(-50,100)
turtle.down()
turtle.shape("turtle")
turtle.width(2)
# loop for pattern
for i in range(6):
# motion
turtle.forward(100)
# set tilt angle by 180
turtle.settiltangle(180)
# print turtleshape
turtle.stamp()
# move to right by 60
turtle.right(60)
# hide the turtle
turtle.ht()
输出 :