p5.js | frameCount Variable

The frameCount variable in p5.js is used to hold the number of frames which are displayed since the program started. Inside setup() function the value is 0, after the first iteration of draw it is 1, etc.

Syntax:

frameCount

Below program illustrates the frameCount Variable in p5.js:



Example: This example uses frameCount variable to display the frame count.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
      
    // Create canvas of given size
    createCanvas(400, 400);
      
    // Set text size to 40px
    textSize(40); 
      
    // Align text to center 
    textAlign(CENTER);
      
    // Set Frame Rate to 0.5  
    frameRate(0.5);
}
   
function draw() {
      
    // Set background color
    background(220);
      
    // Set color of text
    fill('green');
      
    // Use frameCount Variable
    text("Frame Count: \n" + frameCount, 
            width / 2, height / 2); 
}

chevron_right


Output:

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



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.