-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHarmonógrafo-Animado2D.py
40 lines (33 loc) · 1.26 KB
/
Harmonógrafo-Animado2D.py
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
import matplotlib.animation as animation
from matplotlib.animation import PillowWriter
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
#Definindo a função pendulo com valor de parâmetros padrão
def Pendulo(t, A = 1, f = 5, p = 0, d = 0.05):
return (A*np.sin(2*np.pi*f*t + p)*np.exp(-1*d*t))
#Criando um array para t
t = np.linspace(0, 50*np.pi, 30000)
#Plotando os resultados
fig = plt.figure(figsize = (12, 6), dpi = 100)
ax = fig.add_subplot()
ax.set_facecolor('k')
plt.style.use(['dark_background'])
xt = np.zeros(len(t))
yt = np.zeros(len(t))
#Plotando a animação
def update(i):
xt[i] = Pendulo(t[i], 2, 4, -1, 0.05) + Pendulo(t[i], 1, 2, np.pi, 0.01)
yt[i] = Pendulo(t[i], 4, 2, np.pi/4, 0.02) + Pendulo(t[i], 1, 2, np.pi/2, 0.25)
ax.clear()
ax.plot(xt[:i], yt[:i], 'g')
#plt.axis('off')
plt.grid(True)
plt.title('$Harmonógrafo$: t = '+str(i), color = 'g')
#plt.title('t = '+str(i))
ax.set_xlabel('$x(t)$', color = 'g')
ax.set_ylabel('$y(t)$', color = 'g')
#Plotagem para chamar a função update() periodicamente
ani = animation.FuncAnimation(fig, update, np.arange(600), interval = 10, repeat = False)
ani.save('Harmonógrafo2D.gif', writer = PillowWriter(fps = 100))
#plt.show()