A work in progress
October 3rd, 2011

## Bouncing Ball 2

Click the ball to change it’s color.

Press U, D, F, S, R to manipulate the ball.

Source Code
``` float x=0;
float y=0;

float color1=0;
float color2=0;
float color3=0;

float velocity_x=7;
float velocity_y=3;

float x_length = 800;
float y_length = 800;

float diameterc = 150;

float x_left_bound;
float x_right_bound;

float y_upper_bound;
float y_lower_bound;

float diameter_increase;

void setup() {

size(800,800);

}

void draw() {

background(125,125,125);

fill(color1,color2,color3);

x_left_bound = diameterc/2;
x_right_bound = x_length-(diameterc/2);

y_upper_bound = diameterc/2;
y_lower_bound = y_length-(diameterc/2);

if ((x &rt; (x_right_bound-(velocity_x/2))) && (x < (x_right_bound+(velocity_x/2)))) {

velocity_x=velocity_x*-1;

}

else if ((velocity_x < 0) && (x < (x_left_bound-(velocity_x/2))) && (x &rt; (x_left_bound+(velocity_x/2))))

{

velocity_x=velocity_x*-1;

}

if ((y &rt; (y_lower_bound-(velocity_y/2))) && (y < (y_lower_bound+(velocity_y/2)))) {

velocity_y=velocity_y*-1;

}

else if ((velocity_y < 0) && (y < (y_upper_bound-(velocity_y/2))) && (y &rt; (y_upper_bound+(velocity_y/2))))  {

velocity_y=velocity_y*-1;

}

if(keyPressed) {
if (key == 'r' || key == 'R') {
velocity_y=velocity_y*-1;
velocity_x=velocity_x*-1;

}}

if(keyPressed) {
if (key == 'f' || key == 'F') {
velocity_y=velocity_y*1.1;
velocity_x=velocity_x*1.1;

}
}

if(keyPressed) {
if (key == 's' || key == 'S') {
velocity_y=velocity_y*.9;
velocity_x=velocity_x*.9;

}
}

x=velocity_x+x;
y=velocity_y+y;

if(keyPressed) {

if (key == 'u' || key == 'U') {
y = velocity_y+y-10;
}
}

if (keyPressed) {

if  (key == 'd' || key == 'D') {
y = velocity_y+y+10;
}
}

ellipse(x,y,diameterc, diameterc);

if ((mouseX <= (x+(diameterc/2))) && (mouseX &rt;=(x-(diameterc/2))) && (mouseY &rt;= (y-(diameterc/2))) && (mouseY <= (y+(diameterc/2)))) {

if (mousePressed==true) {

color1 = random(255);
color2 = random(255);
color3 = random(255);

}
}
}
```