Update 'palette-gen.js'
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
palette.in
|
||||
palette.out
|
25
Makefile
Normal file
@ -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
|
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.7 MiB After Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.1 MiB |
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.1 MiB |
Before Width: | Height: | Size: 2.6 MiB After Width: | Height: | Size: 2.6 MiB |
Before Width: | Height: | Size: 2.5 MiB After Width: | Height: | Size: 2.5 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 959 KiB After Width: | Height: | Size: 959 KiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.7 MiB After Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.6 MiB After Width: | Height: | Size: 2.6 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.8 MiB After Width: | Height: | Size: 2.8 MiB |
Before Width: | Height: | Size: 2.7 MiB After Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 2.9 MiB After Width: | Height: | Size: 2.9 MiB |
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.1 MiB |
@ -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(",")
|
||||
);
|
||||
});
|
||||
|