Skip to content

Instantly share code, notes, and snippets.

@jesi-rgb
Last active October 21, 2022 01:42
Show Gist options
  • Save jesi-rgb/b9bff93a3d8806578051f49427a7d928 to your computer and use it in GitHub Desktop.
Save jesi-rgb/b9bff93a3d8806578051f49427a7d928 to your computer and use it in GitHub Desktop.
saveGif is coming to p5.js! 🌸
This file has been truncated, but you can view the full file.
/*! p5.js v1.4.1 July 26, 2022 */
@jesi-rgb
Copy link
Author

saveGif is coming to p5 🌸 !

This is the minified, first and extremely buggy version of the p5.js library with the saveGif functionality implemented.

Download and installation

Download this file to the folder in which you usually develop your sketches and make sure to import it properly from the index.html file!
<script src=/path/to/sketch/p5.save-gif.js/>

How to use

The saveGif function admits at most 3 arguments for now:

saveGif(filename, duration, delay)
  • filename for the name of the file downloaded to your computer
  • duration duration in seconds that you wish to download from your animation
  • delay delay in seconds that you wish to wait before recording the animation. The animation will nevertheless have a duration of what you specified on the duration argument.

As an example, I like to use it within the mouse/keyboard events:

 function mousePressed() {
   if (mouseButton === RIGHT) {
     saveGif('mySketch', 3, 1);
   }
 }

This piece of code will wait for 1 second and then encode 3 seconds worth of frames (180 frames at 60fps).

Final note

⚠️ There will be a gazillion bugs and things all over the place, but your help and feedback will surely help on smashing them! Thanks so much for your time and keep code-creating! 🌸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment