Skip to content

Commit

Permalink
add color(#hex) for easier colorization
Browse files Browse the repository at this point in the history
  • Loading branch information
delanni committed Sep 10, 2024
1 parent 7839970 commit 21f9240
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion hydrakit.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,24 @@ const beatPattern = (length, hits, map = e => e) => {
}
}
return a.map(map);
}
}


function hexToRgb(hex) {
if (hex[0] === '#') {
hex = hex.slice(1)
}
const r = (parseInt(`${hex[0]}${hex[1]}`, 16) / 255).toPrecision(4)
const g = (parseInt(`${hex[2]}${hex[3]}`, 16) / 255).toPrecision(4)
const b = (parseInt(`${hex[4]}${hex[5]}`, 16) / 255).toPrecision(4)
return { r, g, b }
}
/** solid, but with #rrggbb color */
function color(...args) {
if (args.length === 1) {
const { r, g, b } = hexToRgb(args[0]);
return eval(`solid(${r},${g},${b})`);
} else {
return eval(`solid(${args[0]},${args[1]},${args[2]})`);
}
}

0 comments on commit 21f9240

Please sign in to comment.