Python是一種高級編程語言,除了作為一般程序設計語言外,Python還可以用來繪制圖形,比如畫一只貓咪!下面是使用Python繪制貓咪的簡單示例:
import turtle # 畫貓咪的臉部 turtle.penup() turtle.goto(0,-150) turtle.pendown() turtle.circle(150) # 畫貓咪的鼻子 turtle.penup() turtle.goto(0,0) turtle.pendown() turtle.dot(50) # 畫貓咪的眼睛 turtle.penup() turtle.goto(-60,60) turtle.pendown() turtle.dot(30) turtle.penup() turtle.goto(60,60) turtle.pendown() turtle.dot(30) # 畫貓咪的嘴巴 turtle.penup() turtle.goto(-80,-60) turtle.pendown() turtle.right(45) turtle.circle(100,90) # 畫貓咪的耳朵 turtle.penup() turtle.goto(-150,150) turtle.pendown() turtle.right(30) turtle.forward(100) turtle.right(120) turtle.forward(100) turtle.right(120) turtle.forward(100) turtle.penup() turtle.goto(150,150) turtle.pendown() turtle.left(30) turtle.forward(100) turtle.left(120) turtle.forward(100) turtle.left(120) turtle.forward(100) # 完成貓咪的繪制 turtle.done()
以上代碼通過調用Python turtle模塊的畫圖函數完成了一只可愛的貓咪的繪制。運行代碼,你就可以看見這只貓咪出現在你的屏幕上啦!