Skip to content

Instantly share code, notes, and snippets.

@slambert
Created April 26, 2017 16:52
Show Gist options
  • Save slambert/61f82a74874afc302bba9b9036c5a88c to your computer and use it in GitHub Desktop.
Save slambert/61f82a74874afc302bba9b9036c5a88c to your computer and use it in GitHub Desktop.
This animates a sequence of images without an animated gif library. Basically stealing from the sequential example on processing.org
/* Animated with no library demo
Steve Lambert April 26, 2017
*/
// https://processing.org/examples/sequential.html
int numFrames = 4; // The number of frames in the animation
int currentFrame = 0;
PImage[] images = new PImage[numFrames];
void setup() {
size(250, 250);
frameRate(24);
imageMode(CENTER);
// you can load things this way
//images[0] = loadImage("red-0000.png");
//images[1] = loadImage("red-0001.png");
//images[2] = loadImage("red-0002.png");
//images[3] = loadImage("red-0003.png");
// or you can load things more cleverly like this:
for (int i = 0; i < numFrames; i++) {
String imageName = "red-" + nf(i, 4) + ".png"; // nf converts #s to strings
images[i] = loadImage(imageName);
}
}
void draw() {
background(0);
if (frameCount % 20 == 0) { // this modulo slows it down to every 20th frame
currentFrame = (currentFrame+1) % numFrames; // Use % to cycle through frames
}
image(images[(currentFrame)], width/2, height/2); // display the current frame
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment