mirror of
https://github.com/bspeice/speice.io
synced 2024-12-23 09:08:10 -05:00
34 lines
2.5 KiB
TypeScript
34 lines
2.5 KiB
TypeScript
|
// https://stackoverflow.com/a/34356351
|
||
|
function hexToBytes(hex: string) {
|
||
|
var bytes = [];
|
||
|
for (var i = 0; i < hex.length; i += 2) {
|
||
|
bytes.push(parseInt(hex.substring(i, i + 2), 16));
|
||
|
}
|
||
|
|
||
|
return bytes;
|
||
|
}
|
||
|
|
||
|
export const paletteHex =
|
||
|
"7E3037762C45722B496E2A4E6A29506728536527546326565C265C5724595322574D2155482153462050451F4E441E4D431E4C3F1E473F1E453F1E433F1E3F3F1E3B3E1E393E1E37421D36431C38451C3A471B3B491B3C4A1A3C4B1A3D4D1A3E4F19405318435517445817465A16475D15495E154960154A65134E6812506B12526E1153711055720F55740F55770E577A0E59810C58840B58880A588B09588F08589107569307559A05539D0451A1034FA5024BA90147AA0046AC0045B00242B4043DBB0634BE082EC20A29C30B27C50C26C90F1DCC1116D32110D6280EDA300CDC380ADF4109E04508E24A08E45106E75704EA6402EC6B01EE7300EE7600EF7A00F07E00F18300F29000F29300F39600F39900F39C00F3A000F3A100F3A201F2A502F1A805F0A906EFAA08EEA909EEA80AEDA60CEBA50FE5A313E1A113DD9F13DB9E13D99D14D49C15D09815CC9518C79318BE8B1ABB891BB9871DB4811FB07D1FAB7621A671239C6227975C289256299053298E502A89482C853F2D803A2E7E3037762C45742B47722B496E2A4E6A29516728536326565C265C5724595322575022564E2255482153452050451F4E431E4C3F1E473E1D463D1D453F1E43411E413F1E3B3E1E37421D36421D38431D3B451C3A471B3A491B3C4B1A3D4D1A3E4F19405318435418445518455817465A16475D154960154A65134E66124F6812506B12526E1153711055740F55770E577A0E597E0D57810C58840B58880A588B09588F08589307559A05539C04529E0452A1034FA5024BA90147AC0045B00242B4043DB7053ABB0634BE0831C20A29C50C26C90F1DCC1116D01711D32110D72A0EDA300CDD390ADF4109E24A08E45106E75704E95F03EA6402EC6C01EE7300EF7A00F07E00F18300F28900F29000F39300F39600F39C00F3A000F3A100F3A201F2A502F2A503F1A805F0A807EFAA08EEA80AEDA60CEBA50FE9A411E5A313E1A113DD9F13D99D14D49C15D09815CC9518C79318C38F1ABE8B1AB9871DB4811FB07D1FAB7621A67123A16A249C6227975E289256298E502A89482C853F2D803A2E";
|
||
|
export const paletteBytes = hexToBytes(paletteHex);
|
||
|
console.log(paletteBytes);
|
||
|
|
||
|
// Re-scale colors to 0-1 (see flam3_get_palette)
|
||
|
export const paletteNumber = paletteBytes.map((b) => b / 0xff);
|
||
|
console.log(paletteNumber);
|
||
|
|
||
|
export function colorIndex(c: number): number {
|
||
|
return Math.floor(c * (paletteNumber.length / 3));
|
||
|
}
|
||
|
|
||
|
export function colorFromIndex(c: number): [number, number, number] {
|
||
|
// A smarter coloring implementation would interpolate between points in the palette,
|
||
|
// but we'll use a step function here to keep things simple
|
||
|
const colorIndex = Math.floor(c * (paletteNumber.length / 3)) * 3;
|
||
|
return [
|
||
|
paletteNumber[colorIndex + 0],
|
||
|
paletteNumber[colorIndex + 1],
|
||
|
paletteNumber[colorIndex + 2],
|
||
|
];
|
||
|
}
|