Python中的 turtle.right() 方法
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
乌龟.right()
turtle.right() 方法用于通过它所接受的参数值来改变海龟的方向。它使乌龟的头部朝一个方向移动。
句法:
turtle.right(angle)
它采用的参数是角度 { 一个数字(整数或浮点数)}。因此,它以角度单位向右转动海龟。 (单位默认为度,但可以通过度()和弧度()函数设置。)角度方向取决于模式。
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# importing package
import turtle
# move the turtle forward by
# 100 unit distance in the
# direction of head of turtle
turtle.forward(100)
# change the direction of turtle
# by 90 degrees to the right.
turtle.right(90)
# move the turtle forward by
# 100 unit distance in the
# direction of head of turtle
turtle.forward(100)
Python3
# importing package
import turtle
# Loop for pattern
for i in range(10):
# move the turtle forward by
# 100+variable unit distance
# in the direction of head of turtle
turtle.forward(100+10*i)
# change the direction of turtle
# by 90 degrees to the right.
turtle.right(90)
输出 :
示例 2:
Python3
# importing package
import turtle
# Loop for pattern
for i in range(10):
# move the turtle forward by
# 100+variable unit distance
# in the direction of head of turtle
turtle.forward(100+10*i)
# change the direction of turtle
# by 90 degrees to the right.
turtle.right(90)
输出 :