float x, y; // The current coordinates of the ball float r = 20; // ball radius float vx, vy; // ball velocity void setup() { size(400,400); smooth(); noStroke(); x = width/2; y = height/2; // start at the center vx = random(-5,5); vy = random(-5,5); // start in random direction } void draw() { background(0); ellipse(x,y,2*r,2*r); // take a step x += vx; y += vy; // bounce if getting offscreen if(x != constrain(x,r,width-r)) { x = constrain(x,r,width-r); // constrain position vx = -vx; // flip velocity } if(y != constrain(y,r,width-r)) { y = constrain(y,r,width-r); // constrain position vy = -vy; // flip velocity } } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }