xxxxxxxxxx
"use strict";
let gRotX = 0;
let gRotY = 0;
let freeCamera = true;
const shapes = [];
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
background(100);
createShapes(random(10, 100));
}
function draw() {
background(100)
colorMode(RGB);
ambientLight('white');
directionalLight(color(50, 50, 50), createVector(1, 1, -1));
if (freeCamera) {
gRotX = -mouseY / 50
gRotY = mouseX / 50
}
shapes.forEach(drawShape);
shapes.forEach(updateShape);
}
function createOneShape(minHue, maxHue, clumpSize) {
const angel = false; //random() < 0.01 ? true: false;
return {
hue: random(minHue, maxHue),
brightness: angel ? 50 : random(80, 100),
saturation: angel ? 0 : random(25, 35),
y: randomGaussian(0, clumpSize * 2),
x: randomGaussian(0, clumpSize * 2),
z: randomGaussian(0, clumpSize * 2),
w: random([40, 80, 160]), //width
h: random([40, 80, 160]), //height
d: random([40, 80, 160]), //depth,
rotationX: 0,
rotationY: 0
}
}
function createShapes(numShapes) {
let minHue = random([0, 30, 60, 80]);
let maxHue = minHue + 20;
let clumpSize = 60;
shapes.length = 0; //throw away any old shapes
for (let i = 0; i < numShapes; i++) {
shapes.push(createOneShape(minHue, maxHue, clumpSize));
}
}
function drawShape(shape) {
//cycle light hue between 0-100 as specified in our call to colorMode
push()
colorMode(HSB, 100);
ambientMaterial(color(shape.hue, shape.saturation, shape.brightness, 100));
rotateX(gRotX)
rotateY(gRotY)
translate(shape.x, shape.y, shape.z)
rotateY(shape.rotationY)
rotateX(shape.rotationX)
noStroke();
box(shape.w, shape.h, shape.d)
pop()
}
function updateShape(shape) {
// if (random() < frameCount/5000) {
// shape.rotationX += random([0, TWO_PI / 4]);
// shape.rotationY += random([0, TWO_PI / 4]);
// shape.rotationZ += random([0, TWO_PI / 4]);
// }
}
function toggleFreeCamera() {
freeCamera = !freeCamera;
}
function keyPressed() {
toggleFreeCamera();
}
function mousePressed() {
let numShapes = random(10, 100);
createShapes(numShapes);
}
// function mouseWheel(event) {
// //move the square according to the vertical scroll amount
// //pos += event.delta;
// //uncomment to block page scrolling
// // return false;
// }