xxxxxxxxxx
Thickrect r1,r2,r3,r4;
void setup(){
size(400,400);
background(150);
r1=new Thickrect(150,150,100,100,2,3);
r2=new Thickrect(250,150,100,100,3,4);
r3=new Thickrect(250,250,100,100,1,4);
r4=new Thickrect(150,250,100,100,1,2);
}
void draw(){
background(200);
r1.update();
r2.update();
r3.update();
r4.update();
r1.display();
r2.display();
r3.display();
r4.display();
}
class Thickrect{
float x,y;
float wd,ht;
// int ori1,ori2;
float angle1,angle2;
float angleSpeed;
Thickrect(float x, float y, float wd, float ht,int ori1,int ori2){
this.x=x;
this.y=y;
this.wd=wd;
this.ht=ht;
switch (ori1){
case 1:
angle1=-HALF_PI;
break;
case 2:
angle1=0;
break;
case 3:
angle1=HALF_PI;
break;
case 4:
angle1=PI;
break;
}
switch (ori2){
case 1:
angle2=-HALF_PI;
break;
case 2:
angle2=0;
break;
case 3:
angle2=HALF_PI;
break;
case 4:
angle2=PI;
break;
}
angleSpeed=0.03;
}
void update(){
angle1+=angleSpeed;
angle2+=angleSpeed;
}
void display(){
fill(255);
strokeWeight(6);
rectMode(CENTER);
rect(x,y,wd,ht);
point(x,y);
strokeWeight(1);
line(x,y,x+wd/2*cos(angle1),y+ht/2*sin(angle1));
line(x,y,x+wd/2*cos(angle2),y+ht/2*sin(angle2));
}
}