Python节日祝福实现

import os
import time
import random
import pygame
import colorama

‘’‘一些变量’’’
BGMPATH = ‘bgm.mp3’
colorama.init(convert=True)
STARS = [2, 4, 8, 10, 14, 20, 26, 28, 40, 44, 52, 60, 64, 76]
HEARTS = [13, 27, 41, 55, 69, 77]
FLOWERS = [7, 15, 23, 31, 39, 46]
RED = colorama.Fore.RED + colorama.Style.BRIGHT
CYAN = colorama.Fore.CYAN + colorama.Style.BRIGHT
GREEN = colorama.Fore.GREEN + colorama.Style.BRIGHT
YELLOW = colorama.Fore.YELLOW + colorama.Style.BRIGHT
MAGENTA = colorama.Fore.MAGENTA + colorama.Style.BRIGHT

‘’‘程序背景音乐’’’
def playBGM(bgm_path):
pygame.mixer.init()
pygame.mixer.music.load(bgm_path)
pygame.mixer.music.play(-1)

‘’‘换行’’’
def nextLine():
time.sleep(0.3)
print()

‘’‘画心’’’
def drawHeart():
num_spaces = random.randint(8, 80)
print(’ ’ * num_spaces, end=’’)
for i in range(78):
if i in HEARTS:
nextLine()
print(’ ’ * num_spaces, end=’’)
elif i in STARS:
print(RED + ‘*’, end=’’)
elif i in [32, 36]:
print(GREEN + ‘M’, end=’’)
elif i == 34:
print(GREEN + ‘O’, end=’’)
else:
print(’ ‘, end=’’)

‘’‘显示祝福文字’’’
def showText():
print(’ ’ * random.randint(8, 80), end=’’)
print(CYAN + “H a p p y M o t h e r ’ s D a y !”, end=’’)

‘’‘画花’’’
def drawFlower():
num_spaces = random.randint(8, 80)
print(’ ’ * num_spaces, end=’’)
for i in range(47):
if i in FLOWERS:
nextLine()
print(’ ’ * num_spaces, end=’’)
elif i in [2, 8, 12, 18]:
print(MAGENTA + ‘{’, end=’’)
elif i in [3, 9, 13, 19]:
print(MAGENTA + ‘_’, end=’’)
elif i in [4, 10, 14, 20]:
print(MAGENTA + ‘}’, end=’’)
elif i in [27, 35, 43]:
print(GREEN + ‘|’, end=’’)
elif i in [34, 44]:
print(GREEN + ‘~’, end=’’)
elif i == 11:
print(YELLOW + ‘o’, end=’’)
else:
print(’ ‘, end=’’)

‘’‘清屏’’’
def clearScreen():
try:
os.system(‘cls’)
except:
os.system(‘clear’)

‘’‘主程序’’’
def main():
playBGM(BGMPATH)
clearScreen()
while True:
drawHeart()
nextLine()
showText()
nextLine()
nextLine()
drawFlower()
print()

if name == ‘main’:
main()在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值