diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cdc81e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +palette.in +palette.out +gifpalette.out +build/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cc9beeb --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ + +SRCDIR:= img +DSTDIR:= build +SOURCES := $(shell find ${SRCDIR} -type f -print) +FILES := $(patsubst $(SRCDIR)/%,$(DSTDIR)/%,$(SOURCES)) + +all: $(FILES) + +palette.out: palette.in + node palette-gen.js + +builddir: + @mkdir -p build + @mkdir -p build/gif + +build/%: img/% builddir palette.out + repalette $< $@ -p $$(cat palette.out) --dither $(DITHER) + +build/%.gif: img/%.gif builddir palette.out + gifsicle --use-colormap gifpalette.out < $< > $@ + +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/img/gif/pond.gif b/img/gif/pond.gif new file mode 100644 index 0000000..8ca77d0 Binary files /dev/null and b/img/gif/pond.gif differ diff --git a/palette-gen.js b/palette-gen.js index 6524d41..35a3811 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 ? { @@ -9,27 +9,33 @@ const hexToRgb = (hex) => { } : null; }; -const parseScheme = (str) => str.split(",").map(e=>hexToRgb(e)) +const parseScheme = (str) => str.replace(/\s+/g, '').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)); +const tints = (c, w) => Array.from({ length: w }, (_, i) => tint(c, (i + 1)/w)); +const shades = (c, w) => Array.from({ length: w }, (_, i) => shade(c, (i )/w)); -const genPalette = (c, w=10) => [...tints(c, w).reverse(), Object.assign(c), ...shades(c, w).reverse()]; +const genPalette = (c, w=3) => [...tints(c, w).reverse(), Object.assign(c), ...shades(c, w).reverse()]; -const readline = require('readline'); -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false -}); - -rl.on('line', (line) => { - console.log(parseScheme(line).map(e=>genPalette(e).map(c=>rgbToHex(c)))); +const fs = require("fs"); + +fs.readFile("palette.in", "utf-8", (_, buf) => { + const colors = parseScheme(buf) + .map(e=> genPalette(e, process.env.PALETTE_SIZE).filter(v=>(v.r+v.g+v.b>0)&&(v.r+v.g+v.b<765))) + + const hexstr = colors.map(cs=>cs.map(c=>rgbToHex(c)).join(',')).join(',') + const gifstr = colors.map(cs=>cs.map(c=>`${c.r} ${c.g} ${c.b}`).join('\n')).join('\n') + + fs.writeFile("palette.out", hexstr, (err) => { + if (err) console.log(err); + }); + fs.writeFile("gifpalette.out", gifstr, (err) => { + if (err) console.log(err); + }); });