今天我們來學習一下使用Python畫小鴨子的方法吧!下面是我們的代碼:
# 導入turtle庫 import turtle # 設置畫筆寬度和顏色 turtle.pensize(4) turtle.pencolor("orange") # 畫小鴨子的頭 turtle.fillcolor("yellow") turtle.begin_fill() turtle.circle(100) turtle.end_fill() # 畫小鴨子的嘴巴 turtle.penup() turtle.goto(35, 120) turtle.pendown() turtle.right(60) turtle.forward(50) # 畫小鴨子的眼睛 turtle.penup() turtle.goto(-30, 160) turtle.pendown() turtle.fillcolor("black") turtle.begin_fill() turtle.circle(10) turtle.end_fill() # 畫小鴨子的身體 turtle.penup() turtle.goto(110, 70) turtle.pendown() turtle.fillcolor("yellow") turtle.begin_fill() turtle.right(150) turtle.forward(150) turtle.right(30) turtle.forward(100) turtle.right(120) turtle.forward(100) turtle.right(30) turtle.forward(150) turtle.end_fill() # 畫小鴨子的腳 turtle.penup() turtle.goto(70, -30) turtle.pendown() turtle.fillcolor("orange") turtle.begin_fill() turtle.right(30) turtle.forward(40) turtle.right(90) turtle.forward(20) turtle.right(90) turtle.forward(40) turtle.right(90) turtle.forward(20) turtle.end_fill() turtle.penup() turtle.goto(160, -30) turtle.pendown() turtle.fillcolor("orange") turtle.begin_fill() turtle.right(90) turtle.forward(40) turtle.right(90) turtle.forward(20) turtle.right(90) turtle.forward(40) turtle.right(90) turtle.forward(20) turtle.end_fill() # 顯示畫布 turtle.done()
運行上述代碼,你就可以看到一個非常可愛的小鴨子啦!