I'm using Processing in Python mode to make a little animation, and I would like to export it as a gif.
If I were coding in javascript, I could use gifAnimation, put I am using python mode, I can't seem to make it work. I could use PIL or Pillow, but that would basically require writing another program.
Is there an easier way to do it?
Just to be clear about libraries with Processing Python mode:
numpy
);Art Simon has a nice example of gifAnimation export here: https://github.com/APCSPrinciples/AnimatedGIF/
A step by step approach:
Download the gifAnimation
library from:
https://github.com/extrapixel/gif-animation/archive/3.0.zip
Unzip and copy the gifAnimation folder into your libraries folder, like this:
user/sketchbook/libraries/gifAnimation
(Linux) or
user/Documents/Processing/libraries/gifAnimation
(Mac/Windows)
Restart the IDE and add this at the start of your sketch:
add_library('gifAnimation')
setup()
def setup():
global exporter
size(400, 400)
exporter = GifMaker(this, "animation.gif")
exporter.setRepeat(0) # infinite repeat
exporter.setQuality(100) # test values
exporter.setDelay(200) # milliseconds
draw()
use the .addFrame()
method and maybe something for the end of the animation recording.def draw():
# your drawing here
exporter.addFrame()
if keyPressed and key == 'e':
exporter.finish()
print("gif saved, exit")
exit()