# Make p5py loop run for 90 frames exaclty?

**URL:** https://discourse.processing.org/t/make-p5py-loop-run-for-90-frames-exaclty/20736
**Category:** p5py
**Created:** [May 11, 2020, 6:36am UTC](https://discourse.processing.org/t/make-p5py-loop-run-for-90-frames-exaclty/20736 "2020-05-11T06:36:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![renec112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/renec112/32/9168_2.png) [@renec112](https://discourse.processing.org/u/renec112)
#### Post date: [May 11, 2020, 6:36am UTC](https://discourse.processing.org/t/make-p5py-loop-run-for-90-frames-exaclty/20736/1 "2020-05-11T06:36:02Z")

</div>

I’m using the p5 python lib [https://github.com/p5py/p5](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?

```auto
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()

```

---

<div class="post-metadata">

### Author: ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)
#### Post date: [May 11, 2020, 6:55am UTC](https://discourse.processing.org/t/make-p5py-loop-run-for-90-frames-exaclty/20736/2 "2020-05-11T06:55:07Z")

</div>

Welcome, @renec112!

How about using the [`frame_count`](https://p5.readthedocs.io/en/latest/reference/environment.html?highlight=frame_count#frame-count)? Something like this:

```auto
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)

```

---

<div class="post-metadata">

### Author: ![renec112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/renec112/32/9168_2.png) [@renec112](https://discourse.processing.org/u/renec112)
#### Post date: [May 11, 2020, 8:19am UTC](https://discourse.processing.org/t/make-p5py-loop-run-for-90-frames-exaclty/20736/3 "2020-05-11T08:19:38Z")

</div>

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 😃
