9 gouden driehoeken met de top van de driehoek in het (0,0) punt
"9gt" dwz 9 gouden driehoeken met het draaipunt in de top van de grootste driehoek, "gk' dwz van groot naar klein, zie argument 4
Door de 9 gulden driehoeken (36,72,72) ontstaan 8 gulden gnomen (36,36,108)
De argumenten van de constructor
1) "n" = de basis van de eerste grootste, driehoek,
2) "lr" = 0 driehoek naar links, "lr" = 1 driehoek naar rechts
3) "r" = aantal driehoeken (max 9), van groot naar klein, dus voor "r" = 1 is de grootste driehoek zichtbaar.
4) en 5) x, y positie van de top van de grootste driehoek dit is ook het draaipunt,
6) hoek, 7) "sw" = lijndikte, 8) "c" lijnkleur
class Drieh_9gt_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.lr = lr; this.r = r;
this.x = x; this.y = y;
this.hoek = hoek; this.sw = sw; this.c = c; this.r = r;
}
display() {
stroke(this.c);
strokeWeight(this.sw);
let lr = this.lr; let r = this.r; let n = this.n;
noFill();
push();
translate(this.x, this.y);
rotate(radians(this.hoek));
let phi= (1+sqrt(5))/2 , nphi = n*phi;
let h1 = nphi*sin(radians(72)) , a = nphi-nphi/phi;
let ax1 = (nphi-a)*cos(radians(72)) , ay1 = (nphi-a)*sin(radians(72));
let b = n-n/phi , ay2 = ay1+b*sin(radians(36));
let c = a-a/phi , bx1 = c*cos(radians(36));
let by1 = ay2+c*sin(radians(36));
let d = b-b/phi , e = c-c/phi , f = d-d/phi ,h = f-f/phi;
let ex1 = c-(e-f*cos(radians(72))) , ey1 = ay2+f*sin(radians(72));
let fx1 = (c-e)+f*cos(radians(36)) , fy1 = ay2+f*sin(radians(36));
let gx1 = (c-e)+(f-h)*cos(radians(36)) , gy1 = ay2+(f-h)*sin(radians(36));
//Driehoek schuine zijde: nphi, basis: n
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(n/2,h1); vertex(-n/2,h1);}
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(n/2,h1); vertex(-n/2,h1);}
endShape(CLOSE);
//driehoek schuine zijde: n, basis: a
beginShape();
if ((r==2 || r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(n/2,h1); vertex(ax1, ay1); vertex(-n/2,h1);}
endShape(CLOSE);
beginShape();
if ((r==2 || r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(-n/2,h1); vertex(-ax1,ay1); vertex(n/2,h1);}
endShape(CLOSE);
//driehoek schuine zijde: a, basis: b
beginShape();
if ((r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(n/2, h1); vertex(ax1, ay1); vertex(0, ay2);}
endShape(CLOSE);
beginShape();
if ((r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(-n/2, h1); vertex(-ax1, ay1); vertex(0, ay2);}
endShape(CLOSE);
//driehoek schuine zijde: b basis: c
beginShape();
if ((r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(bx1,by1);vertex(ax1,ay1); vertex(0,ay2);}
endShape(CLOSE);
beginShape();
if ((r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(-bx1,by1);vertex(-ax1,ay1); vertex(0,ay2);}
endShape(CLOSE);
//driehoek schuine zijde: c, basis: d
beginShape();
if ((r == 5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(bx1, by1); vertex(c ,ay2); vertex(0,ay2);}
endShape(CLOSE);
beginShape();
if ((r == 5 || r==6 || r==7 || r==8 || r==9) && lr==1)
{vertex(-bx1, by1); vertex(-c,ay2); vertex(0, ay2);}
endShape(CLOSE);
//driehoek schuine zijde: d, basis: e
beginShape();
if ((r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(bx1, by1);vertex(c,ay2);vertex(c-e, ay2);}
endShape(CLOSE);
beginShape();
if ((r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(-bx1, by1);vertex(-c,ay2);vertex(-(c-e), ay2);}
endShape(CLOSE);
//driehoek schuine zijde: e, basis: f,
beginShape();
if ((r==7 || r==8 || r==9) && lr==0)
{vertex(ex1,ey1); vertex(c, ay2);vertex(c-e,ay2);}
endShape(CLOSE);
beginShape();
if ((r==7|| r==8 || r==9) && lr==1)
{vertex(-ex1,ey1); vertex(-c,ay2);vertex(-(c-e),ay2);}
endShape(CLOSE);
//driehoek schuine zijde: f basis: g
beginShape();
if ((r==8 || r==9) && lr==0)
{vertex(fx1, fy1); vertex(c-e, ay2);vertex(ex1, ey1);}
endShape(CLOSE);
beginShape();
if ((r==8 || r==9) && lr==1)
{vertex(-fx1, fy1); vertex(-(c-e), ay2);vertex(-ex1, ey1);}
endShape(CLOSE);
//Driehoek schuine zijde: g basis: h
beginShape();
if (r==9 && lr==0)
{vertex(ex1,ey1);vertex(fx1,fy1);vertex(gx1,gy1);}
endShape(CLOSE);
beginShape();
if (r==9 && lr==1)
{vertex(-ex1,ey1);vertex(-fx1,fy1);vertex(-gx1,gy1);}
endShape(CLOSE);
pop();
strokeWeight(1);
}
}