xxxxxxxxxx
43
let spacing = 25;
let r = spacing/2;
let num = 10;
function setup() {
createCanvas(500, 500, WEBGL);
angleMode(DEGREES);
}
function draw() {
background(220);
orbitControl();
let d = map(mouseX, 0, width, 3, 10);
stroke(0);
for (let i=0; i<num; i++) {
for (let j=0; j<num; j++) {
for (let k=0; k<num; k++) {
push();
let offset = -spacing * num/2 + spacing/2;
let x = i*spacing + offset;
let y = j*spacing + offset;
let z = k*spacing + offset;
let distance = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
translate(x, y, z);
normalMaterial();
let shapeSize = spacing - distance/d;
if (mouseIsPressed) {
box(shapeSize);
} else {
sphere(shapeSize);
}
pop();
}
}
}
}