From 21f924011cb4587442e24a5a79697dfc096e36a5 Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Tue, 10 Sep 2024 11:51:16 +0200 Subject: [PATCH] add color(#hex) for easier colorization --- hydrakit.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/hydrakit.js b/hydrakit.js index 7969410..eb0179d 100644 --- a/hydrakit.js +++ b/hydrakit.js @@ -217,4 +217,24 @@ const beatPattern = (length, hits, map = e => e) => { } } return a.map(map); -} \ No newline at end of file +} + + +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]})`); + } +}