How to play Gif after mousePressed?

Hi guys, I’m pretty new to Processing but I am using it for my college project. I’m having trouble getting a gif to load after the mouse has been pressed. I know that after the mouse is pressed once it takes a picture but I was wondering if there was a way to have the gif load after the mouse is pressed and the camera stops?

import processing.video.*;

Capture cam;

PImage facescan;

boolean hasClicked;

void setup() {
  size(1920, 1080);
  background(255);
  facescan = loadImage("facescan.gif"); 

  String[] cameras = Capture.list();
  
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    
    cam = new Capture(this, cameras[0]);
    cam.start();     
  }      
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  
  image(cam, 0, 0, 800, 600);
}

void mousePressed(){
  image(facescan, 1920, 1080);
  cam.stop();
}
1 Like

Is the gif animated or static?

Do you want it to display only only while the mouse is being pressed, or from then on?

It’s a moving gif.
Essentially what I’m looking to do is once you click your picture is taken, a gif loads and then the tint on the camera changes so the image is in a different colour after the gif finishes playing.

One method is to load a list of static images as your animation frames.

https://processing.org/examples/animatedsprite.html

Another is to install the GifAnimation library.