GIF animation speed confusion? #516
villares
started this conversation in
Show and tell
Replies: 2 comments 6 replies
-
Yes, that looks too slow. It might be a speed limit imposed by the PIL image library? I was able to increase the speed with this: So GIF allows it to be faster. There are no limitations in py5 that would cause this to be slower. The PIL image library does not suggest any limitations. https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif-saving It could be a technical shortcoming or limitation in PIL itself. |
Beta Was this translation helpful? Give feedback.
5 replies
-
😄 import py5
from py5_tools import animated_gif
import numpy as np
FPS = 60 # sketch frame rate target
NUM_FRAMES = 100
# To catch the blur from start use START = NUM_FRAMES, otherwise START = 1 is OK, avoid START = 0.
START = NUM_FRAMES # start recording on second cycle
STEP = 2 # set to 2 will capture half NUM_FRAMES
N = 3 # steps for blur
def setup():
py5.size(400, 400)
py5.no_stroke()
global pixel_storage
pixel_storage = np.zeros((N, py5.height, py5.width, 3))
py5.frame_rate(FPS)
animated_gif('output.gif',
frame_numbers=range(START, START + NUM_FRAMES, STEP),
duration=STEP*1/FPS) # if FPS = 30 then 1/15
def draw():
py5.background(0)
f = py5.frame_count
t = (f - 1) % NUM_FRAMES / NUM_FRAMES # lerp rate (will not reach 1)
d = 100 # base diameter
a = py5.TWO_PI * t # angle
vd = d + d * py5.sin(a) # variable diameter
py5.circle(200, 100, vd)
x = py5.lerp(-d / 2, py5.width + d / 2, t) # horizontal pos
py5.circle(x, 300, d)
# blur
py5.get_np_pixels(bands="RGB", dst=pixel_storage[py5.frame_count % N])
py5.set_np_pixels(pixel_storage.mean(axis=0), bands="RGB")
py5.window_title(f'{py5.get_frame_rate():.1f}') # about 60 fps
py5.run_sketch() |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm playing with the great
py5_tools.animated_gif()
export feature. But I wonder if I'm doing something wrong, thinking wrong about the duration that controls the speed. Maybe my GIF viewers don't support a higher speed?Does this GIF seem slower than the running sketch?
Beta Was this translation helpful? Give feedback.
All reactions