xxxxxxxxxx
// Lomz 2023
// kolorfon v2.0
// https://www.lomz.net
let cubes = [];
let cube;
let rotationValues = [0, 90, 180, 270,];
let palette = ["#406BB3", "#D2B75E", "#343434", "#9A6E3B", "#E0D4C6", "#466B3F", "#D69E91", "#C8C8CA"];
function preload() {
cube = loadModel('cube.obj');
}
function setup() {
size = min(windowWidth, windowHeight);
createCanvas(size, size, WEBGL);
background("#E0DFDC");
for (let x = -5; x <= 5; x++) {
for (let y = -5; y <= 5; y++) {
let randomScale = random(1, 3);
cubes.push(new Cube(x*10, y*10, randomScale));
}
}
camera(0, 0, 140, 0, 0, 0, 0, 1, 0);
noStroke();
// pointLight(250, 250, 250, 0, 0, -20);
// pointLight(250, 250, 250, 0, 0, 20);
// pointLight(250, 250, 250, 0, 0, 120);
for (let i = 0; i < cubes.length; i++) {
if (random(1) < 0.35) {
cubes[i].show();
}
}
}
function draw() {
}
class Cube {
constructor(x, y, scale) {
this.x = x;
this.y = y;
this.scale = scale;
this.rotation = random(rotationValues);
this.color = random(palette);
}
show() {
if (random(1) < 0.4) {
push();
translate(this.x + 2, this.y + 2, 0);
fill(this.color);
rotateZ(radians(this.rotation));
rotateX(radians(this.rotation));
rotateY(radians(this.rotation));
scale(random(6,12) * this.scale);
model(cube);
pop();
}
else {
push();
translate(this.x + 2, this.y + 2, 0);
stroke(this.color);
noFill();
rotateZ(radians(this.rotation));
rotateX(radians(this.rotation));
rotateY(radians(this.rotation));
//scale(8 * this.scale);
box(10 * this.scale);
pop();
}
}
}
// **************************
// * Save png *
// **************************
function keyTyped() {
if (key == "s" || key == "S") save("Title" + int(random(0, 1000)) + ".png");
}