xxxxxxxxxx
let n, tam, maxtam;
n = 10;
let rx = 0,
ry = 0,
rz = 0;
let rodar = false;
let poly = 0;
let clique = false;
let ico;
function preload() {
ico = loadModel('polyhedronisme-C300u2I.obj');
}
function setup() {
tam = [window.innerWidth, window.innerHeight];
maxtam = max(tam);
createCanvas(tam[0], tam[1], WEBGL);
angleMode(DEGREES);
}
function draw() {
let aux = clique * 255;
background(aux);
switch (poly) {
case 0:
fill(aux)
stroke(!clique * 255);
strokeWeight(1);
break;
case 1:
noStroke();
specularMaterial(!clique * 255);
ambientLight(127);
pointLight(50, 50, 50, 0, 0, maxtam / n);
break;
case 2:
fill(aux)
stroke(!clique * 255);
strokeWeight(0.3);
break;
}
orbitControl();
if (!rodar) {
if (rotationX * rotationY * rotationZ != 0 && rotationX * rotationY * rotationZ != null) {
rodar = true;
}
}
if (rodar) {
rz = rotationZ;
rx = rotationX;
ry = rotationY;
} else {
ry = map(mouseX, 0, tam[0], 0, -360);
rx = map(mouseY, 0, tam[1], 0, -180);
}
translate(0, 0, 2*sin(3*frameCount) / n*maxtam);
rotateZ(rz);
rotateX(rx);
rotateY(ry);
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
for (let k = 0; k < n; k++) {
push();
let px = map(i, 0, n - 1, -0.5 * maxtam, 0.5 * maxtam);
let py = map(j, 0, n - 1, -0.5 * maxtam, 0.5 * maxtam);
let pz = map(k, 0, n - 1, -0.5 * maxtam, 0.5 * maxtam);
translate(px, py, pz);
switch (poly) {
case 0:
box(maxtam / (n - 1) / 10);
break;
case 1:
sphere(maxtam / (n - 1) / 20, 16, 8);
//sphere(maxtam / (n - 1) / 20, 4, 2);
break;
case 2:
scale(5);
model(ico);
break;
}
pop();
}
}
}
}
function mouseClicked() {
clique = !clique;
if (!clique) {
poly++;
if (poly > 2) {
poly = 0;
}
}
}