Update Image display of GIFS while exporting and overwriting them with CAM images

So I don't have quite the logical grasp on processing since I'm not much of a coder but I've been able to make what I want to happen work- It just lags tremendously and I think it's due to the inefficient way I've tried to direct the process.

I'm also using an outside processing library to create the gifs, found here - http://extrapixel.github.io/gif-animation/

I wanted to do a live update of gif displays while the program exported them under the same filename and so this means having to classify the gifs in void draw() since void setup doesn't get called after it runs the first time unless someone knows of a way to access it. I hope someone can make sense of it and see where I can improve :)? Basically I'm creating a display grid of four gifs, and when the camera is called , it exports the camera recording as a gif and then replaces one of the four displays in a sequential order defined by int a.

 import gifAnimation.*;


 import processing.video.*;
 PImage[] animation;

 Gif gif1;
 Gif gif2;
 Gif gif3;
 Gif gif4;
  GifMaker gifExport;
  int m =0;
  int a = 0;
  int n=0;
 Capture cam;

void setup() {
   size(800, 800);
background(0);
   String[] cameras = Capture.list();


    CAM();
     cam.start();

   }


 void draw() {

   if (n==0&&mousePressed==false) {
    capturetest(); n+=1;}



  frameRate(5);

  image(gif1, 0,0,400,400);
 image(gif2, 400,0,400,400);
 image(gif3, 0,400,400,400);
 image(gif4, 400,400,400,400);

  if (mousePressed) { 
     if (cam.available() == true) {

       cam.read();
       image(cam, 0, 0);
 record();


     }
  }
  }

  void CAM () { 
   cam = new Capture(this, width, height);
 }


 void record(){
   gifExport.setDelay(2);
     gifExport.addFrame();

 }

 void mousePressed() {

 gifExport = new GifMaker(this,a+".gif");
     gifExport.setRepeat(0);             // make it an "endless" animation


 }

 void mouseReleased() {


   gifExport.finish();                 // write file
   if (a < 4) {
     a+=1;
  }
  if (a == 4) {
    a=0; 
   }
    n=0;
 }


 void capturetest(){

 gif1  = new Gif(this, "0.gif");
 gif1.loop();
 gif2 = new Gif(this, "1.gif");
 gif2.loop();
 gif3 = new Gif(this, "2.gif");
 gif3.loop();
 gif4 = new Gif(this, "3.gif");
 gif4.loop();}
Sign In or Register to comment.