import { useId } from 'react'; const seed = (s: string) => [...s].reduce((n, c) => (n * 31 + c.charCodeAt(0)) >>> 0, 7); const PALETTE = ['var(--blue)', 'var(--violet)', 'var(--teal)']; /** * A coworker's face: generative colour fields seeded from the name (same name, same face), with a soft swirl. * Decorative (the name is always written beside it). While the coworker is working the colours slowly turn; still * with reduced motion (coworkers.css). */ export function CoworkerAvatar({ name, size = 48, working = false }: { name: string; size?: number; working?: boolean }) { const id = useId().replace(/:/g, ''); const n = seed(name); const hue = n % 360; const pick = (k: number) => PALETTE[(n >> k) % PALETTE.length]; const spot = (k: number) => 14 + ((n >> k) % 28); const fields = [ { c: pick(1), x: spot(2), y: spot(5), r: 30 }, { c: pick(4), x: spot(8), y: spot(11), r: 26 }, { c: `hsl(${(hue + 40) % 360} 90% 62%)`, x: spot(14), y: spot(17), r: 22 }, ]; return ( {fields.map((f, i) => ( ))} {fields.map((f, i) => )} ); }