xxxxxxxxxx
int sq1_x;
int sq1_y;
int sq1_wh;
void setup() {
size(805, 805);
frameRate(50);
}
void draw() {
background(255);
sq1_x = 0;
sq1_y = 0;
sq1_wh = 300;
// a coords
float sq1_ax = sq1_x - (sq1_wh/2);
float sq1_ay = sq1_y - (sq1_wh/2);
// b coords
float sq1_bx = sq1_x + (sq1_wh/2);
float sq1_by = sq1_y - (sq1_wh/2);
// c coords
float sq1_cx = sq1_x - (sq1_wh/2);
float sq1_cy = sq1_y + (sq1_wh/2);
// d coords
float sq1_dx = sq1_x + (sq1_wh/2);
float sq1_dy = sq1_y + (sq1_wh/2);
// Triangle Angles
float A = mouseY;
float C = 90;
float B = 180 - (A + C);
// Triangle Side Lengths
float c = sq1_wh; // hypotenuse length
float a = round((c * sin(radians(A)))/sin(radians(C)));
float b = round((c * sin(radians(B)))/sin(radians(C))); //floor(sqrt(pow(c, 2) + pow(a, 2) - 2*c*a*cos(radians(B))));
// Triangle 1 coordinates
float A1_x = sq1_ax;
float A1_y = sq1_ay;
float B1_x = sq1_bx;
float B1_y = sq1_by;
float C1_x = A1_x + (cos(radians(A))*b);
float C1_y = A1_y + (sin(radians(A))*b);
strokeWeight(5);
strokeJoin(ROUND);
pushMatrix();
translate(width/2, height/2);
// draw square 1
fill(232, 39, 39);
rectMode(CENTER);
rect(sq1_x, sq1_y, sq1_wh, sq1_wh);
// Draw Triangles
for (int x = 0; x < 4; x++) {
rotate(radians(90));
noFill();
triangle(A1_x, A1_y, B1_x, B1_y, C1_x, C1_y);
}
popMatrix();
}