|
//bounce
float a;
float b;
float x;
float y;
float x_direction;
float y_direction;
float a_direction;
float b_direction;
float x_speed;
float y_speed;
float a_speed;
float b_speed;
void setup(){
size(300,300);
x_direction=1;
y_direction=1;
a_direction=1;
b_direction=1;
x_speed=2.1;
y_speed=2.9;
a_speed=1.1;
b_speed=6.9;
}
void loop(){
x=x+x_direction*x_speed;
y=y+y_direction*y_speed;
background(255,255,255);
ellipse(x,y,30,30);
if(x>300-30 ){
x_direction=-1;
}
if(x<0 ){
x_direction=1;
}
if(y>300-30){
y_direction=-1;
}
if(y<0){
y_direction=1;
}
a=a+a_direction*a_speed;
b=b+b_direction*b_speed;
ellipse(230-a,b,70,70);
if(a>300-70){
a_direction=-1;
}
if(a<0 ){
a_direction=1;
}
if(b>300-70){
b_direction=-1;
}
if(b<0){
b_direction=1;
}
}
|
|