Turtle模塊以麵向對象和麵向過程的方式提供了Turtle圖形基元。由於它使用Tkinter作為基礎圖形,因此需要安裝有Tk支持的Python版本。
turtle .circle():
此方法用於繪製具有給定半徑的圓。
用法: turtle.circle(radius, extent=None, steps=None)
Parameters:
- radius:圓的半徑。
- extent:圓的度數,以弧為單位。
- steps:將形狀劃分為相等數量的給定步驟。
下麵是上述方法的實現和一些示例:
範例1:
Python3
# importing turtle package
import turtle
# draw circle of radius
# 80 pixel
turtle.circle(80)
輸出:
範例2:
Python3
# importing turtle package
import turtle
# draw circle of radius 80
# pixel and extent = 180
# so it draw half circle
turtle.circle(80,
extent = 180)
輸出:
範例3:
Python3
# importing turtle package
import turtle
# draw circle of radius 80
# pixel and steps = 5
# so it draw pentagon with
# equal length 5 sides
turtle.circle(80,
steps = 5)
輸出:
相關用法
注:本文由純淨天空篩選整理自deepanshu_rustagi大神的英文原創作品 turtle.circle() method in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。