Created
July 15, 2021 17:31
-
-
Save s-m-e/5b234927e157b6031d0ac1658380b9f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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