I made a little change to your initial sketch:
Code:void setup() {
size(400,400);
smooth();
strokeWeight(5);
}
void draw() {
background (255);
display (100, 100, 100, PI/2*mouseX / width );
}
void display (int x, int y, int d, float a) {
pushMatrix();
translate(x,y);
rotate(PI-a);
stroke (255,0,0); //red line
line(0,0, d,0);
translate(d,0); // Go to end of red line
rotate(2*a-PI);
stroke (255,0,255); //purple line
line(0,0, d,0);
popMatrix ();
pushMatrix();
translate(x,y);
rotate(a);
stroke (0,255,0); //green line
line(0,0, d,0);
translate(d,0); // Go to end of green line
rotate(PI-2*a);
stroke (0,0,255); //blue line
line(0,0, d,0);
popMatrix ();
}
Therefore, doing the same thing with rectangles was easy:
Code:void setup() {
size(400,400);
smooth();
strokeWeight(5);
}
void draw() {
background (255);
display (100, 100, 100, PI/2*mouseX / width );
}
float w = 322/6; float h = 595/6;
void display (int x, int y, int d, float a) {
pushMatrix();
translate(x,y);
rotate(PI-a);
stroke (255,0,0); //red line
rect(0,0,w,h);
//line(0,0, d,0);
translate(w,0); // Go to end of red line
rotate(2*a-PI);
stroke (255,0,255); //purple line
rect(0,0,w,h);
//line(0,0, d,0);
popMatrix ();
pushMatrix();
translate(x,y);
rotate(a);
stroke (0,255,0); //green line
rect(0,0,w,-h);
//line(0,0, d,0);
translate(w,0); // Go to end of green line
rotate(PI-2*a);
stroke (0,0,255); //blue line
rect(0,0,w,-h);
//line(0,0, d,0);
popMatrix ();
}