repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
pi/agent/extensions/animations/utils.ts
RawFile outline
export const rgb = (r: number, g: number, b: number) =>
`\x1b[38;2;${r};${g};${b}m`;
export const bold = "\x1b[1m";
export const dim = "\x1b[2m";
export const reset = "\x1b[0m";
export const nobold = "\x1b[22m";
// Pi gradient (nicobailon style): magenta → purple → cyan
export const PI_GRAD = [
[255, 0, 135],
[175, 95, 175],
[135, 95, 215],
[95, 95, 255],
[95, 175, 255],
[0, 255, 255],
];
export function hsl(h: number, s = 1, l = 0.5): string {
const c = (1 - Math.abs(2 * l - 1)) * s;
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
const m = l - c / 2;
let r = 0,
g = 0,
b = 0;
if (h < 60) {
r = c;
g = x;
} else if (h < 120) {
r = x;
g = c;
} else if (h < 180) {
g = c;
b = x;
} else if (h < 240) {
g = x;
b = c;
} else if (h < 300) {
r = x;
b = c;
} else {
r = c;
b = x;
}
return rgb(
Math.round((r + m) * 255),
Math.round((g + m) * 255),
Math.round((b + m) * 255),
);
}
export function lerpGrad(
grad: number[][],
t: number,
): [number, number, number] {
const i = Math.floor(t * (grad.length - 1));
const i2 = Math.min(i + 1, grad.length - 1);
const lt = (t * (grad.length - 1)) % 1;
return [
Math.round(grad[i][0] + (grad[i2][0] - grad[i][0]) * lt),
Math.round(grad[i][1] + (grad[i2][1] - grad[i][1]) * lt),
Math.round(grad[i][2] + (grad[i2][2] - grad[i][2]) * lt),
];
}
export const ellipsis = (f: number) =>
[".", "..", "...", ""][Math.floor(f / 10) % 4];