xxxxxxxxxx
49
const cnvW = 750;
const cnvH = cnvW;
const rows = 15;
const w = Math.floor(cnvW / rows);
let maxDist;
let angle = 0;
function setup() {
createCanvas(cnvW, cnvH, WEBGL);
maxDist = floor(dist(0,0, width*0.6, width*0.6));
}
function draw() {
background(255);
ortho(-cnvW, cnvH, -cnvW, cnvH, -cnvW, cnvW*2);
let l1 = color("#82bab4");
let l2 = color("#e6e4b0");;
let l3 = color("#3f5484");
directionalLight(l1, 0, 1, 0);
directionalLight(l2, -1, 0, 0);
directionalLight(l3, 1, 0, 0);
ambientMaterial(255);
rotateX(-PI/4);
rotateY(PI/4);
noStroke();
for (let z = w; z < height; z += w) {
for (let x = w; x < width; x += w) {
push();
const d = dist(x, z, width/2, height/2);
const offset = map(d, 0, width/2, -PI, PI);
const a = angle + offset;
const h = floor(map(sin(a), -1, 1, w*3, maxDist));
translate(x - width/2, 0, z - height/2);
box(w, h, w);
pop();
}
}
angle += 0.05;
// noLoop();
}