mirror of
https://github.com/mempool/mempool.git
synced 2025-03-13 03:24:28 +01:00
29 lines
763 B
TypeScript
29 lines
763 B
TypeScript
|
import { Color } from './sprite-types';
|
||
|
|
||
|
export function hexToColor(hex: string): Color {
|
||
|
return {
|
||
|
r: parseInt(hex.slice(0, 2), 16) / 255,
|
||
|
g: parseInt(hex.slice(2, 4), 16) / 255,
|
||
|
b: parseInt(hex.slice(4, 6), 16) / 255,
|
||
|
a: hex.length > 6 ? parseInt(hex.slice(6, 8), 16) / 255 : 1
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function desaturate(color: Color, amount: number): Color {
|
||
|
const gray = (color.r + color.g + color.b) / 6;
|
||
|
return {
|
||
|
r: color.r + ((gray - color.r) * amount),
|
||
|
g: color.g + ((gray - color.g) * amount),
|
||
|
b: color.b + ((gray - color.b) * amount),
|
||
|
a: color.a,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function darken(color: Color, amount: number): Color {
|
||
|
return {
|
||
|
r: color.r * amount,
|
||
|
g: color.g * amount,
|
||
|
b: color.b * amount,
|
||
|
a: color.a,
|
||
|
}
|
||
|
}
|