1. 程式人生 > >用python畫個花朵

用python畫個花朵



#匯入turtle模組
import turtle
window=turtle.Screen()  #建立一個新視窗用於繪圖
babbage=turtle.Turtle() #建立一個名字叫babbage的turtle物件
babbage.color("green","black")
babbage.left(90)    #使babbage左轉90°
babbage.forward(100)    #向前移動了100畫素
babbage.right(90)   #右轉90°
babbage.color("black","black")
babbage.begin_fill()    #為圓填充顏色
babbage.circle(10)  #畫個半徑為10畫素的圓
babbage.end_fill()

#畫第N個花瓣
for i in range(1,24):
    if babbage.color()==("red","black"):
        babbage.color("orange","black")
    elif babbage.color()==("orange","black"):
        babbage.color("yellow","black")
    else:
          babbage.color("red","black")
    babbage.left(15)
    babbage.forward(50)
    babbage.left(157)
    babbage.forward(50)
babbage.hideturtle()

window.exitonclick()    #定義單擊視窗就可以將其關閉