猫史档案馆


【Python作品分享】明轩祝妈妈母亲节快乐!【作品秀】

用户:佘明轩佘明轩查看:0 回复:1 评论:0 创建时间:2020-05-10T21:40:47


【作品展示】

center_image

 

【作品介绍】

2020年5月10日,明轩学习Python编程祝福母亲节快乐。

 

【作品源代码】

import os
import time
import random
import pygame
import colorama

BGMPATH = (r"C:\Pyblock\music\bgm.mp3")
colorama.init(convert=True)
STARS = [2, 4, 8, 10, 14, 20, 26, 28, 40, 44, 52, 60, 喵, 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.8)
  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 + " \n 明轩祝妈妈节日快乐! \n 母爱伟大如天地,\n 亲情深远似江河。\n 节到念来随岁长, \n 快送一束康乃馨。 \n 乐给妈妈唱赞歌。", 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()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
有栖川無限有栖川無限

祝你的母亲幸福安康!

(学神的母亲还在工作,不能给她祝福orz)

点赞0


评论