//ball bounces around in a random pattern, different each time or after a count of a certain amount //ball changes color as it moves //screen clears after a certain amount of time or with a mousepress and a new background color is made float r; float g; float b; float a; float diam; int count=0; int reset=0; //this should initialize starting point to center but must not work here since it doesn't know these until setup?? float x=width/2; float y=height/2; //variables for speed in the horizontal and vertical direction. float xspeed = 6; float yspeed = 3; void setup() { size(2560,1600); smooth(); frameRate(25); } void draw() { r = random(255); g = random(255); b = random(255); a = random(255); diam = random(100); count=count+1; reset=reset+1; //after 50 passes, change the starting position and relative x-y speeds to change direction if (count>50){ x = random(width); y = random(height); xspeed=int(random (5,50)); yspeed=int(random (5,50)); count=0; } // Change the location of circle by speed x = x + xspeed; y = y + yspeed; // bounces ball of edge of screen going right-left if ((x > width) || (x < 0)) { xspeed = xspeed * -1; } // bounces ball of edge of screen going up-down if ((y > height) || (y < 0)) { yspeed = yspeed * -1; } // Draw circle fill(r,g,b,a); ellipse(x,y,diam,diam); //reset the background by number of passes (here 1 minute based on framerate) or by pressing the mouse if (reset > 1500 || mousePressed) { background(r,g,b); reset=0; } }