Files
  • main.py
  • sinewave_1d.gif
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import matplotlib.pyplot as plt
import numpy as np
import moviepy.editor as mpy
from moviepy.video.io.bindings import mplfig_to_npimage

duration = 10

fig = plt.figure(figsize=(28.8, 19))
ax = fig.add_subplot(111)
xx = np.linspace(0,4*np.pi,100)
yy = lambda t: np.sin(xx-t)

def make_movie_1d(t):
    plt.clf()
    plt.axis("off")

    plt.plot(xx, yy(4*np.pi*t/(duration)), "ko")
    return mplfig_to_npimage(fig)

animation = mpy.VideoClip(make_movie_1d, duration=duration)
animation.write_gif("sinewave_1d.gif", fps=40)