// Based on Processing example Topics | Drawing | Animator PImage[] frames = new PImage[100]; boolean create = true; // drawing or playing back int currentFrame = 0; // displayed frame int numFrames = 0; // number of frames in the animation int timer = 0; // number of frames before the next boolean clearFrame = false; // whether to clear every frame void setup() { size(500, 300); smooth(); background(0); frameRate(60); reset(); } // reset the sketch to contain only an empty frame void reset() { background(0); frames[0] = get(); numFrames = 1; currentFrame = 0; timer = 30; } // advance to the next frame void advance() { currentFrame = (currentFrame+1)%numFrames; timer = 10; } void draw() { // update the drawing if(create) { // draw on the sketch if(mousePressed) { strokeWeight(12); stroke(255); line(mouseX,mouseY,pmouseX,pmouseY); } // if the timer is done if(timer == 0) { // grab it frames[numFrames] = get(); numFrames++; if(clearFrame) background(0); advance(); } else timer--; // decrease the timer } else { // draw the image image(frames[currentFrame],0,0); // scrubbing ala iMovie if(mousePressed) { currentFrame = constrain((numFrames*mouseX)/width,0,numFrames-1); timer = 10; } else { // advance if the timer is done, or decrese the timer if(timer == 0) advance(); else timer--; } } // draw the frame bar fill(0); noStroke(); rect(0,height-20,width,20); for(int i = 0; i < numFrames; i ++) { stroke(128); strokeWeight(3); point(width*(i+0.5)/(numFrames),height-10); } stroke(255); point(width*(currentFrame+0.5)/(numFrames),height-10); } // used to reseat the sketch void keyPressed() { if(key == ' ') { create = !create; if(create) reset(); else advance(); } if(key == 'c') clearFrame = !clearFrame; } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }