Python是一種很流行的編程語言,可以用它來創作各種應用。今天,我們來嘗試用Python畫一只可愛的貓咪吧!
# 導入需要的庫 import turtle # 確定畫布大小 turtle.setup(600, 600, 0, 0) # 設置畫筆顏色和寬度 turtle.color('black') turtle.pensize(5) # 畫出貓臉 turtle.circle(150) # 畫出左耳朵 turtle.penup() turtle.goto(-80, 180) turtle.pendown() turtle.left(45) turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) # 畫出右耳朵 turtle.penup() turtle.goto(80, 180) turtle.pendown() turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(100) # 畫出眼睛 turtle.penup() turtle.goto(-60, 50) turtle.pendown() turtle.circle(20) turtle.penup() turtle.goto(60, 50) turtle.pendown() turtle.circle(20) # 畫出鼻子 turtle.penup() turtle.goto(0, 0) turtle.pendown() turtle.dot(50) # 畫出嘴巴 turtle.penup() turtle.goto(-70, -50) turtle.pendown() turtle.right(90) turtle.circle(70, 180) # 完成畫貓 turtle.done()
通過上面的代碼,我們可以輕松地畫出一只可愛的Python貓咪!