Daphne Bouncingballs
int d1; 
int d2;
int px1;
int px2;
int py1;
int py2;
boolean xBouncing1 = true;
boolean xBouncing2 = true;
boolean yBouncing1 = true;
boolean yBouncing2 = true;
 
void setup(){
 size(400,400);
 smooth();
 px1=1;
 px2=1;
 py1=1;
 py2=height;
 d1=30;
 d2=60;
 xBouncing1 = true;
 xBouncing2 = true;
 yBouncing1 = true;
 yBouncing2 = true;
}
 
void draw(){
 background(100);
 //draw the ellipse1
 fill(px1,py1,py2);
 ellipse(px1, py1,d1,d1);
 if (xBouncing1){
 px1 = px1 +2;
// py1 = py1 +2;
 }else{
 px1 = px1 -3;
// py1 = py1 -2;
 }
 if (yBouncing1){
   py1=py1+1;
 }else{
   py1 = py1-3;
 }
   if (px1 >=width - (d1/2)){
   xBouncing1 = false;
}
if(py1>=height - (d1/2)){
  yBouncing1 = false;
}
  if (px1 < 0 + (d1/2)){
   xBouncing1 = true;
}
if(py1 < 0 + (d1/2)) {
  yBouncing1 = true;
}
 
 //draw the ellipse2 
fill(px1,py1,px2);
 ellipse(px2, py2,d2,d2); 
if (xBouncing2){
 px2 = px2 +6;
 //py2 = py2 -2;
  }else{
px2 = px2 -5;
 //py2 = py2 -2;
}
 if (yBouncing2){
   py2=py2+1;
}else{
   py2 = py2-1;
}
 if (px2 >=width - (d2/2)){
 xBouncing2 = false;
}
if(py2>=height - (d2/2)){
  yBouncing2 = false;
}
  if (px2 < 0 + (d2/2)){
 xBouncing2 = true;
 }
 if(py2 < 0 + (d2/2)) {
  yBouncing2 = true;
}
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License