xxxxxxxxxx
105
let x = [];
let y = [];
let z = [];
let xs = [];
let ys = [];
let zs = [];
let rx;
let ry;
let rz;
let shapes;
let s = 60;
let t = 0;
let tt =0;
let phi = 1.618;
function setup() {
createCanvas(1440, 720, WEBGL);
//colorMode(HSB);
angleMode(DEGREES);
x = [1,-1,1,1,-1,-1,1,-1,0, 0, 0, 0, 1/phi,1/phi,-1/phi,-1/phi,phi, -phi, phi, -phi];
y = [1,1,-1,1,-1,1,-1,-1,phi, -phi, phi, -phi, 0, 0, 0, 0, 1/phi,1/phi,-1/phi,-1/phi];
z = [1,1,1,-1,1,-1,-1,-1,1/phi,1/phi,-1/phi,-1/phi,phi, -phi, phi, -phi, 0, 0, 0, 0];
for(var i=0; i<x.length; i++){
x[i]*=s;
y[i]*=s;
z[i]*=s;
}
}
function tri(a,b,c){
beginShape();
vertex(x[a]-
(sc*abs(x[a])/x[a]*sqrt((sq(x[a])+sq(y[a])+sq(z[a]))/3))/s,y[a]-(sc*abs(y[a])/y[a]*sqrt((sq(x[a])+sq(y[a])+sq(z[a]))/3))/s,z[a]-(sc*abs(z[a])/z[a]*sqrt((sq(x[a])+sq(y[a])+sq(z[a]))/3))/s);
vertex(x[b]-
(sc*abs(x[b])/x[b]*sqrt((sq(x[b])+sq(y[b])+sq(z[b]))/3))/s,y[b]-(sc*abs(y[b])/y[b]*sqrt((sq(x[b])+sq(y[b])+sq(z[b]))/3))/s,z[b]-(sc*abs(z[b])/z[b]*sqrt((sq(x[b])+sq(y[b])+sq(z[b]))/3))/s);
vertex(x[c]-
(sc*abs(x[c])/x[c]*sqrt((sq(x[c])+sq(y[c])+sq(z[c]))/3))/s,y[c]-(sc*abs(y[c])/y[c]*sqrt((sq(x[c])+sq(y[c])+sq(z[c]))/3))/s,z[c]-(sc*abs(z[c])/z[c]*sqrt((sq(x[c])+sq(y[c])+sq(z[c]))/3))/s);
vertex(x[a]-
(sc*abs(x[a])/x[a]*sqrt((sq(x[a])+sq(y[a])+sq(z[a]))/3))/s,y[a]-(sc*abs(y[a])/y[a]*sqrt((sq(x[a])+sq(y[a])+sq(z[a]))/3))/s,z[a]-(sc*abs(z[a])/z[a]*sqrt((sq(x[a])+sq(y[a])+sq(z[a]))/3))/s);
endShape();
}
function makeshapes() {
beginGeometry();
for(var j=0; j<x.length; j++){
for(var k=j; k<x.length; k++){
for(var l=j; l<x.length; l++){
if(j!=k && j!=l && k!=l){
d1 = sqrt(sq(x[j]-x[k])+sq(y[j]-y[k])+sq(z[j]-z[k]));
d2 = sqrt(sq(x[j]-x[l])+sq(y[j]-y[l])+sq(z[j]-z[l]));
d3 = sqrt(sq(x[l]-x[k])+sq(y[l]-y[k])+sq(z[l]-z[k]));
if(d1<s*1.8 && d2<s*1.8 && d3<s*2.2){
c = color((tt + t + 255*j/x.length)%255, (1.618*tt + t + 255*k/x.length)%255,(tt*3 + t + 255*l/x.length)%255,60)
fill(c);
t = PI/4*((sin(frameCount/2)/2 + 0.5));
sc =0.25+ 37*((sin(frameCount/2+180)/2 + 0.5));
if(x[j]>0){rx = sqrt(3)/3;}
else{rx = -sqrt(3)/3; t = -t;}
if(z[j]>0){rz = sqrt(3)/3;}
else{rz = -sqrt(3)/3; t = -t;}
if(y[j]>0){ry = sqrt(3)/3;}
else{ry = -sqrt(3)/3; t = -t;}
angleMode(RADIANS);
a = 2*(rx*rx*(1-cos(t))+(cos(t)));
b = 2*(ry*rx*(1-cos(t))-(rz*sin(t)));
c = 2*(rz*rx*(1-cos(t))+(ry*sin(t)));
d = 0;
e = 2*(rx*ry*(1-cos(t))+(rz*sin(t)));
f = 2*(ry*ry*(1-cos(t))+(cos(t)));
g = 2*(rz*ry*(1-cos(t))-(rx*sin(t)));
h = 0;
i = 2*(rx*rz*(1-cos(t))-(ry*sin(t)));
jj = 2*(ry*rz*(1-cos(t))+(rx*sin(t)));
kk = 2*(rz*rz*(1-cos(t))+(cos(t)));
ll = 0;
m = 0;
n = 0;
o = 0;
p = 2;
angleMode(DEGREES);
push();
applyMatrix(a, b, c, d, e, f, g, h, i, jj, kk, ll, m, n, o, p)
tri(j,k,l);
pop()
}
}
}
}
}
shapes = endGeometry();
}
function draw() {
tt++;
rotateY(frameCount/2);
rotateX(frameCount/2);
orbitControl();
makeshapes();
scale(1.6);
ambientLight(190);
pointLight(250,250,250,300*sin(tt*6) - width / 2,300*cos(tt*6) - width / 2,300*sin(tt*6+45));
background(0);
fill(200,150,0,84);
noStroke();
model(shapes);
}