65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { Color, Colors, rgb } from './color.js';
|
|
import { Layer } from './layer.js';
|
|
|
|
export type Swatch =
|
|
Exclude<Layer, 'eyeshine' | 'stroke' | 'static'>
|
|
| 'collars' | 'bells' | 'tongues' | 'socks' | 'sclera';
|
|
|
|
// in palette order
|
|
export const SWATCHES: Swatch[] =
|
|
['lines', 'outer', 'vitiligo1', 'spines',
|
|
'socks', 'stripes', 'cuffs',
|
|
'vitiligo4', 'belly1', 'vitiligo3', 'belly2', 'vitiligo2',
|
|
'fins1', 'fins2', 'fins3', 'masks', 'claws',
|
|
'sclera', 'eyes', 'tongues', 'collars', 'bells'];
|
|
|
|
export const NAMES: Partial<Record<Swatch, string>> = {
|
|
outer: 'outer body',
|
|
stripes: 'sock stripes',
|
|
cuffs: 'sock cuffs',
|
|
fins1: 'fins (outer)',
|
|
fins2: 'fins (mid)',
|
|
fins3: 'fins (inner)',
|
|
belly1: 'belly 1',
|
|
belly2: 'belly 2',
|
|
vitiligo1: 'outer body vitiligo',
|
|
vitiligo2: 'belly 2 vitiligo',
|
|
vitiligo3: 'belly 1 vitiligo',
|
|
vitiligo4: 'fins vitiligo',
|
|
};
|
|
|
|
export function name(l: Swatch): string {
|
|
return NAMES[l] ?? l;
|
|
}
|
|
|
|
export type StaticColor = Exclude<Swatch, Layer>;
|
|
|
|
export const STATIC_COLS: Record<StaticColor, Color> = {
|
|
collars: rgb(206, 75, 101),
|
|
bells: rgb(235, 178, 79),
|
|
tongues: rgb(222, 165, 184),
|
|
socks: rgb(238, 239, 228),
|
|
sclera: rgb(238, 239, 228),
|
|
};
|
|
|
|
export function get(col: Swatch, palette: Colors): Color {
|
|
type PPalette = Partial<Record<Swatch, Color>>;
|
|
const p = palette as PPalette;
|
|
const s = STATIC_COLS as PPalette;
|
|
return (p[col] ?? s[col])!;
|
|
}
|
|
|
|
export function make(seed: string, palette: Colors): Blob {
|
|
const lines = [
|
|
"GIMP Palette\n",
|
|
`Name: quox ${seed}\n`,
|
|
"Columns: 6\n\n",
|
|
];
|
|
|
|
for (const sw of SWATCHES) {
|
|
const col = get(sw, palette);
|
|
lines.push(`${col.red} ${col.green} ${col.blue} ${name(sw)}\n`);
|
|
}
|
|
|
|
return new Blob(lines, { type: 'application/x-gimp-palette' });
|
|
}
|