新春佳節來臨,讓我們使用Python來畫一張新春祝福的圖片,祝福大家新年快樂,萬事如意!
import turtle # 設置畫筆 turtle.speed(3) turtle.pensize(2) turtle.penup() turtle.goto(0, -200) turtle.pendown() turtle.color('red') # 畫園 turtle.begin_fill() turtle.circle(200) turtle.end_fill() # 寫字 turtle.penup() turtle.goto(-100, 0) turtle.pendown() turtle.color('yellow') turtle.write('新年快樂', font=('Arial', 30, 'normal')) # 畫花 turtle.penup() turtle.goto(-60, 80) turtle.pendown() turtle.color('green') turtle.begin_fill() for i in range(12): turtle.forward(40) turtle.left(150) turtle.forward(40) turtle.right(180-30) turtle.end_fill() turtle.penup() turtle.goto(60, 80) turtle.pendown() turtle.color('green') turtle.begin_fill() for i in range(12): turtle.forward(40) turtle.left(150) turtle.forward(40) turtle.right(180-30) turtle.end_fill() # 畫心 turtle.penup() turtle.goto(-80, -80) turtle.pendown() turtle.color('pink') turtle.begin_fill() turtle.left(45) turtle.forward(100) turtle.circle(50, 180) turtle.left(90) turtle.circle(50, 180) turtle.forward(100) turtle.end_fill() # 完成畫圖 turtle.hideturtle() turtle.done()
運行代碼后,我們就可以得到一張美麗的新春祝福圖片啦!