Skip to content

Instantly share code, notes, and snippets.

@s-m-e
Created July 15, 2021 17:31
Show Gist options
  • Save s-m-e/5b234927e157b6031d0ac1658380b9f3 to your computer and use it in GitHub Desktop.
Save s-m-e/5b234927e157b6031d0ac1658380b9f3 to your computer and use it in GitHub Desktop.
from bewegung import Video, FFmpegGifEncoder
from multiprocessing import cpu_count
from random import gauss
FRAMES = 300
def data(length, *args, **kwargs):
state = 0
for _ in range(length):
state += gauss(*args, **kwargs)
yield state
v = Video(
width = 480, height = 270,
frames = FRAMES, # video length in frames
fps = 30, # set output to 30 fps
)
@v.sequence()
class SomeSequence:
def __init__(self):
self._x = list(data(FRAMES, mu = 0, sigma = 10))
self._y = list(data(FRAMES, mu = 0, sigma = 10))
@v.layer(canvas = v.canvas(backend = 'matplotlib', facecolor = '#FFFFFF', dpi = 150))
def growing_sinwave(self, canvas, time):
ax = canvas.subplots()
ax.plot(self._x[:time.index+1], self._y[:time.index+1])
ax.set_aspect('equal')
return canvas
v.render(
video_fn = 'test.gif',
processes = cpu_count(), # render video frames in parallel
encoder = FFmpegGifEncoder(), # export as gif file
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment