Commit c5ddf1dd by BellCodeEditor

save project

parent e6a2cb7a
Showing with 68 additions and 1 deletions
......@@ -12,6 +12,6 @@ today_menu={'前菜':{'熏鲢鱼':20,'生蚝':20,'面包':10},
for k,v in today_menu.items():
print('今日' + k + '有:')
for i in v.values():
for i in v:
print(i,end=' ') #依次告诉客人今天的各类菜有哪些选择
print()
\ No newline at end of file
# -*- coding:utf-8 -*-
# @Time : 2023-01-01
# @Author : Carl_DJ
'''
实现功能:
新年愿望代码雨
'''
import random
import pygame
# 设置窗口的尺寸
Windows_width = 1000
Windows_heigh = 800
#创建代码雨窗口
pygame.init()
winsur = pygame.display.set_mode((Windows_width,Windows_heigh))
# 设置文字间距
font_px = 18
#设置文字大小
font_a = pygame.font.SysFont('',26)
bg_suface = pygame.Surface((Windows_width,Windows_heigh),flags = pygame.SRCALPHA)
pygame.Surface.convert(bg_suface)
bg_suface.fill(pygame.Color(0,0,0,26))
#填充
winsur.fill((0,0,0))
# 设置代码雨的内容
message = '2023 HappyNewYear! 2023HappyNewYear! 2023 HappyNewYear!'
#设置字体及颜色
texts = [font_a.render(message[i],True,(10,255,255)) for i in range(40)]
# 设置屏幕显示比例,防止字幕超过屏幕
colum = int(Windows_width/ font_px)
drops = [0 for i in range (colum)]
# 让字幕一直显示,避免一闪而过的尴尬
while True:
#从队列中获取
for event in pygame.event.get():
#添加判断,超过则退出
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN:
change = pygame.key.get_pressed()
if change[30]:
exit()
# 设置下落速度为50ms
pygame.time.delay(50)
#重新编译图像
winsur.blit(bg_suface,(0,0))
for i in range(len(drops)):
text = random.choice(texts)
#重排每个坐标点
winsur.blit(text,(i * font_px,drops[i] * font_px))
drops[i] += 1
#禁止行数超过屏幕的高
if drops[i] * 10 > Windows_heigh or random.random() > 0.95:
drops[i] = 0
pygame.display.flip()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment