p5.js | frameRate() Function

The frameRate() function in p5.js is used to specify the number of frames to be displayed every second. Calling frameRate() with no arguments returns the current framerate. The draw function must run at least once before it will return a value. This function is same as getFrameRate() function.

Syntax

frameRate( c )

Parameters: The function accepts single parameter c which stores the value of frame rate variable.

Below program illustrates the frameRate() function in p5.js:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
    
    // Create canvas of given size
    createCanvas(500, 200);
      
    // Set the font size
    textSize(20);
    
    // Use frameRate() function
    frameRate(3);
}
   
function draw() {
      
    // Set the background color
    background(0, 153, 0);
      
    // Display the output
    text("Frame Count with frameRate "
         int(getFrameRate()), 100, 100);
}

chevron_right


Output:

Reference: https://p5js.org/reference/#/p5/frameRate



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.