I have answered this today on Stack Overflow and I think it might be useful for someone:
Just to be clear about libraries with Processing Python mode:
- You can use “pure Python” libraries;
- You can’t use Python libraries with C extensions & etc (like
numpy
); - You can’t use JavaScript (or p5js) libraries;
- You can use Java & Processing Java mode libraries (most of them work)!
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')
- Initialize an exporter object inside
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
- at the end of
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()