Skip to content
Related Articles

Related Articles

p5.Image reset() Method

Improve Article
Save Article
  • Last Updated : 18 Sep, 2020
Improve Article
Save Article

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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!