|
float x,y,a,b,p,q,w,z;
float x_speed,y_speed,a_speed,b_speed,p_speed,q_speed,w_speed,z_speed;
int x_direction,y_direction,a_direction,b_direction,p_direction,q_direction,w_direction,z_direction;
void setup(){
size(300,300);
//object1
x_direction=1;
y_direction=1;
x_speed=1.2;
y_speed=1.8;
//object2
a_direction=1;
b_direction=1;
a_speed=1.9;
b_speed=1.3;
//object3
p_direction=1;
q_direction=1;
p_speed=0.5;
q_speed=2.3;
//object4
w_direction=1;
z_direction=1;
w_speed=1.1;
z_speed=0.07;
}
void loop(){
background(255,255,255);
DrawObject1();
DrawObject2();
DrawObject3();
DrawObject4();
}
//object1
void DrawObject1(){
x= x + x_direction*x_speed;
y= y + y_direction*y_speed;
rect(x,y,30,30);
stroke(x,y,a);
line(x,y,a,b);
//bounce
if(x>300-30 || x<0){
x_direction = x_direction*-1;
}
if(y>300-30 || y<0){
y_direction = y_direction*-1;
}
}
//object2
void DrawObject2(){
a= a + a_direction*a_speed;
b= b + b_direction*b_speed;
rect(a,b,10,10);
stroke(a,b,p);
line(a,b,p,q);
//bounce
if(a>300-10 || a<0){
a_direction = a_direction*-1;
}
if(b>300-10 || b<0){
b_direction = b_direction*-1;
}
}
//object3
void DrawObject3(){
p= p + p_direction*p_speed;
q= q + q_direction*q_speed;
rect(p,q,5,5);
stroke(p,q,w);
line(p,q,w,z);
//bounce
if(p>300-5|| p<0){
p_direction = p_direction*-1;
}
if(q>300-5 || q<0){
q_direction = q_direction*-1;
}
}
//object4
void DrawObject4(){
w= w + w_direction*w_speed;
z= z + z_direction*z_speed;
rect(w,z,7,7);
stroke(w,z,x);
line(w,z,x,y);
//bounce
if(w>300-7 || w<0){
w_direction = w_direction*-1;
}
if(z>300-7 || z<0){
z_direction = z_direction*-1;
}
}
|