Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson4_diy2
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
fe7832e9
authored
Jul 21, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
106ac2d2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
244 additions
and
58 deletions
1.mp3
歌曲4.mp3 → 2.mp3
my_music.py
1.mp3
0 → 100644
View file @
fe7832e9
File added
歌曲4
.mp3
→
2
.mp3
View file @
fe7832e9
File moved
my_music.py
View file @
fe7832e9
import
pygame
from
pygame
import
locals
#
import pygame
#
from pygame import locals
pygame
.
init
()
# 初始化
# 创建窗口
screen
=
pygame
.
display
.
set_mode
((
640
,
480
))
# 载入图片、资源
bg_img
=
pygame
.
image
.
load
(
'background.png'
)
# 背景图
play_img
=
pygame
.
image
.
load
(
'play.png'
)
# 播放按钮
stop_img
=
pygame
.
image
.
load
(
'stop.png'
)
# 暂停按钮
last_img
=
pygame
.
image
.
load
(
'last.png'
)
# 上一曲按钮
next_img
=
pygame
.
image
.
load
(
'next.png'
)
# 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
start
=
stop_img
# 中间logo
pygame
.
mixer
.
music
.
load
(
'歌曲4.mp3'
)
# pygame.init() # 初始化
# # 创建窗口
# screen = pygame.display.set_mode((640, 480))
# # 载入图片、资源
# bg_img = pygame.image.load('background.png') # 背景图
# play_img = pygame.image.load('play.png') # 播放按钮
# stop_img = pygame.image.load('stop.png') # 暂停按钮
# last_img = pygame.image.load('last.png') # 上一曲按钮
# next_img = pygame.image.load('next.png') # 下一曲按钮
# logo_img = pygame.image.load('logo.png')
# start = stop_img # 中间logo
# volume = 0.2
# pygame.mixer.music.set_volume(volume)
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
pygame
.
mixer
.
music
.
play
()
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
start
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
screen
.
blit
(
last_img
,
(
120
,
350
))
# 上一曲
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
# 刷新画面
pygame
.
display
.
update
()
# music = ["1.mp3","2.mp3"]
# a=-1
# b = stop_img
# x,y = pygame.mouse.get_pos()
# volume = 0.2
# pygame.mixer.music.set_volume(volume)
# start = stop_img
# click = 0
# while True:
# x,y = pygame.mouse.get_pos()
# for event in pygame.event.get():
# if event.type == locals.QUIT:
# exit()
# if event.type == locals.KEYDOWN:
# if event.key == locals.K_UP:
# volume += 0.1
# if volume < 0 or volume==0:
# volume = 0
# pygame.mixer.music.set_volume(volume)
# if event.key == locals.K_DOWN:
# volume -= 0.1
# if volume < 0 or volume==0:
# volume = 0
# pygame.mixer.music.set_volume(volume)
# if event.type == locals.MOUSEBUTTONDOWN:
# click += 1
# if click%2 == 0:
# pygame.mixer.music.unpause()
# start = stop_img
# else:
# pygame.mixer.music.pause()
# start = play_img
# if event.type == locals.KEYDOWN:
# if x < 370 and x>270 and y<360 and y>260:
# if event.key == locals.K_UP:
# if volume >=1:
# pygame.mixer.music.set_volume(1)
# else:
# volume += 0.1
# pygame.mixer.music.set_volume(volume)
# if event.key == locals.K_DOWN:
# if volume <=0:
# pygame.mixer.music.set_volume(0)
# else:
# volume -= 0.1
# pygame.mixer.music.set_volume(volume)
# if event.type == locals.MOUSEBUTTONDOWN:
# a += 1
# if a%2 == 0:
# pygame.mixer.music.pause()
# b = play_img
# if a%2 == 1:
# pygame.mixer.music.unpause()
# b = stop_img
# if pygame.mixer.music.get_busy() == False:
# pygame.mixer.music.load(music[0])
# pygame.mixer.music.play()
# screen.blit(bg_img, (0, 0)) # 填充背景
# screen.blit(b, (270, 330)) # 暂停按钮
# screen.blit(logo_img, (170, 60)) # 中间logo图
# screen.blit(last_img, (120, 350)) # 上一曲
# screen.blit(next_img, (420, 350)) # 下一曲
# # 刷新画面
# pygame.display.update()
# if volume <=0:
# volume = 0
# if pygame.mixer.music.get_busy() == False:
# pygame.mixer.music.play()
# 绘制画面
\ No newline at end of file
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
matplotlib.collections
import
LineCollection
x0
,
y0
=
1
,
1
#此为流星位置
ts
=
np
.
arange
(
0
,
1
,
0.01
)
#参数
xs
,
ys
=
x0
+
ts
,
y0
+
ts
#绘图线条
plt
.
figure
(
facecolor
=
"black"
)
points
=
np
.
array
([
xs
,
ys
])
.
T
.
reshape
(
-
1
,
1
,
2
)
segments
=
np
.
concatenate
([
points
[:
-
1
],
points
[
1
:]],
axis
=
1
)
ax
=
plt
.
subplot
()
lc
=
LineCollection
(
segments
,
cmap
=
'viridis'
)
lc
.
set_array
(
ts
)
lc
.
set_linewidth
(
ts
[::
-
1
])
line
=
ax
.
add_collection
(
lc
)
ax
.
set_xlim
(
0
,
3
)
ax
.
set_ylim
(
0
,
3
)
plt
.
show
()
from
numpy.random
import
rand
,
randint
N
,
L
=
20
,
100
#流星个数和线段数
ts
=
np
.
array
([
np
.
linspace
(
0
,
rand
(),
L
)
for
_
in
range
(
N
)])
.
T
x0
,
y0
=
rand
(
2
*
N
)
.
reshape
(
2
,
1
,
N
)
x0
*=
5
xs
,
ys
=
x0
+
ts
,
y0
+
ts
#绘图线条1
points
=
np
.
array
([
xs
,
ys
])
.
T
.
reshape
(
N
,
L
,
-
1
,
2
)
ax
=
plt
.
subplot
()
for
i
in
range
(
N
):
segs
=
np
.
concatenate
([
points
[
i
][:
-
1
],
points
[
i
][
1
:]],
axis
=
1
)
lc
=
LineCollection
(
segs
,
cmap
=
'viridis'
)
lc
.
set_array
(
ts
[:,
i
])
lc
.
set_linewidth
(
ts
[::
-
1
,
i
])
ax
.
add_collection
(
lc
)
ax
.
set_xlim
(
0
,
6
)
ax
.
set_ylim
(
-
2
,
3
)
ax
.
set_axis_off
()
#取消坐标轴
plt
.
show
()
def
bgpic
(
self
,
picname
=
None
):
"""Set background image or return name of current backgroundimage.
Optional argument:
picname -- a string, name of a gif-file or "nopic".
If picname is a filename, set the corresponding image as background.
If picname is "nopic", delete backgroundimage, if present.
If picname is None, return the filename of the current backgroundimage.
Example (for a TurtleScreen instance named screen):
>>> screen.bgpic()
'nopic'
>>> screen.bgpic("landscape.gif")
>>> screen.bgpic()
'landscape.gif'
"""
if
picname
is
None
:
return
self
.
_bgpicname
if
picname
not
in
self
.
_bgpics
:
self
.
_bgpics
[
picname
]
=
self
.
_image
(
picname
)
self
.
_setbgpic
(
self
.
_bgpic
,
self
.
_bgpics
[
picname
])
self
.
_bgpicname
=
picname
# coding: utf-8
import
pygame
import
os
import
sys
from
pygame.locals
import
*
os
.
chdir
(
'E:/星空'
)
os
.
getcwd
()
pygame
.
init
()
pygame
.
mixer
.
init
()
pygame
.
mixer
.
music
.
load
(
"星空之美.mp3"
)
# pygame.mixer.music.set_volume(0.4)
pygame
.
mixer
.
music
.
play
()
bg_size
=
width
,
height
=
300
,
200
bg_rgb
=
(
255
,
255
,
255
)
screen1
=
pygame
.
display
.
set_mode
(
bg_size
)
pygame
.
display
.
set_caption
(
"音乐"
)
clock
=
pygame
.
time
.
Clock
()
pause_rect
=
pause_image
.
get_rect
()
print
(
pause_rect
.
width
,
pause_rect
.
height
)
pause_rect
.
left
,
pause_rect
.
top
=
(
width
-
pause_rect
.
width
)
//
2
,
(
height
-
pause_rect
.
height
)
//
2
from
turtle
import
*
from
random
import
random
,
randint
os
.
chdir
(
'E:/星空'
)
screen
=
Screen
()
width
,
height
=
900
,
700
screen
.
setup
(
width
,
height
)
screen
.
title
(
"浪漫的流星雨"
)
screen
.
bgcolor
(
"black"
)
screen
.
mode
(
"logo"
)
screen
.
delay
(
0
)
printer
=
Turtle
()
printer
.
hideturtle
()
printer
.
penup
()
printer
.
color
(
'red'
)
printer
.
goto
(
-
100
,
-
350
)
printer
.
write
(
"宇宙广阔(弱水三千)""
\n\n
"
,
move
=
True
,
align
=
"left"
,
font
=
(
"Italic"
,
30
,
"bold"
))
printer
.
goto
(
-
50
,
-
400
)
printer
.
write
(
"只寻你一颗!(只取一瓢饮!)
\n\n
"
,
move
=
True
,
align
=
"left"
,
font
=
(
"Italic"
,
30
,
"bold"
))
t
=
Turtle
(
visible
=
False
,
shape
=
'circle'
)
t
.
pencolor
(
"white"
)
t
.
fillcolor
(
"white"
)
t
.
penup
()
t
.
setheading
(
-
90
)
t
.
goto
(
width
/
2
,
randint
(
-
height
/
2
,
height
/
2
))
stars
=
[]
for
i
in
range
(
300
):
star
=
t
.
clone
()
s
=
random
()
/
3
if
s
>
0.01
and
s
<
0.03
:
star
.
pencolor
(
"black"
)
star
.
fillcolor
(
"black"
)
elif
s
>
0.03
and
s
<
0.04
:
star
.
pencolor
(
"lightcoral"
)
star
.
fillcolor
(
"lightcoral"
)
elif
s
>
0.05
and
s
<
0.1
:
star
.
pencolor
(
"green"
)
star
.
fillcolor
(
"green"
)
elif
s
>
0.15
and
s
<
0.16
:
star
.
pencolor
(
"yellow"
)
star
.
fillcolor
(
"yellow"
)
elif
s
>
0.19
and
s
<
0.2
:
star
.
pencolor
(
"red"
)
star
.
fillcolor
(
"red"
)
elif
s
>
0.21
and
s
<
0.22
:
star
.
pencolor
(
"purple"
)
star
.
fillcolor
(
"purple"
)
elif
s
>
0.29
and
s
<
0.3
:
star
.
pencolor
(
"darkorange"
)
star
.
fillcolor
(
"darkorange"
)
elif
s
>
0.31
and
s
<
0.32
:
star
.
pencolor
(
"red"
)
star
.
fillcolor
(
"yellow"
)
elif
s
>
0.32
and
s
<
0.33
:
star
.
pencolor
(
"yellow"
)
star
.
fillcolor
(
"white"
)
star
.
shapesize
(
s
,
s
)
star
.
speed
(
int
(
s
*
30
))
star
.
setx
(
width
/
2
+
randint
(
1
,
width
))
star
.
sety
(
randint
(
-
height
/
2
,
height
/
2
))
# star.showturtle()
stars
.
append
(
star
)
i
=
0
pause
=
False
while
True
:
i
+=
0
for
star
in
stars
:
star
.
setx
(
star
.
xcor
()
-
3
*
star
.
speed
())
if
star
.
xcor
()
<
-
width
/
2
:
star
.
hideturtle
()
star
.
setx
(
width
/
2
+
randint
(
1
,
width
))
star
.
sety
(
randint
(
-
height
/
2
,
height
/
2
))
star
.
showturtle
()
if
i
>=
100
:
break
# 查找队列事件
for
event
in
pygame
.
event
.
get
():
# 查找点击关闭窗口事件
if
event
.
type
==
QUIT
:
sys
.
exit
# 查找鼠标左右击事件
if
event
.
type
==
MOUSEBUTTONDOWN
:
if
event
.
button
==
1
:
pause
=
not
pause
if
event
.
button
==
3
:
pause
=
not
pause
if
event
.
type
==
KEYDOWN
:
if
event
.
key
==
K_SPACE
:
pause
=
not
pause
screen1
.
fill
(
bg_rgb
)
if
pause
:
pygame
.
mixer
.
music
.
pause
()
screen1
.
blit
(
pause_image
,
pause_rect
)
else
:
pygame
.
mixer
.
music
.
unpause
()
screen1
.
blit
(
play_image
,
pause_rect
)
pygame
.
display
.
flip
()
clock
.
tick
(
30
)
\ 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