From fce65bdd30f67f6a57bedb464601824d6df25197 Mon Sep 17 00:00:00 2001 From: sora Date: Sat, 17 Jun 2023 02:42:25 +0200 Subject: [PATCH] Update 'palette-gen.js' --- .gitignore | 2 ++ Makefile | 25 ++++++++++++++++++ .../16dcbfda36e31291-3410818.png | Bin .../20b1948153937310-3410788.png | Bin .../29f1e13d2ed05450-3410849.png | Bin .../40337e5c769f227d-3410837.png | Bin .../4a48911129733692-3410774.png | Bin .../507cf836ca5eadba-3410867.png | Bin .../7c0a2112ac5ee728-3410801.png | Bin .../8cd98da44e5fcb5d-3412088.png | Bin .../a3e376acbf396f46-3410794.png | Bin .../ac821bdf9293d497-3410814.png | Bin .../c57194ffcb0e0833-3412091.png | Bin dark.jpg => img/dark.jpg | Bin .../ddcc4bd17f2f0900-3410778.png | Bin .../de4deb8277528cc0-3410822.png | Bin .../e36d6f83d02a1d91-3410847.png | Bin .../e80335d0115db967-3410783.png | Bin .../e818a34f775d182b-3410770.png | Bin .../eaf2bdd4d3e0b4fc-3410797.png | Bin .../effc6d0d04b1d517-3410762.png | Bin .../f6fb83f6911802db-3410824.png | Bin .../f78af4cfcbf71896-3410777.png | Bin palette-gen.js | 15 ++++++++--- 24 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile rename 16dcbfda36e31291-3410818.png => img/16dcbfda36e31291-3410818.png (100%) rename 20b1948153937310-3410788.png => img/20b1948153937310-3410788.png (100%) rename 29f1e13d2ed05450-3410849.png => img/29f1e13d2ed05450-3410849.png (100%) rename 40337e5c769f227d-3410837.png => img/40337e5c769f227d-3410837.png (100%) rename 4a48911129733692-3410774.png => img/4a48911129733692-3410774.png (100%) rename 507cf836ca5eadba-3410867.png => img/507cf836ca5eadba-3410867.png (100%) rename 7c0a2112ac5ee728-3410801.png => img/7c0a2112ac5ee728-3410801.png (100%) rename 8cd98da44e5fcb5d-3412088.png => img/8cd98da44e5fcb5d-3412088.png (100%) rename a3e376acbf396f46-3410794.png => img/a3e376acbf396f46-3410794.png (100%) rename ac821bdf9293d497-3410814.png => img/ac821bdf9293d497-3410814.png (100%) rename c57194ffcb0e0833-3412091.png => img/c57194ffcb0e0833-3412091.png (100%) rename dark.jpg => img/dark.jpg (100%) rename ddcc4bd17f2f0900-3410778.png => img/ddcc4bd17f2f0900-3410778.png (100%) rename de4deb8277528cc0-3410822.png => img/de4deb8277528cc0-3410822.png (100%) rename e36d6f83d02a1d91-3410847.png => img/e36d6f83d02a1d91-3410847.png (100%) rename e80335d0115db967-3410783.png => img/e80335d0115db967-3410783.png (100%) rename e818a34f775d182b-3410770.png => img/e818a34f775d182b-3410770.png (100%) rename eaf2bdd4d3e0b4fc-3410797.png => img/eaf2bdd4d3e0b4fc-3410797.png (100%) rename effc6d0d04b1d517-3410762.png => img/effc6d0d04b1d517-3410762.png (100%) rename f6fb83f6911802db-3410824.png => img/f6fb83f6911802db-3410824.png (100%) rename f78af4cfcbf71896-3410777.png => img/f78af4cfcbf71896-3410777.png (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ce5a6ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +palette.in +palette.out \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1f129c6 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ + +SRCDIR:= img +DSTDIR:= build +SOURCES := $(wildcard $(SRCDIR)/*) +FILES := $(patsubst $(SRCDIR)/%,$(DSTDIR)/%,$(SOURCES)) + +palette.out: palette.in + node palette-gen.js < palette.in > palette.out + +builddir: + @mkdir -p build + +build/%.jpg: builddir palette.out img/%.jpg + repalette $@ build/$@ -p $(cat palette.out) --dither $(DITHER) + +build/%.png: builddir palette.out img/%.png + repalette $@ build/$@ -p $(cat palette.out) --dither $(DITHER) + + +all: $(FILES) + @echo $(SOURCES) + @echo $(FILES) + +clean: + @rm -rf palette.in palette.out build \ No newline at end of file diff --git a/16dcbfda36e31291-3410818.png b/img/16dcbfda36e31291-3410818.png similarity index 100% rename from 16dcbfda36e31291-3410818.png rename to img/16dcbfda36e31291-3410818.png diff --git a/20b1948153937310-3410788.png b/img/20b1948153937310-3410788.png similarity index 100% rename from 20b1948153937310-3410788.png rename to img/20b1948153937310-3410788.png diff --git a/29f1e13d2ed05450-3410849.png b/img/29f1e13d2ed05450-3410849.png similarity index 100% rename from 29f1e13d2ed05450-3410849.png rename to img/29f1e13d2ed05450-3410849.png diff --git a/40337e5c769f227d-3410837.png b/img/40337e5c769f227d-3410837.png similarity index 100% rename from 40337e5c769f227d-3410837.png rename to img/40337e5c769f227d-3410837.png diff --git a/4a48911129733692-3410774.png b/img/4a48911129733692-3410774.png similarity index 100% rename from 4a48911129733692-3410774.png rename to img/4a48911129733692-3410774.png diff --git a/507cf836ca5eadba-3410867.png b/img/507cf836ca5eadba-3410867.png similarity index 100% rename from 507cf836ca5eadba-3410867.png rename to img/507cf836ca5eadba-3410867.png diff --git a/7c0a2112ac5ee728-3410801.png b/img/7c0a2112ac5ee728-3410801.png similarity index 100% rename from 7c0a2112ac5ee728-3410801.png rename to img/7c0a2112ac5ee728-3410801.png diff --git a/8cd98da44e5fcb5d-3412088.png b/img/8cd98da44e5fcb5d-3412088.png similarity index 100% rename from 8cd98da44e5fcb5d-3412088.png rename to img/8cd98da44e5fcb5d-3412088.png diff --git a/a3e376acbf396f46-3410794.png b/img/a3e376acbf396f46-3410794.png similarity index 100% rename from a3e376acbf396f46-3410794.png rename to img/a3e376acbf396f46-3410794.png diff --git a/ac821bdf9293d497-3410814.png b/img/ac821bdf9293d497-3410814.png similarity index 100% rename from ac821bdf9293d497-3410814.png rename to img/ac821bdf9293d497-3410814.png diff --git a/c57194ffcb0e0833-3412091.png b/img/c57194ffcb0e0833-3412091.png similarity index 100% rename from c57194ffcb0e0833-3412091.png rename to img/c57194ffcb0e0833-3412091.png diff --git a/dark.jpg b/img/dark.jpg similarity index 100% rename from dark.jpg rename to img/dark.jpg diff --git a/ddcc4bd17f2f0900-3410778.png b/img/ddcc4bd17f2f0900-3410778.png similarity index 100% rename from ddcc4bd17f2f0900-3410778.png rename to img/ddcc4bd17f2f0900-3410778.png diff --git a/de4deb8277528cc0-3410822.png b/img/de4deb8277528cc0-3410822.png similarity index 100% rename from de4deb8277528cc0-3410822.png rename to img/de4deb8277528cc0-3410822.png diff --git a/e36d6f83d02a1d91-3410847.png b/img/e36d6f83d02a1d91-3410847.png similarity index 100% rename from e36d6f83d02a1d91-3410847.png rename to img/e36d6f83d02a1d91-3410847.png diff --git a/e80335d0115db967-3410783.png b/img/e80335d0115db967-3410783.png similarity index 100% rename from e80335d0115db967-3410783.png rename to img/e80335d0115db967-3410783.png diff --git a/e818a34f775d182b-3410770.png b/img/e818a34f775d182b-3410770.png similarity index 100% rename from e818a34f775d182b-3410770.png rename to img/e818a34f775d182b-3410770.png diff --git a/eaf2bdd4d3e0b4fc-3410797.png b/img/eaf2bdd4d3e0b4fc-3410797.png similarity index 100% rename from eaf2bdd4d3e0b4fc-3410797.png rename to img/eaf2bdd4d3e0b4fc-3410797.png diff --git a/effc6d0d04b1d517-3410762.png b/img/effc6d0d04b1d517-3410762.png similarity index 100% rename from effc6d0d04b1d517-3410762.png rename to img/effc6d0d04b1d517-3410762.png diff --git a/f6fb83f6911802db-3410824.png b/img/f6fb83f6911802db-3410824.png similarity index 100% rename from f6fb83f6911802db-3410824.png rename to img/f6fb83f6911802db-3410824.png diff --git a/f78af4cfcbf71896-3410777.png b/img/f78af4cfcbf71896-3410777.png similarity index 100% rename from f78af4cfcbf71896-3410777.png rename to img/f78af4cfcbf71896-3410777.png diff --git a/palette-gen.js b/palette-gen.js index 6524d41..065049c 100644 --- a/palette-gen.js +++ b/palette-gen.js @@ -1,7 +1,7 @@ #!/bin/nodejs 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 result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { @@ -14,8 +14,8 @@ const parseScheme = (str) => str.split(",").map(e=>hexToRgb(e)) const getTint = (c, w) => Math.round(c + (255 - c) * 1 * w); const getShade = (c, w) => Math.round(c * w); -const tint = (c, w) => ({r:getTint(c.r,w), g:getTint(c.g,w), b:getTint(c.b,w)}); -const shade = (c, w) => ({r:getShade(c.r,w), g:getShade(c.g,w), b:getShade(c.b,w)}); +const tint = (c, w) => ({r:getTint(c.r, w), g:getTint(c.g, w), b:getTint(c.b, w)}); +const shade = (c, w) => ({r:getShade(c.r, w), g:getShade(c.g, w), b:getShade(c.b, w)}); const tints = (c, w) => Array.from({ length: 100 / w }, (_, i) => tint(c, (i + 1) * w/100)); const shades = (c, w) => Array.from({ length: 100 / w }, (_, i) => shade(c, (i + 1) * w/100)); @@ -31,5 +31,12 @@ const rl = readline.createInterface({ }); 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(",") + ); });