Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

The most simple and modular way to export a gif

$
0
0

Hi folks!

I've created two gif-export-functions in a seperate file to simplify the process of exporting gifs. Now all i have to do is calling the gifsetup-function in the setup and the gifdraw-function in draw.

This is an example for a sketch

int a = 0;

void setup() {
  size(540, 540);

// Call the gifsetup-function
  gifsetup();
}

void draw() {
ellipse(width/2,height/2,a,a);
a++;
// Call the gifdraw-function
// Specify, how many frames shall be recorded
  gifdraw(40);
}

The functions are stored in a separate file (gifexport.pde)

import gifAnimation.*;

GifMaker gifExport;

void gifsetup() {
  println("gifAnimation " + Gif.version());
  gifExport = new GifMaker(this, "export.gif");
  gifExport.setRepeat(0);
  gifExport.setDelay(50);
}

void gifdraw(int frames) {

  gifExport.addFrame();
  if (frameCount == frames) {
    gifExport.finish();
    println("gif saved");
    exit();
  }
}

As you can see, all i have to do to export a gif is calling two functions: gifsetup(); in the setup and gifdraw(); in the draw-section.

Now my question is: Is it possible to simplify the gif-export a bit more? It would be perfect, to just have one lie of code instead of two. Maybe like this

gif(40);

Thanks and enjoy your weekend!

Tim


Viewing all articles
Browse latest Browse all 2896

Trending Articles