Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson10-5
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c5ddf1dd
authored
Apr 22, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
e6a2cb7a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletions
diy.py
hfv.py
diy.py
View file @
c5ddf1dd
...
...
@@ -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
hfv.py
0 → 100644
View file @
c5ddf1dd
# -*- 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment