import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
fig = plt.figure()
ax = plt.axes(xlim=(-25, 25), ylim=(-25, 25))
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
p = np.arange(0, 4*np.pi, 0.1)
x = 12*np.cos(p) + 8*np.cos(1.5*p)
y = 12*np.sin(p) - 8*np.sin(1.5*p)
def animate(i):
t = 0.1*i
X = x*np.cos(t) - y*np.sin(t)
Y = y*np.cos(t) + x*np.sin(t)
line.set_data(X, Y)
return line,
plt.title('A rotating star!')
plt.axis('off')
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=100, blit=True)
anim.save('basic_animation.mp4', writer = 'ffmpeg', fps = 10)
plt.show()