当先锋百科网

首页 1 2 3 4 5 6 7

新春佳节来临,让我们使用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()

运行代码后,我们就可以得到一张美丽的新春祝福图片啦!