Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson9_diy3
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
45fb00d4
authored
May 26, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
28bdbe8f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
1.py
1.py
0 → 100644
View file @
45fb00d4
'''
注:这个程序只能在cmd中通过当前目录下python test1.py来运行才能实时显示
'''
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
matplotlib
import
animation
# New figure with white background
fig
=
plt
.
figure
(
figsize
=
(
6
,
6
),
facecolor
=
'white'
)
# New axis over the whole figure, no frame and a 1:1 aspect ratio
ax
=
fig
.
add_axes
([
0
,
0
,
1
,
1
],
frameon
=
False
,
aspect
=
1
)
# Number of ring
n
=
50
size_min
=
50
size_max
=
50
**
2
# Ring position
pos
=
np
.
random
.
uniform
(
0
,
1
,
(
n
,
2
))
# Ring colors
color
=
np
.
ones
((
n
,
4
))
*
(
0
,
0
,
0
,
1
)
# Alpha color channel geos from 0(transparent) to 1(opaque)
color
[:,
3
]
=
np
.
linspace
(
0
,
1
,
n
)
# Ring sizes
size
=
np
.
linspace
(
size_min
,
size_max
,
n
)
# Scatter plot
scat
=
ax
.
scatter
(
pos
[:,
0
],
pos
[:,
1
],
s
=
size
,
lw
=
0.5
,
edgecolors
=
color
,
facecolors
=
'None'
)
# Ensure limits are [0,1] and remove ticks
ax
.
set_xlim
(
0
,
1
),
ax
.
set_xticks
([])
ax
.
set_ylim
(
0
,
1
),
ax
.
set_yticks
([])
def
update
(
frame
):
global
pos
,
color
,
size
# Every ring is made more transparnt
color
[:,
3
]
=
np
.
maximum
(
0
,
color
[:,
3
]
-
1.0
/
n
)
# Each ring is made larger
size
+=
(
size_max
-
size_min
)
/
n
# Reset specific ring
i
=
frame
%
50
pos
[
i
]
=
np
.
random
.
uniform
(
0
,
1
,
2
)
size
[
i
]
=
size_min
color
[
i
,
3
]
=
1
# Update scatter object
scat
.
set_edgecolors
(
color
)
scat
.
set_sizes
(
size
)
scat
.
set_offsets
(
pos
)
# Return the modified object
return
scat
,
anim
=
animation
.
FuncAnimation
(
fig
,
update
,
interval
=
10
,
blit
=
True
,
frames
=
200
)
# plt.savefig('fig.png',bbox_inches='tight')
# plt.subplot(111)
plt
.
show
()
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