xxxxxxxxxx
61
// Variable to store colors
let colorPalette;
function setup() {
createCanvas(800, 600, WEBGL);
angleMode(DEGREES);
// Define colors for ink washes
colorPalette = [
color(255, 0, 0, 100),
color(0, 255, 0, 100),
color(0, 0, 255, 100),
color(255, 255, 0, 100),
color(255, 0, 255, 100),
color(0, 255, 255, 100),
];
}
function draw() {
background(220);
for (let i = 0; i < 21; i++) {
push();
let sz = random(50, 150);
let posX = random(-300, 300);
let posY = random(-200, 200);
let posZ = random(-500, 0);
translate(posX, posY, posZ);
rotateX(45);
rotateY(atan(1 / sqrt(2)));
drawCube(sz, colorPalette[i % colorPalette.length]);
pop();
}
// Prevent loop to fix the cubes' positions and sizes
noLoop();
}
function drawCube(sz, cubeColor) {
push();
noStroke();
fill(cubeColor);
// Draw the six faces of the cube
for (let i = 0; i < 6; i++) {
push();
if (i % 2 === 0) {
rotateY(90 * i);
} else {
rotateX(90);
rotateY(90 * (i - 1));
}
translate(0, 0, sz / 2);
rect(-sz / 2, -sz / 2, sz, sz);
pop();
}
pop();
}