patchwise-agent-studio / web /src /components /CoworkerAvatar.tsx
EnergyVenom's picture
Patchwise Agent Studio: Oracle AI Agent Studio cycles
af1bee9 verified
Raw History Blame Contribute Delete
2.26 kB
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 (
<svg className="cw-avatar" data-working={working || undefined} width={size} height={size} viewBox="0 0 56 56" aria-hidden focusable="false">
<defs>
<clipPath id={`${id}c`}><rect width="56" height="56" rx="12" /></clipPath>
<filter id={`${id}b`} x="-30%" y="-30%" width="160%" height="160%"><feGaussianBlur stdDeviation="5" /></filter>
{fields.map((f, i) => (
<radialGradient key={i} id={`${id}g${i}`}>
<stop offset="0%" style={{ stopColor: f.c, stopOpacity: 1 }} />
<stop offset="100%" style={{ stopColor: f.c, stopOpacity: 0 }} />
</radialGradient>
))}
</defs>
<g clipPath={`url(#${id}c)`}>
<rect width="56" height="56" style={{ fill: `hsl(${hue} 45% 16%)` }} />
<g className="cw-avatar-field" filter={`url(#${id}b)`}>
{fields.map((f, i) => <circle key={i} cx={f.x} cy={f.y} r={f.r} fill={`url(#${id}g${i})`} />)}
</g>
<path className="cw-avatar-swirl" d={`M10 ${36 + (n % 8)} C 20 ${14 + (n % 10)}, 36 ${44 - (n % 9)}, 48 ${16 + (n % 7)}`}
fill="none" stroke="white" strokeOpacity="0.45" strokeWidth="2.2" strokeLinecap="round" />
</g>
</svg>
);
}