Update 'palette-gen.js'

This commit is contained in:
sora 2023-06-17 02:42:25 +02:00
parent 1563bb0815
commit 8825bd0f75

View File

@ -1,7 +1,7 @@
#!/bin/nodejs #!/bin/nodejs
const componentToHex = (c) => ("0" + c.toString(16)).slice(-2); const componentToHex = (c) => ("0" + c.toString(16)).slice(-2);
const rgbToHex = (c) => "#" + componentToHex(c.r) + componentToHex(c.g) + componentToHex(c.b); const rgbToHex = (c) => componentToHex(c.r) + componentToHex(c.g) + componentToHex(c.b);
const hexToRgb = (hex) => { const hexToRgb = (hex) => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? { return result ? {
@ -31,5 +31,5 @@ const rl = readline.createInterface({
}); });
rl.on('line', (line) => { rl.on('line', (line) => {
console.log(parseScheme(line).map(e=>genPalette(e).map(c=>rgbToHex(c)))); console.log(parseScheme(line).map(e=>genPalette(e).map(c=>rgbToHex(c))).join(","));
}); });