1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| '''
Author: rumosky
Email: rumosky@163.com
Date: 2022-08-04 20:34:19
Description: 心电图爱心
'''
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
ln, = ax.plot([], [], '-', color='r', lw=1)
time_template = 'rumosky-LOVE = %.1fs'
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)
# 祝大家七夕快乐
def init():
ax.set_xlim(-3, 3)
ax.set_ylim(-2, 3)
return ln,
def update(ii):
xdata, ydata = [], []
for i in range(0, 183):
xi = (182-i)/100
xdata.append(0.01*i-1.82)
yi = (xi**(2/3))+(0.9*(3.3-xi**2)**0.5)*np.cos(ii*(np.pi)*xi)
if type(yi) == 'complex':
yi = np.around(abs(yi), decimals=4)
yi = np.around(yi, decimals=3)
ydata.append(yi)
for i in range(0, 182):
xi = i/100
xdata.append(xi)
yi = (xi**(2/3))+(0.9*(3.3-xi**2)**0.5)*np.cos(ii*(np.pi)*xi)
if type(yi) == 'complex':
yi = np.around(abs(yi), decimals=4)
yi = np.around(yi, decimals=3)
ydata.append(yi)
ln.set_data(xdata, ydata)
time_text.set_text(time_template % (ii))
return ln,
ani = FuncAnimation(fig, update, np.linspace(
0, 13.14, 100), init_func=init, interval=100)
ani.save('rumoskylove.gif', writer='imagemagick', fps=60)
plt.show()
|