Python中的turtle.right()方法

Python中的turtle.right()方法

turtle模块以面向对象和面向过程的方式提供Turtle图形基元。因为它使用 Tkinter 作为底层图形,它需要安装一个支持 Tk 的 Python 版本。

turtle.right()

turtle.right()方法用于通过它的参数值来改变Turtle的方向。它给出了Turtle头部移动的方向。

语法:

turtle.right(angle)

它接受的参数是角度{一个数字(整数或浮点数)}。所以,它把Turtle向右转的角度单位。(单位默认为度,但可以通过 degrees() 和 radians() 函数设置)。角度方向取决于模式。

下面是上述方法的实现和一些例子。

示例 1:

# 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)

输出 :

Python中的turtle.right()方法

示例 2:

# 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)

输出 :

Python中的turtle.right()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Python Turtle