Something went wrong. Try again.
(WIP) Modern Minecraft server-side HUD framework.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687// Color Utilities for Gradient Interpolation
export interface RGB { r: number; g: number; b: number;}
/** * Convert hex color to RGB */export function hexToRgb(hex: string): RGB { const clean = hex.replace('#', ''); const r = parseInt(clean.substring(0, 2), 16); const g = parseInt(clean.substring(2, 4), 16); const b = parseInt(clean.substring(4, 6), 16);
return { r, g, b };}
/** * Convert RGB to hex color */export function rgbToHex(rgb: RGB): string { const r = Math.round(rgb.r).toString(16).padStart(2, '0'); const g = Math.round(rgb.g).toString(16).padStart(2, '0'); const b = Math.round(rgb.b).toString(16).padStart(2, '0');
return `#${r}${g}${b}`;}
/** * Linear interpolation between two values */function lerp(a: number, b: number, t: number): number { return a + (b - a) * t;}
/** * Interpolate between two RGB colors */function lerpColor(color1: RGB, color2: RGB, t: number): RGB { return { r: lerp(color1.r, color2.r, t), g: lerp(color1.g, color2.g, t), b: lerp(color1.b, color2.b, t) };}
/** * Interpolate colors across a gradient * @param colors Array of hex colors * @param position Position in gradient (0 to 1) * @param phase Optional phase offset (-1 to 1) */export function interpolateGradient(colors: string[], position: number, phase: number = 0): string { if (colors.length === 0) return '#FFFFFF'; if (colors.length === 1) return colors[0];
let pos = position + phase; pos = pos - Math.floor(pos);
const scaledPos = pos * (colors.length - 1); const index1 = Math.floor(scaledPos); const index2 = Math.min(index1 + 1, colors.length - 1); const t = scaledPos - index1;
const rgb1 = hexToRgb(colors[index1]); const rgb2 = hexToRgb(colors[index2]); const result = lerpColor(rgb1, rgb2, t);
return rgbToHex(result);}
/** * Apply gradient to text (character-by-character) */export function applyGradient(text: string, colors: string[], phase: number = 0): string[] { const chars = Array.from(text); // Handle Unicode correctly if (chars.length === 0) return [];
return chars.map((char, i) => { const position = chars.length === 1 ? 0 : i / (chars.length - 1); return interpolateGradient(colors, position, phase); });}