Animation animation1; void setup() { size(400, 300); frameRate(8); animation1 = new Animation("_", 26); } void draw() { if (mousePressed) { animation1.displayZ(0, 0); } else { animation1.displayA(0, 0); } } // Class for animating a sequence of GIFs class Animation { PImage[] images; int imageCount; int frame; Animation(String imagePrefix, int count) { imageCount = count; images = new PImage[imageCount]; for (int i = 0; i < imageCount; i++) { // Use nf() to number format 'i' String filename = imagePrefix + nf(i, 3) + ".JPG"; images[i] = loadImage(filename); } } void displayA(float a, float b) { frame = (frame+1) % imageCount; image(images[frame], 0, 0); //println("A"+ frame); } void displayZ(float a, float b) { frame = abs(frame-1) % imageCount; image(images[frame], 0, 0); //println("Z"+ frame); } int getWidth() { return images[0].width; } }