turtle 模塊以麵向對象和麵向過程的方式提供 turtle 圖形基元。由於它使用Tkinter作為基礎圖形,因此需要安裝有Tk支持的Python版本。
turtle .right()
turtle.right()方法用於通過其參數值來更改 turtle 的方向。它使 turtle 的頭部朝一個方向移動。
用法:
turtle.right(angle)
它接受的參數是angle {一個數字(整數或浮點數)}。因此,它以角度單位向右轉。 (單位默認為度,但可以通過degrees()和radians()函數進行設置。)角度方向取決於模式。
下麵是上述方法的實現和一些示例:
範例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)
輸出:
範例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)
輸出:
相關用法
- Python next()用法及代碼示例
- Python set()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python Decimal exp()用法及代碼示例
- Python shutil.which()用法及代碼示例
- Python os.minor()用法及代碼示例
- Python os.sched_rr_get_interval()用法及代碼示例
- Python os.sched_get_priority_min()用法及代碼示例
- Python os.sched_setaffinity()用法及代碼示例
- Python os.sched_get_priority_max()用法及代碼示例
- Python os.sched_getaffinity()用法及代碼示例
- Python os.major()用法及代碼示例
- Python os.ftruncate()用法及代碼示例
- Python os.truncate()用法及代碼示例
- Python os.fsdecode()用法及代碼示例
- Python os.wait()用法及代碼示例
- Python sympy.div()用法及代碼示例
- Python os.setgroups()用法及代碼示例
注:本文由純淨天空篩選整理自deepanshu_rustagi大神的英文原創作品 turtle.right() method in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。