Image Sequence

You can use a counter variable to cycle through a series of images, either automatically, like a flipbook, or one at a time in response to mouse clicks or other events. There are several different ways of doing this. For a short image sequence, you can load each image into a PImage variable, use a counter variable to keep track of which one you're showing, and use 'if' statements to show a different image for each possible value.

When you use an if statement like this, to see if a variable is equal to a specific value, you must use two equal signs . This way Processing knows you mean "compare these two things", not "set the value of this variable."

These examples will all use the same set of images. Save each of these images (Right-click, Save Link As..., or similar), and add them to your sketch in Processing.

/* Fast Flipbook */ PImage zero; PImage one; PImage two; PImage three; PImage four; PImage five; int counter=0; void setup() { size(640,480); zero = loadImage("zero.jpg"); one = loadImage("one.jpg"); two = loadImage("two.jpg"); three = loadImage("three.jpg"); four = loadImage("four.jpg"); five = loadImage("five.jpg"); } void draw() { counter++; if (counter>5) counter=0; if (counter == 0) { image(zero,0,0); } if (counter ==1) { image(one,0,0); } if (counter==2) { image(two,0,0); } if (counter==3) { image(three,0,0); } if (counter==4) { image(four,0,0); } if (counter==5) { image(five,0,0); } }