I get this asked from time to time so here’s a quick reminder about how to create an animated GIF from a Processing sketch:
One way to go would be to use a library (http://extrapixel.github.io/gif-animation) but I’m not a big fan of this.
So personally I do it like this:
1. You define how many frames you want your GIF to have, like ‘int numberFrames = 120’
2. If your animation is a loop then you increase the theta (the value you are using in your sin() or cos() function) in your draw() function by TWO_PI divided by the number of frames, like ‘theta += TWO_PI/numberFrames’
3. You define a condition for when to save the individual GIFs. Depending on your effect the easiest could be: ‘if (frameCount<=numberFrames) saveFrame(“export/image-###.gif”)
4. You then use a tool like ‘gifsicle' (command line tool for Mac, PC and Linux) or 'unfreez' (graphical tool for Windows) to stitch the individual GIFs together. With gifsicle you would use a command like 'gifsicle -b -d 5 —loop —colors 256 i*.gif > anim.gif'
You can check the code of this sketch to see this implemented.
Feel free to ask if something wasn’t clear.