1. 程式人生 > 其它 >python turtle模組(二) 畫圓

python turtle模組(二) 畫圓

注意點:
1、turtle.pu() 與turtle.penup()用法一樣 抬起畫筆
2、turtle.fd(r) 引數是距離值,移動多少距離,penddown時可以劃線 penup時可以移動
3、turtle.left(90) 逆時針轉動90度,turtle.right(90)是順時針轉動90度,注意是在當前角度上轉動90度
4、turtle.seth(60) 引數是畫筆的角度

'
def draw_a_circle(radius):

turtle.pendown()
turtle.circle(radius)

if __name__=="__main__":

r = 50

# 設定畫布
turtle.setup(1000, 1000, -r, 0)

# 畫第一個圓
draw_a_circle(r)

# 畫第二個圓,紅色,與第一個圓完全重合
turtle.pu()
turtle.fd(0)
turtle.pencolor("red")
draw_a_circle(r)

# 畫第三個圓,與第二個圓相交
turtle.pu()
turtle.fd(r)
turtle.pencolor("green")
draw_a_circle(r)

# 畫第四個圓,與第三個圓相切
turtle.pu()
turtle.fd(2*r)
turtle.pencolor("red")
draw_a_circle(r)

# 畫第五個圓,與第四個圓相離
turtle.pu()
turtle.fd(2.5 * r)
turtle.pencolor("red")
draw_a_circle(r)

# 畫第6個圓
turtle.right(90)
turtle.pencolor("green")
draw_a_circle(r)

# 畫第7個圓
turtle.left(180)
turtle.pencolor("green")
draw_a_circle(r)

# 畫第8個圓
turtle.left(90)
turtle.pencolor("green")
draw_a_circle(r)

# 畫第9個圓
turtle.settiltangle(60)
turtle.pencolor("red")
draw_a_circle(r)

# 畫一條直線 角度60
turtle.seth(60)
turtle.pencolor("red")
turtle.fd(100)

# 圖形完成後,不會立即退出,需要使用者點選關閉按鈕才會退出
turtle.exitonclick()

'