Skip to content

Instantly share code, notes, and snippets.

@HalCanary
Created December 23, 2022 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HalCanary/25fe401c16504c461adae2678867c214 to your computer and use it in GitHub Desktop.
Save HalCanary/25fe401c16504c461adae2678867c214 to your computer and use it in GitHub Desktop.
animate.py
#! /usr/bin/env python3
import matplotlib.pyplot as plt
import matplotlib.animation as anim
import numpy as np
x = np.arange(0,2*(np.pi),.01)
y, z = 0 * x, 0 * x
fig = plt.figure()
ax = plt.axes(xlim=(0, 2*np.pi), ylim=(-2, 2))
yline, = ax.plot([], [])
zline, = ax.plot([], [])
def init():
y.fill(0)
z.fill(0)
yline.set_data(x, y)
zline.set_data(x, z)
return yline, zline
def animate(i):
global y, z
y += np.sin((2*i+1)*x)/(2*i+1)
z += np.sin((i+1)*x)/(i+1)
yline.set_data(x, y)
zline.set_data(x, z)
return yline, zline
a = anim.FuncAnimation(fig, animate, init_func=init, frames=40, interval=250)
a.save("foo.gif")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment