Bounce

Here is my code:

float xPos;
float yPos;
float diam = 50;
float xSpeed;
float ySpeed;
float xPos2 = 350;
float yPos2 = 25;
float xSpeed2 = 3;
float ySpeed2 = 4;

color ballColor1=(#CC99FF);
color ballColor2 =(#FFE2E2);

void setup() {
size(400, 300);
noStroke();
background(#99CCFF);

xPos = random(0, width);
yPos = random(0, height);

xSpeed = random(-5.0, 5.0);
ySpeed = random(-5.0, 5.0);

}

void draw() {
background(#99CCFF);

fill(ballColor1);
ellipse(xPos, yPos, 50, 50);
fill(ballColor2);
ellipse(xPos2, yPos2, diam, diam);

xPos = xPos+xSpeed;
yPos = yPos+ySpeed;

xPos2 = xPos2 + xSpeed2;
yPos2 = yPos2 + ySpeed2;

if (xPos > width || xPos < 0) {
xSpeed = xSpeed*-1;
}
if (yPos > height || yPos < 0) {
ySpeed = ySpeed*-1;
}
if (xPos2 > width-diam/2 || xPos2 < diam/2) {
xSpeed2 = -xSpeed2;

}
if (yPos2 > height-diam/2 || yPos2 < diam/2) {
ySpeed2 = -ySpeed2;
}

}

 

Here is my movie: bounce

Comments are closed.