xxxxxxxxxx
/*
Gems #WCCChallenge "Pressure" 250305
https://openprocessing.org/sketch/2566872
#generativeart #creativecoding #p5js
Dear Raph and creative coding community,
gemstones are made by insane heat, pressure and carbon ^^
Join the Birb's Nest Discord for friendly creative coding community
and future challenges and contributions: https://discord.gg/S8c7qcjw2b
WCCC-Contributions: https://openprocessing.org/curation/78544
*/
let gems;
function setup() {
let T = 1, S = Infinity;
const MAX_SZE = random(123, 400);
while (S > MAX_SZE) {
S = min(windowWidth,windowHeight) / T;
T++;
}
S = ~~(S * 0.9);
let TX = ~~(windowWidth/S), TY = ~~(windowHeight/S);
let PX = ~~((windowWidth-TX*S)/(TX+1)), PY = ~~((windowHeight-TY*S)/(TY+1));
// console.log(`S ${S}, T ${T}, TX ${TX}, TY ${TY}, PX ${PX}, PY ${PY}`)
createCanvas(windowWidth, windowHeight);
describe("grid of gems of different shape and color")
frameRate(25);
d = ~~(min(width, height) / 1.2)
gems = [];
for (let y = 0; y < TY; y++) {
for (let x = 0; x < TX; x++) {
const xx = (x+1) * PX + (x+0.5) * S;
const yy = (y+1) * PY + (y+0.5) * S;
gems.push(new Gem(xx, yy, S));
}
}
background("rgb(4, 2, 12)");
}
function draw() {
// init bg or shape colors
if (frameCount % 100 === 0) {
setup();
return;
}
// pause progress last half
if (frameCount % 100 > 50) return;
// draw shapes / progress
for (let gem of gems) gem.draw();
}
function mousePressed() {
if (mouseButton === LEFT) setup();
}