Make p5py loop run for 90 frames exaclty?

I’m using the p5 python lib https://github.com/p5py/p5

I would love to do an animation scence that is 3 seconds long. So the draw loop should run for 90 frames, with 30 frames a second.

I’m trying to do this by using no_loop() and redraw(). But it’s not working… Any ideas on what to do?

from p5 import *
frames = 90

def setup():
    size(1280, 720)
    no_stroke()
    no_loop()

def draw():
    background(255)

    save_frame("out/export.png")

if __name__ == '__main__':
  run(frame_rate=30)

for i in range(0,frames):
    redraw()
1 Like

Welcome, @renec112!

How about using the frame_count? Something like this:

from p5 import *
frames = 90

def setup():
    pass

def draw():
    print(frame_count)
    save_frame('frame.png')
    
    if frame_count == frames:
        exit()

if __name__ == '__main__':
    run(frame_rate=30)
3 Likes

Thank you for the brilliant solution. Works perfectly!

And thank you for the welcome. I’m really excited to learn about this beutiful graphics package. I’m used to matplotlib which has its pros and cons :smiley:

1 Like