Python中的 turtle.tilt()函数
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
海龟.tilt()
此函数用于将海龟形状从其当前倾斜角度旋转一个角度,但不要改变海龟的航向(运动方向)。
句法 :
turtle.tilt(angle)
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# import package
import turtle
# set turtle screen
sc=turtle.Screen()
sc.setup(500,300)
# set turtle
turtle.speed(1)
turtle.up()
turtle.setpos(-200,0)
turtle.down()
turtle.shape("square")
turtle.width(2)
# motion
turtle.forward(200)
# tilt turtleshape by 45
turtle.tilt(45)
# motion
turtle.forward(200)
Python3
# import package
import turtle
# set screen
sc=turtle.Screen()
sc.setup(500,350)
# 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)
# tilt turtleshpae by 180
turtle.tilt(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 screen
sc=turtle.Screen()
sc.setup(500,350)
# 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)
# tilt turtleshpae by 180
turtle.tilt(180)
# print turtleshape
turtle.stamp()
# move to right by 60
turtle.right(60)
# hide the turtle
turtle.ht()
输出 :