/** * Squashing * * Math for artists who now need to program * ITP DriveBy, 10/2/2008 * Elie Zananiri - ez@silentlycrashing.net */ //---------------------------- // variables float currY; int currTime; //---------------------------- void setup() { // set up the applet size(300, 300); smooth(); frameRate(15); // reset the animation independent variable (time) currTime = 0; // set the ball color noStroke(); fill(#FF6F00); } //---------------------------- void draw() { // clear the screen background(0); // move the ball currY = move(currTime); // draw the ball if (currTime%55 == 54) { // squash it! ellipse(width/2, currY - 5, 30, 10); } else { ellipse(width/2, currY, 20, 20); } currTime = (currTime+1)%55; //if (currTime > 55) { // currTime = 0; //} } //---------------------------- void mousePressed() { // reset the animation independent variable (time) currTime = 0; } //---------------------------- float move(float x) { return (0.1 * pow(x, 2) + 10); }