xxxxxxxxxx
let COUNT = 20;
let SIZE = 20;
let NOISE_VAL = 0.004;
let b = [];
let fc;
function setup() {
createCanvas(1112, 834, WEBGL);
colorMode(HSB, 360);
angleMode(DEGREES);
rectMode(CENTER);
loadBoxes();
//noStroke();
}
function draw() {
fc = frameCount;
background(100);
camera(sin(fc) * 600, cos(fc)*100, 600, 0, 0, 0, 0, 1, 0);
ambientLight(360, 0, 360);
pointLight(360, 90, 180, sin(fc)*width/5, cos(fc)*width/5, 0);
rotateX(frameCount/50);
rotateZ(60);
for (let box of b) {
push();
box.display();
box.move();
pop();
}
}
function loadBoxes() {
for (let i = 0; i < COUNT; i++) {
for (let j = 0; j < COUNT; j++) {
b.push(new Box(i, j, COUNT / 2));
}
}
}
class Box {
constructor(x, y, z) {
this.x = -SIZE * (COUNT / 2) + x * SIZE;
this.y = -SIZE * (COUNT / 2) + y * SIZE;
this.z = -SIZE * (COUNT / 2) + z * SIZE;
this.off = 1;
}
display() {
let d = dist(this.x, this.y, 0, 0)*2;
let dx = map(d, 0, width / 2, SIZE / 2, SIZE * 4);
let nx = 10;
translate(this.x * this.off, this.y * this.off, this.z);
specularMaterial((dx * 5 + fc) % 360, 360, 360);
box(SIZE, SIZE, cos((fc + dx) * 5) * 100 + 100);
}
move() {
this.off += sin(fc*2)/100;
}
}
pad = (a, b) =>
(1e15 + a + "").slice(-b)
//save JPG
let lapse = 0; // mouse timer
function mousePressed(){
// prevents mouse press from registering twice
if (millis() - lapse > 400){
save("img_" + month() + '-' + day() + '_' + hour() + '-' + minute() + '-' + second() + ".jpg");
lapse = millis();
}
}