// Based on Processing example Topics | Drawing | Animator // and Reas & Fry Synthesis | Chronodraw, by Andreas Gysin (www.ertdfgcvb.ch) PImage[] frames = new PImage[25]; boolean create = true; // drawing or playing back int currentFrame = 0; // displayed frame int numFrames = frames.length; // number of frames in the animation (fixed in this case) int timer = 0; // number of frames before the next boolean clearFrame = false; // whether to clear every frame int numStrips = 11; // number of strips to draw int stripWidth; // set later on int timeBarHeight = 20; // time bar height void setup() { size(550, 300); smooth(); background(0); frameRate(60); stripWidth = width / numStrips; reset(); } // reset the sketch to contain only an empty frame void reset() { background(0); for(int i = 0; i < numFrames; i ++) { frames[i] = get((numStrips/2) * stripWidth,0,stripWidth,height); } currentFrame = 0; timer = 30; } // advance to the next frame void advance() { if(currentFrame < numFrames-1) currentFrame++; timer = 10; } void draw() { // draw all other strips fill(128); stroke(64); strokeWeight(1); for(int i = -numStrips/2; i <= numStrips/2; i ++) { if(i == 0) continue; rect((i+numStrips/2)*stripWidth,0,stripWidth,height); tint(255,128); if(i+currentFrame >= 0 && i+currentFrame < numFrames) { image(frames[i+currentFrame],(i+numStrips/2)*stripWidth,0); } } // update the drawing for the active strip 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[currentFrame] = get((numStrips/2) * stripWidth,0,stripWidth,height); if(clearFrame) { noStroke(); fill(0); rect((numStrips/2) * stripWidth,0,stripWidth,height); } advance(); } else timer--; // decrease the timer } else { // draw the image tint(255); image(frames[currentFrame],(numStrips/2) * stripWidth,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 noStroke(); fill(0); rect(0,height-timeBarHeight,width,timeBarHeight); for(int i = 0; i < numFrames; i ++) { stroke(128); strokeWeight(3); point(width*(i+0.5)/(numFrames),height-timeBarHeight/2); } stroke(255); point(width*(currentFrame+0.5)/(numFrames),height-timeBarHeight/2); } // used to reseat the sketch void keyPressed() { if(key == ' ') { create = !create; if(create) reset(); else { currentFrame = -1; advance(); } } if(key == 'c') clearFrame = !clearFrame; } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }