再过几天就是八月十五了,又迎来了一年一度的中秋节。在我国大部分地区,中秋节是仅次于春节的传统节日、象征着团圆安康。在这天,天上的月亮会格外的大、格外的圆,我们吃到嘴里的月饼也比平常要甜。
吃月饼本来就是中秋节里最有仪式感的一件事情,它寄托着亲人的祝福,也承载着人们对美食的传承,更是对于中华民族优良传统文化的传承。
还没有开始买月饼的小伙伴们不要担心哟,接下来有超详细的月饼攻略,花样多、款式多,简直不能太赞了!
使用turtle库绘制月亮、云朵、山以及古诗,游戏模块使用pygame库,配上美美的背景音乐。
'''
Function: 中秋赏月
Author: 向阳逐梦
微信公众号: maker星球
'''
import turtle
import time
import pygame
def drawMoon(): #绘制月亮
turtle.penup() #画笔拿起
turtle.goto(-150, 0)
turtle.fillcolor((255, 215, 0)) #圆月的颜色
turtle.pendown() #画笔放下
turtle.begin_fill()
turtle.circle(112)
turtle.end_fill() #turtle.begin_fill()到turtle.end_fill() 颜色填充
def drawCloud(): #绘制云朵
turtle.penup()
turtle.goto(-500, 200)
turtle.fillcolor((245, 245, 245))
turtle.pencolor((255, 255, 255))
turtle.pensize(5)
turtle.pendown()
turtle.forward(250)
def cloud(mode='right'):
for i in range(90):
turtle.pensize((i+1)*0.2+5)
turtle.right(1) if mode == 'right' else turtle.left(1)
turtle.forward(0.5)
for i in range(90):
turtle.pensize(90*0.2+5-0.2*(i+1))
turtle.right(1) if mode == 'right' else turtle.left(1)
turtle.forward(0.5)
cloud()
turtle.forward(100)
cloud('left')
turtle.forward(600)
def drawMountain(): #绘制山川
turtle.penup()
turtle.goto(-500, -250)
turtle.pensize(4)
turtle.fillcolor((36, 36, 36))
turtle.pencolor((31, 28, 24))
turtle.pendown()
turtle.begin_fill()
turtle.left(20)
turtle.forward(400)
turtle.right(45)
turtle.forward(200)
turtle.left(60)
turtle.forward(300)
turtle.right(70)
turtle.forward(300)
turtle.goto(500, -300)
turtle.goto(-500, -300)
turtle.end_fill()
def initTurtle():
pygame.mixer.init()
pygame.mixer.music.load('zqbg.mp3')
pygame.mixer.music.play(-1, 20.0)
turtle.hideturtle()
turtle.setup(1000, 600)
turtle.title('中秋赏月')
turtle.colormode(255)
turtle.bgcolor((193, 210, 240))
turtle.speed(10)
def writePoetry():
turtle.penup()
turtle.goto(400, -150)
turtle.pencolor((250, 240, 230))
#古诗句
potery = ["\n人\n有\n悲\n欢\n离\n合","\n月\n有\n阴\n晴\n圆\n缺","\n但\n愿\n人\n长\n久\n", "千\n里\n共\n婵\n娟\n"]
#诗句的位置(可自行设计添加), 最好2/4句五言诗
coordinates = [(300, -150), (200, -150), (100, -150)]
for i, p in enumerate(potery):
turtle.write(p, align="center", font=("STXingkai", 50, "bold"))
if (i + 1) != len(potery):
time.sleep(2)
turtle.goto(coordinates[i])
def main():
initTurtle()
drawMoon() #绘制月亮
drawCloud() #绘制云朵
drawMountain() #绘制山
writePoetry() #写诗
turtle.done()
if __name__ == '__main__':
main()
链接:https://pan.baidu.com/s/1VI5WIDeOMYE_KjMKsRqHCQ?pwd=4ry4 提取码:4ry4
代码运行截图:
代码运行显示:
https://live.csdn.net/v/embed/236563
QQ录屏20220903191022