// the vertical position of the box float yPos; // the acceleration rate of the box (negative is up, positive is down) float rate; // the constant rate of gravity (9.8m/s^2 / 10) float gravityRate = 0.98; // the size of the box int boxSize = 10; // the desired frame rate int fps = 60; void setup() { frameRate(fps); size(200, 200); // current position is at the top (0) yPos = 0; // current acceleration rate is 0 (simulates dropping) rate = 0; noStroke(); fill(255); } void draw() { // black background background(0); // once we hit the floor, reverse the acceleration // so that we're going up. if (rate != 0 && yPos >= height - boxSize) { // lose a little bit in the process (i.e., deformation) rate *= -0.95; } // add more gravity! rate += (gravityRate / fps); // add the rate to the position yPos += rate; // don't draw below the floor if (yPos >= height - boxSize) yPos = height - boxSize; // draw the box rect(95, yPos, boxSize, boxSize); }