Python是一種廣泛使用的編程語言,可以用于編寫各種應(yīng)用程序,包括繪圖和圖像處理。今天我們將使用Python來繪制一只可愛的柯基犬!
import turtle # 設(shè)置畫筆屬性 turtle.pensize(4) turtle.pencolor("#8B4513") turtle.fillcolor("#8B4513") # 繪制狗頭 turtle.begin_fill() turtle.circle(50) turtle.end_fill() # 繪制耳朵 turtle.penup() turtle.goto(30, 150) turtle.pendown() turtle.begin_fill() turtle.circle(20) turtle.end_fill() turtle.penup() turtle.goto(-30, 150) turtle.pendown() turtle.begin_fill() turtle.circle(20) turtle.end_fill() # 繪制眼睛 turtle.fillcolor("#FFFFFF") turtle.penup() turtle.goto(20, 60) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(-20, 60) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() # 繪制眼珠 turtle.fillcolor("#000000") turtle.penup() turtle.goto(20, 65) turtle.pendown() turtle.begin_fill() turtle.circle(5) turtle.end_fill() turtle.penup() turtle.goto(-20, 65) turtle.pendown() turtle.begin_fill() turtle.circle(5) turtle.end_fill() # 繪制嘴巴 turtle.fillcolor("#FFCC99") turtle.penup() turtle.goto(0, 40) turtle.pendown() turtle.begin_fill() turtle.circle(15) turtle.end_fill() # 繪制身體 turtle.fillcolor("#FFFFFF") turtle.penup() turtle.goto(0, -50) turtle.pendown() turtle.begin_fill() turtle.circle(80) turtle.end_fill() # 繪制腿 turtle.fillcolor("#8B4513") turtle.penup() turtle.goto(40, -80) turtle.pendown() turtle.begin_fill() turtle.circle(20) turtle.end_fill() turtle.penup() turtle.goto(-40, -80) turtle.pendown() turtle.begin_fill() turtle.circle(20) turtle.end_fill() # 隱藏畫筆 turtle.hideturtle() # 顯示畫面 turtle.done()
通過上面的代碼,我們使用turtle庫來實(shí)現(xiàn)柯基犬的繪制。首先設(shè)置畫筆的顏色,大小和填充顏色,然后通過畫圓來繪制狗頭、耳朵等各個部位。最后,隱藏畫筆,顯示畫面即可看到我們所繪制的柯基犬!
上一篇css使div布局居中
下一篇Python畫棒條