/* Sample processing program for CS112 Spring 2015 it would be a good idea to add an x velocity and have the ball bounce off the sides */ float x; // keep track of the ball's x and y position float y; float yvelocity; // keep track of the ball's y veloicity void setup(){ // setup() is run once to setup the program size(500,300); // create the window x = 10; // set the ball's initial x and y position y = 10; yvelocity = 2; // set the ball's initial y velocity } void draw(){ // draw() is run in an infinite loop fill(random(0,255),random(0,255),random(0,255)); // amount of red, green, and blue from 0 - 255 to fill the ball background(100,200,100); // draw in the background stroke(100,100,0); // set the color of the ball's outline ellipse(x,y,40,20); // draw the ball x = x + 1; // change the ball's x position y = y + yvelocity; // change the ball's y position if(y > height){ // bounce off the bottom of the screen yvelocity = yvelocity * -1; } if(y < 0){ // bounce off the top of the screen yvelocity = yvelocity * -1; } }