From b56196364a2f0df155a79437d919cc6ba0ce5f14 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 3 Apr 2021 10:49:56 -0500 Subject: [PATCH] gif_example shows how to make animated gifs --- gif_example/README.md | 3 +++ gif_example/gif_example.pde | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 gif_example/README.md create mode 100644 gif_example/gif_example.pde diff --git a/gif_example/README.md b/gif_example/README.md new file mode 100644 index 0000000..36592a9 --- /dev/null +++ b/gif_example/README.md @@ -0,0 +1,3 @@ +# gif example + +Example for writing a Processing sketch that exports an animated gif diff --git a/gif_example/gif_example.pde b/gif_example/gif_example.pde new file mode 100644 index 0000000..2acd099 --- /dev/null +++ b/gif_example/gif_example.pde @@ -0,0 +1,38 @@ +import gifAnimation.*; + +GifMaker gifExport; +int frames = 0; +int totalFrames = 120; + +public void setup() { + smooth(); + size(400, 400); + + gifExport = new GifMaker(this, "export.gif", 100); + gifExport.setRepeat(0); // make it an "endless" animation + + noFill(); + stroke(0); + strokeWeight(20); +} + +void draw() { + background(255); + + float size = 100.0 * sin(TWO_PI * frames / float(totalFrames)) + 200.0; + ellipse(width/ 2.0, height / 2.0, size, size); + export(); +} + +void export() { + if(frames < totalFrames) { + gifExport.setDelay(20); + gifExport.addFrame(); + frames++; + } else { + gifExport.finish(); + frames++; + println("gif saved"); + exit(); + } +} \ No newline at end of file