Python是一種非常流行的編程語言,在各個領域都有著廣泛的應用。它不僅易于學習,而且擁有著強大的功能。今天,我們就來看一下Python如何使用turtle庫畫月餅。
import turtle # 設置畫布大小和背景色 turtle.setup(800, 600) turtle.bgcolor("lightblue") # 繪制月餅外層矩形和圓弧形 turtle.penup() turtle.goto(-200, 0) turtle.pendown() turtle.color("brown") turtle.begin_fill() turtle.forward(400) turtle.left(90) turtle.forward(200) turtle.left(90) turtle.forward(400) turtle.left(90) turtle.forward(200) turtle.end_fill() turtle.color("orange") turtle.begin_fill() turtle.penup() turtle.goto(-200, 100) turtle.pendown() turtle.circle(100, 180) turtle.end_fill() # 繪制月餅內層圓形和花紋 turtle.color("yellow") turtle.begin_fill() turtle.penup() turtle.goto(-150, 0) turtle.pendown() turtle.circle(50) turtle.end_fill() turtle.penup() turtle.goto(-140, 20) turtle.pendown() turtle.color("white") turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(-120, 60) turtle.pendown() turtle.color("white") turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(-100, 40) turtle.pendown() turtle.color("white") turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(-80, 20) turtle.pendown() turtle.color("white") turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(-20, 60) turtle.pendown() turtle.color("white") turtle.begin_fill() turtle.circle(10) turtle.end_fill() # 隱藏turtle turtle.hideturtle() # 程序結束 turtle.done()
以上是畫月餅的代碼,使用turtle庫可以輕松地繪制出漂亮的圖形。
上一篇php jenkins
下一篇ajax與數據庫登錄校驗