Open In App
Related Articles

p5.Image reset() Method

Improve Article
Improve
Save Article
Save
Like Article
Like

The reset() method of p5.Image in p5.js is used to restart an animated GIF and play it from its beginning state. It can be used with a button press or user input to restart the GIF animation. It does not accept any parameters.

Syntax:

reset()

Parameters: This method does not accept any parameter.

The example below illustrates the reset() method in p5.js:

Example:

Javascript




function preload() {
    example_gif = loadImage("sample-gif.gif");
}
  
function setup() {
    createCanvas(500, 300);
    textSize(18);
  
    example_gif.delay(15);
  
    text("Click on the button to " +
         "reset the animation", 20, 20);
  
    resetBtn = 
      createButton("Reset Animation");
    resetBtn.position(30, 40);
    resetBtn.mousePressed(resetAnimation);
}
  
function draw() {
    image(example_gif, 20, 60, 300, 200);
}
  
function resetAnimation() {
  
    // Reset the animation using
    // the reset() method
    example_gif.reset();
}


Output:

Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Reference: https://p5js.org/reference/#/p5.Image/reset

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!

Last Updated : 18 Sep, 2020
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials