xxxxxxxxxx
// simple color palette generator
// see console for logged hex codes
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB,360,100,100,1.0);
generate();
}
let palette ;
function generate() {
palette = [];
const dark = {
h: random(0,360),
s: random(95,100),
b: random(0,30)
};
palette.push(dark);
const saturation = random(55,85);
const brightness = random(80,95);
let h = random(dark.h, (dark.h + 360) % 360);
const stepBase = random(180,360) / 3;
for (let i = 0; i < 3; i++) {
palette.push({
h: h,
s: saturation,
b: brightness
});
h = (h + random(stepBase-30,stepBase+30)) % 360;
}
const light = {
h: dark.h,
s: random(0,30),
b: random(95,100)
};
palette.push(light);
debugPrint();
}
function debugPrint() {
console.log(palette.map((pc) => {
const c = color(pc.h, pc.s, pc.b);
return c.toString('#rrggbb') ;
}));
}
function draw() {
background(95);
noStroke();
const swatchWidth = width/5;
for (var i = 0; i < palette.length; i++) {
const c = palette[i];
fill(c.h, c.s, c.b);
rect(i*swatchWidth,0,swatchWidth,height);
}
noLoop();
}
function keyPressed(){
if(key === " ") {
generate();
loop();
}
}