64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { Rgb, Rgbs, rgb } from './color.js';
|
|
import { Layer } from './layer.js';
|
|
|
|
export type Color =
|
|
Exclude<Layer, 'eyeshine' | 'stroke' | 'static'>
|
|
| 'collars' | 'bells' | 'tongues' | 'socks' | 'sclera';
|
|
|
|
// in palette order
|
|
export const COLORS: Color[] =
|
|
['lines', 'outer', 'vitiligo1', 'spines', 'fins1', 'fins2', 'fins3',
|
|
'vitiligo4', 'belly1', 'vitiligo3', 'belly2', 'vitiligo2', 'sclera',
|
|
'eyes', 'tongues', 'masks', 'claws', 'socks', 'stripes', 'cuffs',
|
|
'collars', 'bells'];
|
|
|
|
export const NAMES: Partial<Record<Color, 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: Color): string {
|
|
return NAMES[l] ?? l;
|
|
}
|
|
|
|
export type StaticColor = Exclude<Color, Layer>;
|
|
|
|
export const STATIC_COLS: Record<StaticColor, Rgb> = {
|
|
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: Color, palette: Rgbs): Rgb {
|
|
type PPalette = Partial<Record<Color, Rgb>>;
|
|
let p = palette as PPalette;
|
|
let s = STATIC_COLS as PPalette;
|
|
return (p[col] ?? s[col])!;
|
|
}
|
|
|
|
export function make(seed: string, palette: Rgbs): Blob {
|
|
let lines = [
|
|
"GIMP Palette\n",
|
|
`Name: quox ${seed}\n`,
|
|
"Columns: 6\n\n",
|
|
];
|
|
|
|
for (const col of COLORS) {
|
|
let { r, g, b } = get(col, palette);
|
|
lines.push(`${r} ${g} ${b} ${name(col)}\n`);
|
|
}
|
|
|
|
return new Blob(lines, { type: 'application/x-gimp-palette' });
|
|
}
|