0x57ca1267…d46csent to0xf28f163e…abec·#21,828,225·view on Etherscan
ipfs://bafybeifncbl7k4w4ftgg4bf5gtcw6okmsp3r5mn4jot7ym2uh4wo5tqiqa
>let gc=10,gr=10,cyc=1000,rot=0.01,nts=0.055,nsf=0.055,cam=500,cells=[],cw,ch;
function setup(){
createCanvas(windowWidth,windowHeight,WEBGL);
angleMode(RADIANS);
cw=width/gc;ch=height/gr;
createCells();
}
function draw(){
background(0);
translate(0,0,-cam);
rotateX(-PI/6);
rotateY(PI/4+frameCount*rot);
let t=frameCount%cyc,tn=t/cyc,ph,i=0;
if(tn<0.25) ph=0;
else if(tn<0.5){ph=1;i=map(tn,0.25,0.5,0,1);}
else if(tn<0.75){ph=2;i=map(tn,0.5,0.75,0,1);}
else {ph=3;i=map(tn,0.75,1,0,1);}
for(let c of cells) drawCell(c,ph,i);
if(t==0 && frameCount>0) createCells();
}
function createCells(){
cells=[];
for(let i=0;i<gc;i++){
for(let j=0;j<gr;j++){
let x0=-width/2+i*cw, x1=-width/2+(i+1)*cw,
y0=-height/2+j*ch, y1=-height/2+(j+1)*ch,
bh=random(cw*0.2,cw*0.8),
bd=bh*random(2,3),
dx=random(1,2), dy=random(1,2), dz=random(0.5,2);
cells.push({x0,y0,x1,y1,bh,bd,dx,dy,dz});
}
}
}
function drawCell(c,ph,tVal){
let {x0,y0,x1,y1,bh,bd,dx,dy,dz}=c;
let v0=createVector(x0,y0,0), v1=createVector(x1,y0,0),
v2=createVector(x1,y1,0), v3=createVector(x0,y1,0),
b0=createVector(x0,y0,bd), b1=createVector(x1,y0,bd),
b2=createVector(x1,y1,bd), b3=createVector(x0,y1,bd),
tf=frameCount*nts;
function oV(bv){
let _dx=map(noise(bv.x*nsf,bv.y*nsf,tf),0,1,-bd*dx,bd*dx),
_dy=map(noise(bv.x*nsf+100,bv.y*nsf+100,tf),0,1,-bd*dy,bd*dy),
_dz=map(noise(bv.x*nsf+200,bv.y*nsf+200,tf),0,1,-bd*dz,bd*dz);
return p5.Vector.add(bv,createVector(_dx,_dy,_dz));
}
let o0=oV(b0), o1=oV(b1), o2=oV(b2), o3=oV(b3), t0,t1,t2,t3;
if(ph===0){t0=v0.copy();t1=v1.copy();t2=v2.copy();t3=v3.copy();}
else if(ph===1){t0=p5.Vector.lerp(v0,b0,tVal);t1=p5.Vector.lerp(v1,b1,tVal);
t2=p5.Vector.lerp(v2,b2,tVal);t3=p5.Vector.lerp(v3,b3,tVal);}
else if(ph===2){t0=p5.Vector.lerp(b0,o0,tVal);t1=p5.Vector.lerp(b1,o1,tVal);
t2=p5.Vector.lerp(b2,o2,tVal);t3=p5.Vector.lerp(b3,o3,tVal);}
else if(ph===3){t0=p5.Vector.lerp(o0,v0,tVal);t1=p5.Vector.lerp(o1,v1,tVal);
t2=p5.Vector.lerp(o2,v2,tVal);t3=p5.Vector.lerp(o3,v3,tVal);}
stroke(255);noFill();
beginShape();vertex(v0.x,v0.y,v0.z);vertex(v1.x,v1.y,v1.z);
vertex(v2.x,v2.y,v2.z);vertex(v3.x,v3.y,v3.z);endShape(CLOSE);
beginShape();vertex(t0.x,t0.y,t0.z);vertex(t1.x,t1.y,t1.z);
vertex(t2.x,t2.y,t2.z);vertex(t3.x,t3.y,t3.z);endShape(CLOSE);
line(v0.x,v0.y,v0.z,t0.x,t0.y,t0.z);
line(v1.x,v1.y,v1.z,t1.x,t1.y,t1.z);
line(v2.x,v2.y,v2.z,t2.x,t2.y,t2.z);
line(v3.x,v3.y,v3.z,t3.x,t3.y,t3.z);
}
function windowResized(){
resizeCanvas(windowWidth,windowHeight);
cw=width/gc;ch=height/gr;
createCells();
}