Door de 9 gulden driehoeken (36,72,72) ontstaan 8 gulden gnomen (36,36,108)
"9g" dwz 9 gulden driehoeken, "kg" dwz van klein naar groot, zie argument 4
De argumenten van de constructor
1) "n" = de basis van de negende, grootste, driehoek,
2) "lr" = 0 driehoek naar links, "lr" = 1 driehoek naar rechts
3) "r" = aantal driehoeken (max 9), van klein naar groot, dus voor "r" = 1 is alleen de kleinste driehoek zichtbaar.
4) en 5) x, y positie van het punt linksonder voor de rechter, en rechtsonder voor de linker driehoek, dit is ook het draaipunt,
6) hoek, 7) "sw" = lijndikte, 8) lijnkleur
class Drieh_9g_kg 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 h1 = nphi*sin(radians(72)), a = nphi-nphi/phi;
let ax1 = a*cos(radians(72)), ay1 = a*sin(radians(72));
let ax2 = a*cos(radians(36)), ay2 = a*sin(radians(36));
let b = n-n/phi , c = a-a/phi;
let bx1 = (a-c)*cos(radians(36)) , by1 = (a-c)*sin(radians(36));
let d = b-b/phi , f = d-d/phi;
let ex1 = (ax2-d)-f*cos(radians(72)) , ey1 = ay2-f*sin(radians(72));
let e = c-c/phi , fx1 = ax2-(d+e/2) , fy1 = ay2-f*sin(radians(36));
let h = f-f/phi , gx1 = fx1+h*cos(radians(36)) , gy1 = fy1+h*sin(radians(36));
beginShape(); //Driehoek nphi
if (r==9 && lr==0)
{vertex(0,0); vertex(-ax2,-h1); vertex(-n,0);}
endShape(CLOSE);
beginShape();
if (r==9 && lr==1)
{vertex(0,0); vertex(ax2,-h1); vertex(n, 0);}
endShape(CLOSE);
beginShape(); //driehoek n
if ((r==8 || r==9) && lr==0)
{vertex(0,0); vertex(-ax1,-ay1); vertex(-n,0);}
endShape(CLOSE);
beginShape();
if ((r==8 || r==9) && lr==1)
{vertex(0,0); vertex(ax1,-ay1); vertex(n,0);}
endShape(CLOSE);
beginShape(); //driehoek a
if ((r==7|| r==8 || r==9) && lr==0)
{vertex(0, 0); vertex(-ax1, -ay1); vertex(-ax2, -ay2);}
endShape(CLOSE);
beginShape();
if ((r==7|| r==8 || r==9) && lr==1)
{vertex(0, 0); vertex(ax1, -ay1); vertex(ax2, -ay2);}
endShape(CLOSE);
beginShape(); //driehoek b
if ((r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-bx1,-by1);vertex(-ax1,-ay1); vertex(-ax2,-ay2);}
endShape(CLOSE);
beginShape();
if ((r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(bx1,-by1);vertex(ax1,-ay1); vertex(ax2,-ay2);}
endShape(CLOSE);
beginShape(); //driehoek c
if ((r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-bx1,-by1); vertex(-(ax2-c),-ay2); vertex(-ax2,-ay2);}
endShape(CLOSE);
beginShape();
if ((r==5 || r==6 || r==7 || r==8 || r==9) && lr==1)
{vertex(bx1,-by1); vertex(ax2-c,-ay2); vertex(ax2,-ay2);}
endShape(CLOSE);
beginShape(); //driehoek d
if ((r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-bx1, -by1);vertex(-(ax2-c),-ay2);vertex(-(ax2-d),-ay2);}
endShape(CLOSE);
beginShape();
if ((r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==1)
{vertex(bx1, -by1);vertex(ax2-c,-ay2);vertex(ax2-d, -ay2);}
endShape(CLOSE);
beginShape(); //driehoek e
if ((r==3 || r==4 || r==5 ||r==6 ||r==7 || r==8 || r==9) && lr==0)
{vertex(-ex1,-ey1); vertex(-(ax2-c),-ay2);vertex(-(ax2-d),-ay2);}
endShape(CLOSE);
beginShape();
if ((r==3 || r==4 || r==5 ||r==6 || r==7 || r==8 || r==9) && lr==1)
{vertex(ex1,-ey1); vertex(ax2-c,-ay2);vertex(ax2-d,-ay2);}
endShape(CLOSE);
beginShape(); //driehoek f
if ((r==2 || r==3 || r==4 || r==5 || r==6 || r==7 ||r==8 || r==9) && lr==0)
{vertex(-fx1, -fy1); vertex(-(ax2-d), -ay2);vertex(-ex1, -ey1);}
endShape(CLOSE);
beginShape();
if ((r==2 || r==3 || r==4 || r==5 || r==6 || r==7 || r==8 || r==9) && lr==1)
{vertex(fx1, -fy1); vertex(ax2-d, -ay2);vertex(ex1, -ey1);}
endShape(CLOSE);
beginShape(); //Driehoek g
if ((r==1 || r==2 || r==3 || r==4 || r==5 || r==6 || r==7|| r==8 || r==9) && lr==0)
{vertex(-ex1,-ey1);vertex(-fx1,-fy1);vertex(-gx1,-gy1);}
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(ex1,-ey1);vertex(fx1,-fy1);vertex(gx1,-gy1);}
endShape(CLOSE);
pop();
strokeWeight(1);
}
}