// bounce // Copyright © 2011 Mark F. Russo // Bryn Mawr College, Department of Computer Science // Permission is granted to copy and distribute provided // this entire copyright notice is reproduced in all copies. float sx = 0.0; // x position float sy = 0.0; // y position float vx = 1.0; // x velocity float vy = 1.0; // y velocity float ay = 0.2; // y acceleration (gravity) void setup() { size(500, 500); fill(255, 0, 0); smooth(); ellipseMode(CENTER); } void draw() { // Equations of Motion sx = sx + vx; sy = sy + vy; vy = vy + ay; // Bounce off walls if (sx <= 0.0 || sx >= width) vx = -vx; // Bounce off floor and // lose some velocity due to friction if (sy >= (height-10.0)) vy = -0.9*vy; // Draw at current location background(255); ellipse(sx, sy, 20, 20); }