# Frame rate logic in draw -- locating it in the source code

**URL:** <https://discourse.processing.org/t/frame-rate-logic-in-draw-locating-it-in-the-source-code/3840>\
**Category:** Processing\
**Created:** [September 25, 2018, 6:36pm UTC](https://discourse.processing.org/t/frame-rate-logic-in-draw-locating-it-in-the-source-code/3840 "2018-09-25T18:36:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 25, 2018, 6:36pm UTC](https://discourse.processing.org/t/frame-rate-logic-in-draw-locating-it-in-the-source-code/3840/1 "2018-09-25T18:36:10Z")

</div>

I am trying to track down the code that Processing uses to change the `frameRate()` into decisions about when to lag or speed up individual frame start times – including where the default frameRate() goal is stored, how it is updated, how it is used, and how the frameRate status variable is updated.

I tried digging around with github search and had problems.

I found the interface for setFrameRate in PSurface, but not where it is being used (by g?).

> <https://github.com/processing/processing/blob/master/core/src/processing/core/PSurface.java#L120-L122>

I also found rendering logic that looks right in the PSurfaceNone.thread class definition for AnimationThread. PSurface is a “Surface that’s not really visible. Used for PDF and friends, or as a base class for other drawing surfaces. It includes the standard rendering loop.” So I am unsure – is this timing code for “PDF and friends” — things with None surfaces – or does this get extended into something used by g?

> <https://github.com/processing/processing/blob/master/core/src/processing/core/PSurfaceNone.java#L260-L267>

The only other timing logic I have been able to dig up is in saveTargetAsync in PGraphics, which I’m almost certain is for file saving only – not draw.

> <https://github.com/processing/processing/blob/master/core/src/processing/core/PGraphics.java#L8388-L8393>

Is anyone familiar with the Processing draw loop who can help me identify the right bits of code to inspect for its timing logic?

---

<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:** [September 25, 2018, 7:02pm UTC](https://discourse.processing.org/t/frame-rate-logic-in-draw-locating-it-in-the-source-code/3840/2 "2018-09-25T19:02:39Z")

</div>

I believe that FPS logic is pretty much at these lines: 🤔

> <https://github.com/processing/processing/blob/processing-0265-3.4/core/src/processing/core/PApplet.java#L2361-L2365>

> <https://github.com/processing/processing/blob/processing-0265-3.4/core/src/processing/core/PApplet.java#L2413-L2464>

- Notice though that class PSurface is exclusive to P3.
- And it was created as a replacement of Java’s java.applet.Applet:  
[Docs.Oracle.com/javase/10/docs/api/java/applet/Applet.html](http://Docs.Oracle.com/javase/10/docs/api/java/applet/Applet.html)
- Which class PApplet used to extend up till Processing v3.0a5:

> <https://github.com/processing/processing/blob/processing-0232-3.0a5/core/src/processing/core/PApplet.java#L161-L163>
