# Reset frameRate()

**URL:** <https://discourse.processing.org/t/reset-framerate/18359>\
**Category:** Coding Questions\
**Created:** [March 3, 2020, 6:49pm UTC](https://discourse.processing.org/t/reset-framerate/18359 "2020-03-03T18:49:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mamboleoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mamboleoo/32/8281_2.png) [@Mamboleoo](https://discourse.processing.org/u/Mamboleoo)\
**Post date:** [March 3, 2020, 6:49pm UTC](https://discourse.processing.org/t/reset-framerate/18359/1 "2020-03-03T18:49:27Z")

</div>

Hey there,  
I’m having a demo where I need the frameRate to be set to 5.  
But later on the demo I need to reset the frameRate to the default one.  
I don’t want to set a fixed value `frameRate(30)` as I want my frameRate to follow the default `requestAnimationFrame` callback method.

How could I “reset” the frameRate to its initial value?

Thanks!  
Mamboleoo

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 4, 2020, 3:35am UTC](https://discourse.processing.org/t/reset-framerate/18359/2 "2020-03-04T03:35:05Z")

</div>

Don’t.

Instead, when you want to limit the frame rate to 5fps, restructure your drawing code so that it only updates what is drawn every 200ms.

Example:

```auto
boolean draw_at_five_fps = true;
int time_to_draw = 0;

void draw(){
  if( draw_at_five_fps ){
    if( time_to_draw >= millis() ){
      time_to_draw = millis() + 200;
      // Update variables and draw something slowly.
    }
  } else {
    // Update variables and draw something quickly.
  }
} // End draw()

void toggle_slowmode(){
  draw_at_five_fps = !draw_at_five_fps;
  if( draw_at_five_fps ){
    time_to_draw = millis();
  }
}

```

… or just set it to frameRate(60). Processing won’t go any faster than that anyway.

---

<div class="post-metadata">

**Author:** ![Mamboleoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mamboleoo/32/8281_2.png) [@Mamboleoo](https://discourse.processing.org/u/Mamboleoo)\
**Post date:** [March 4, 2020, 8:23am UTC](https://discourse.processing.org/t/reset-framerate/18359/3 "2020-03-04T08:23:24Z")

</div>

I’m not familiar with Processing, but P5.js can go faster than 60fps since the frame rate is linked to the screen refresh rate.  
And I don’t want to set frameRate(200) as it won’t be useful for most of the users.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [March 4, 2020, 10:51am UTC](https://discourse.processing.org/t/reset-framerate/18359/4 "2020-03-04T10:51:29Z")

</div>

You should re-read the answer given! 😉

---

<div class="post-metadata">

**Author:** ![Mamboleoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mamboleoo/32/8281_2.png) [@Mamboleoo](https://discourse.processing.org/u/Mamboleoo)\
**Post date:** [March 4, 2020, 11:08am UTC](https://discourse.processing.org/t/reset-framerate/18359/5 "2020-03-04T11:08:39Z")

</div>

I do understand the first answer and the end result would indeed be the same.  
In my case I wanted to know if there was a way to reset the frameRate setting to its default.  
Since you can set a specific frameRate I was interested to know if there was a way to do the opposite like `frameRate(AUTO)`.  
I looked into the source code but I couldn’t find anything ☹  
(For my specific case, I’m showing demos to beginners and I don’t want to overload them with more logic & code outside of P5)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 4, 2020, 3:26pm UTC](https://discourse.processing.org/t/reset-framerate/18359/6 "2020-03-04T15:26:55Z")

</div>

> [@Mamboleoo](#):
>
> … if there was a way to reset the frameRate setting to its default.

From Processing’s reference [Processing.org/reference/frameRate\_.html:](http://Processing.org/reference/frameRate_.html:)

> The default rate is 60 frames per second.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [March 4, 2020, 6:50pm UTC](https://discourse.processing.org/t/reset-framerate/18359/7 "2020-03-04T18:50:14Z")

</div>

> [@GoToLoop](#):
>
> From Processing’s reference [Processing.org/reference/frameRate\_.html:](http://Processing.org/reference/frameRate_.html:)
> 
> > The default rate is 60 frames per second.

See [reference | p5.js](https://p5js.org/reference/#/p5/frameRate) and you’ll notice it’s different.

However, it does look like you can call `frameRate()` to get the existing rate, so do that before switching from the default? (noting the caveat that you can’t do it on first draw call)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 4, 2020, 7:55pm UTC](https://discourse.processing.org/t/reset-framerate/18359/8 "2020-03-04T19:55:07Z")

</div>

> [@neilcsmith](#):
>
> See [reference | p5.js](https://p5js.org/reference/#/p5/frameRate) and you’ll notice it’s different.

Oops! Forgot this is p5js category! 🥴

However, this statement below from p5js’ **frameRate()** reference doesn’t seem correct: 🤔

> The default frame rate is based on the frame rate of the display (here also called “refresh rate”), which is set to 60 frames per second on most computers.

In the source code, the internal variable _\_targetFrameRate_ is initialized w/ `60`; same as Processing’s Java Mode: 😌  
[https://github.com/processing/p5.js/blob/1.0.1/src/core/environment.js#L16-L17](https://github.com/processing/p5.js/blob/1.0.1/src/core/environment.js#L16-L17)  
Looking up the p5js repo I couldn’t find anywhere it could be based on monitor’s refresh rate. 📺

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 4, 2020, 8:09pm UTC](https://discourse.processing.org/t/reset-framerate/18359/9 "2020-03-04T20:09:54Z")

</div>

> [@neilcsmith](#):
>
> (noting the caveat that you can’t do it on first draw call)

The reason why is that method p5::**frameRate()** returns the internal property p5::_\_frameRate_, which is merely the current temporary FPS calculation for p5::_deltaTime_ purposes: ⏲  
[https://github.com/processing/p5.js/blob/1.0.1/src/core/main.js#L376-L380](https://github.com/processing/p5.js/blob/1.0.1/src/core/main.js#L376-L380)  
Instead of p5::_\_targetFrameRate_, which is the actual desired FPS: 😑  
[https://github.com/processing/p5.js/blob/1.0.1/src/core/environment.js#L295-L306](https://github.com/processing/p5.js/blob/1.0.1/src/core/environment.js#L295-L306)

In short, when p5::**frameRate()** is invoked as a setter, it mutates p5::_\_targetFrameRate_. 👍

But when it’s invoked as a getter, it returns p5::_\_frameRate_ instead. 🤪

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [March 5, 2020, 10:04am UTC](https://discourse.processing.org/t/reset-framerate/18359/10 "2020-03-05T10:04:13Z")

</div>

Good call! So it’s basically exactly like the Java API with different documentation. 🙄 At least it’s just safe to treat 60 as the default still.
