p5.js Image getCurrentFrame() Method Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The getCurrentFrame() method of p5.Image in p5.js library is used to return the index of the currently shown frame of the GIF animation. Syntax: getCurrentFrame() Parameters: This function accept does not accept any parameter. Return Value: This method returns a number that represents the current frame of the animation that is currently visible. The following libraries are included in the "head" section of the HTML page while implementing the following examples. <script src=”p5.Image.js”></script> <script src=”p5.min.js”></script> Example 1: The example below illustrates the getCurrentFrame() method in p5.js library. JavaScript function setup() { example_gif = loadImage("sample-gif.gif"); createCanvas(500, 300); textSize(18); incSpeedBtn = createButton("Increase GIF Speed"); incSpeedBtn.position(30, 240); incSpeedBtn.mousePressed(() => { // Decrease the delay between frames example_gif.delay(25); }) decSpeedBtn = createButton("Decrease GIF Speed"); decSpeedBtn.position(200, 240); decSpeedBtn.mousePressed(() => { // Increase the delay between frames example_gif.delay(150); }) } function draw() { clear(); text("The current frame is shown " + "using getCurrentFrame()", 20, 20); // Draw the GIF on screen image(example_gif, 20, 40, 260, 140); // Get the current frame let currFrame = example_gif.getCurrentFrame(); text("The current frame is: " + currFrame, 20, 200); } Output: Example 2: JavaScript function preload() { example_gif = loadImage("sample-gif.gif"); } function setup() { createCanvas(500, 300); textSize(18); text("Click on the button to get " + "the current frame", 20, 20); frameBtn = createButton("Get current frame"); frameBtn.position(30, 40); frameBtn.mousePressed(getFrame); } function draw() { // Draw the GIF on screen image(example_gif, 20, 60, 240, 120); } function getFrame() { clear(); // Get the current frame let currFrame = example_gif.getCurrentFrame(); text("The current frame is: " + currFrame, 20, 200); text("Click on the button to get " + "the current frame", 20, 20); } Output: Online editor: https://editor.p5js.org/Environment Setup: https://www.geeksforgeeks.org/javascript/p5-js-soundfile-object-installation-and-methods/Reference: https://p5js.org/reference/#/p5.Image/getCurrentFrame Comment S sayantanm19 Follow 0 Improve S sayantanm19 Follow 0 Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like