gouden rechthoeken class "Rechth_9g_gk" in p5.js terug naar de inleiding
rechthoeken "lr" = 0, "r" = 9 rechthoeken "lr" = 1, "r" = 9
De draaipunten staan in het (0,0) punt
Met deze class kan je max 9 gouden rechthoeken creeeren, zo ontstaan 8 vierkanten
"Rechth_9g_gk" is een hulpmiddel om spiralen en andere gouden vormen in een schets te positioneren. gk dwz van groot naar klein, zie argument 4
De argumenten van de constructor
1) "n" = lengte van de korte zijde van de rechthoek, 2) "lr" = 0 rechthoeken staan links, "lr" = 1 rechthoeken staan rechts
3) "r" = aantal rechthoeken (max 9), van groot naar klein, dus met "r" = 1 is de grootste rechthoek zichtbaar
4) en 5) x, y positie, 6) hoek, 7) "sw" = lijndikte , 8) "c" = lijnkleur
n, a, b, c, d, e, f, g en h zijn de korte zijden van de 9 gouden rechthoeken en de zijden van de 8 ontstane vierkanten
class Rechth_9g_gk extends Vormen {
//constructor 1 2 3 4 5 6 7 8
constructor(n, lr, r, x, y, hoek, sw, c) {
super(x,y,hoek);
this.n = n; this.sw = sw; this.lr = lr; this.r = r;
this.x = x; this.y = y;
this.hoek = hoek; this.c = c;
}
display() {
stroke(this.c);
strokeWeight(this.sw);
noFill();
let lr = this.lr; let r = this.r; let n = this.n;
push();
translate(this.x, this.y);
rotate(radians(this.hoek));
let phi= (1+sqrt(5))/2; let nphi = n*phi;
let a = nphi-nphi/phi, b = n-n/phi , c = a-a/phi, d = b-b/phi;
let e = c-c/phi , f = d-d/phi , g = e-e/phi , h = f-f/phi;
beginShape();
if ((r==1 || r==2 || r==3 || r==4 || r==5 || r==6 || r==7 || r==8 || r==9) && lr==0)
{vertex(0,0); vertex(0,-n); vertex(-nphi,-n); vertex(-nphi,0);}
endShape(CLOSE);
beginShape();
if ((r==1 || r==2 || r==3 || r==4 || r==5 || r==6 || r==7 || r==8 || r==9) && lr==1)
{vertex(0,0); vertex(0,-n); vertex(nphi,-n); vertex(nphi ,0);}
endShape(CLOSE);
beginShape();
if ((r==2 || r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-n,0); vertex(-n,-n); vertex(-(n+a),-n); vertex(-(n+a),0);}
endShape(CLOSE);
beginShape();
if ((r==2 || r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(n,0); vertex(n,-n); vertex(n+a,-n); vertex(n+a,0);}
endShape(CLOSE);
beginShape();
if ((r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-n, 0); vertex(-n, -b); vertex(-(n+a), -b); vertex(-(n+a),0);}
endShape(CLOSE);
beginShape();
if ((r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(n, 0); vertex(n, -b); vertex(n+a, -b); vertex(n+a,0);}
endShape(CLOSE);
beginShape();
if ((r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-n,0);vertex(-n,-b); vertex(-(n+c),-b); vertex(-(n+c),0);}
endShape(CLOSE);
beginShape();
if ((r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(n,0);vertex(n,-b); vertex(n+c,-b); vertex(n+c,0);}
endShape(CLOSE);
beginShape();
if ((r == 5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-n,-c); vertex(-n,-(c+d)); vertex(-(n+c),-(c+d)); vertex(-(n+c),-c);}
endShape(CLOSE);
beginShape();
if ((r == 5 || r==6 || r==7 || r==8 || r==9) && lr==1)
{vertex(n,-c); vertex(n,-(c+d)); vertex(n+c,-(c+d)); vertex(n+c,-c);}
endShape(CLOSE);
beginShape();
if ((r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-(n+c-e), -c);vertex(-(n+c-e), -(d+c));vertex(-(n+c), -(d+c));vertex(-(n+c), -c);}
endShape(CLOSE);
beginShape();
if ((r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(n+c-e, -c);vertex(n+c-e,-(d+c));vertex(n+c, -(d+c));vertex(n+c,-c);}
endShape(CLOSE);
beginShape();
if ((r==7 || r==8 || r==9) && lr==0)
{vertex(-(n+d),-c);vertex(-(n+d),-(c+f));vertex(-(n+d+e),-(c+f));vertex(-(n+d+e),-c);}
endShape(CLOSE);
beginShape();
if ((r==7|| r==8 || r==9) && lr==1)
{vertex(n+d,-c);vertex(n+d,-(c+f));vertex(n+d+e,-(c+f));vertex(n+d+e,-c);}
endShape(CLOSE);
beginShape();
if ((r==8 || r==9) && lr==0)
{vertex(-(n+d), -c);vertex(-(n+d), -(c+f));vertex(-(n+d+g), -(f+c));vertex(-(n+d+g), -c);}
endShape(CLOSE);
beginShape();
if ((r==8 || r==9) && lr==1)
{vertex(n+d, -c);vertex(n+d, -(c+f));vertex(n+d+g, -(f+c));vertex(n+d+g, -c);}
endShape(CLOSE);
beginShape();
if (r==9 && lr==0)
{vertex(-(n+d),-c);vertex(-(n+d), -(c+f-h));vertex(-(n+d+g),-(c+f-h));vertex(-(n+d+g), -c);}
endShape(CLOSE);
beginShape();
if (r==9 && lr==1)
{vertex(n+d,-c);vertex(n+d,-(c+f-h));vertex(n+d+g,-(c+f-h));vertex(n+d+g, -c);}
endShape(CLOSE);
pop();
strokeWeight(1);
}
}