Thursday, November 20, 2025
HomeLanguagesJavascriptp5.js | frameCount Variable

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.




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); 
}


Output:

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11925 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6905 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6861 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS