Monster Avatar
A friendly monster for each agent. Pick a body, color, pattern, ears, eyes, mouth, hat, and the thing it holds, or let the agent id choose. Each one breathes, blinks, and moves the thing it holds.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/monster-avatar.jsonCopies Monster Avatar into your app, installs the packages, and adds the styles. Then import it from @/components/ui/monster-avatar. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-mergeAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Copy and paste the following code into your project.
'use client'; import { useEffect, useRef, type CSSProperties, type HTMLAttributes } from 'react'; import { hash } from '@/lib/sprout/hash'; import { bodies, bodyGeometry, bodyTexture, colors, defaultHand, earParts, ears, eyeParts, eyes, hatParts, hats, ink, itemParts, items, mouthParts, mouths, palettes, patterns, type MonsterBody, type MonsterColor, type MonsterEars, type MonsterEyes, type MonsterHat, type MonsterItem, type MonsterMouth, type MonsterPattern, } from '@/lib/sprout/monster-avatar-parts'; import { presets } from '@/lib/sprout/monster-avatar-presets'; import { cn } from '@/lib/sprout/classes'; export type { MonsterBody, MonsterColor, MonsterEars, MonsterEyes, MonsterHat, MonsterItem, MonsterMouth, MonsterPattern, }; export interface MonsterAvatarConfig { body: MonsterBody; color: MonsterColor; pattern: MonsterPattern; ears: MonsterEars; eyes: MonsterEyes; mouth: MonsterMouth; hat: MonsterHat; item: MonsterItem; } export const monsterAvatarParts = { body: bodies, color: colors, pattern: patterns, ears, eyes, mouth: mouths, hat: hats, item: items, } as const; export const monsterAvatarPresets: readonly { name: string; config: MonsterAvatarConfig }[] = presets; const pick = <T,>(list: readonly T[], value: number) => list[value % list.length]!; export function monsterAvatar(agentId: string): MonsterAvatarConfig { const h = hash(agentId); const h2 = hash(`${agentId}:monster`); return { body: pick(bodies, h), color: pick(colors, h >>> 4), pattern: pick(patterns, h2 >>> 23), ears: pick(ears, h >>> 9), eyes: pick(eyes, h >>> 14), mouth: pick(mouths, h >>> 19), hat: h2 % 3 === 0 ? pick(hats, h2 >>> 3) : 'none', item: pick(items.slice(1), h2 >>> 11), }; } const box = { x: -4, y: -8, size: 136 }; const percent = (value: number, start: number) => `${Math.round(((value - start) / box.size) * 1000) / 10}%`; const origin = (x: number, y: number) => `${percent(x, box.x)} ${percent(y, box.y)}`; const strokes = `stroke="${ink}" stroke-width="2.6" stroke-linejoin="round" stroke-linecap="round"`; interface Layers { back: string; body: string; eyes: string; hat: string; item: string; wave: string; waveOrigin: string; eyeOrigin: string; hatOrigin: string; itemOrigin: string; hatSway: boolean; itemMotion: string; } const cache = new Map<string, Layers>(); function layers(config: MonsterAvatarConfig): Layers { const key = Object.values(config).join('/'); let result = cache.get(key); if (result) return result; const palette = palettes[config.color]; const body = bodyGeometry(config.body); if (!palette || !(config.ears in earParts) || !(config.eyes in eyeParts) || !(config.mouth in mouthParts)) { throw new Error(`Unknown monster avatar: ${key}`); } const hat = hatParts[config.hat]; const item = itemParts[config.item]; if (!hat || !item) throw new Error(`Unknown monster avatar: ${key}`); const dy = body.top - 30; const [fx, fy] = body.face; const head = `transform="translate(${body.cx} ${dy}) scale(${body.sx} 1) translate(-64 0)"`; const face = `transform="translate(${fx} ${fy})"`; const holding = config.item !== 'none'; const [ix, iy] = body.item; const paw = (x: number, y: number) => `<ellipse cx="${x}" cy="${y}" rx="5.5" ry="5" fill="${palette.body}"/>` + `<path d="M${x - 1.8} ${y + 1.6}v2.2M${x + 1.6} ${y + 1.6}v2.2" stroke-width="1.5"/>`; const hand = item.hand ?? defaultHand; const motion = item.motion ?? 'bob'; result = { back: `<g ${head}>${earParts[config.ears](palette)}</g>` + (body.wave && !holding ? body.armRight(palette.body) : ''), wave: body.wave ? body.wave.art(palette.body) : '', waveOrigin: body.wave ? origin(...body.wave.shoulder) : '', body: `<path d="${body.path}" fill="${palette.body}" stroke-width="3"/>` + body.toes + bodyTexture(config.body, config.pattern, palette.shade) + body.arm(palette.body) + (body.wave || holding ? '' : body.armRight(palette.body)) + `<g transform="translate(${fx} ${fy + 2})">${mouthParts[config.mouth](palette)}</g>`, eyes: `<g ${face}>${eyeParts[config.eyes](palette)}</g>`, hat: `<g ${head}>${hat.art(palette)}</g>`, item: holding ? `<g transform="translate(${ix} ${iy})">${item.art}${body.paw ? paw(hand[0], hand[1]) : ''}</g>` : '', eyeOrigin: origin(64 + fx, 60 + fy), hatOrigin: origin(body.cx, body.top), itemOrigin: motion === 'pulse' || !body.paw ? origin(ix + 20, iy + 20) : origin(ix + hand[0], iy + hand[1]), hatSway: hat.sway === true, itemMotion: motion, }; cache.set(key, result); return result; } const svg = (content: string, attributes = '') => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${box.x} ${box.y} ${box.size} ${box.size}"${attributes}><g ${strokes}>${content}</g></svg>`; export function monsterAvatarSvg(config: MonsterAvatarConfig) { const l = layers(config); return svg(l.back + l.wave + l.body + l.eyes + l.hat + l.item); } export function monsterAvatarSrc(config: MonsterAvatarConfig) { return `data:image/svg+xml,${encodeURIComponent(monsterAvatarSvg(config))}`; } let observer: IntersectionObserver | undefined; function watch(element: Element) { if (typeof IntersectionObserver === 'undefined') return () => {}; observer ??= new IntersectionObserver(entries => { for (const entry of entries) entry.target.toggleAttribute('data-offscreen', !entry.isIntersecting); }); observer.observe(element); return () => observer?.unobserve(element); } export interface MonsterAvatarProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'color'>, Partial<MonsterAvatarConfig> { agentId?: string | undefined; config?: MonsterAvatarConfig | undefined; size?: number | undefined; animated?: boolean | undefined; label?: string | undefined; } const layerClass = 'sprout-monster-layer'; export function MonsterAvatar({ agentId, config, body, color, pattern, ears: earsProp, eyes: eyesProp, mouth, hat, item, size = 64, animated = true, label, className, style, ...props }: MonsterAvatarProps) { const ref = useRef<HTMLSpanElement>(null); useEffect(() => (animated && ref.current ? watch(ref.current) : undefined), [animated]); const base = config ?? monsterAvatar(agentId ?? 'monster'); const resolved: MonsterAvatarConfig = { body: body ?? base.body, color: color ?? base.color, pattern: pattern ?? base.pattern, ears: earsProp ?? base.ears, eyes: eyesProp ?? base.eyes, mouth: mouth ?? base.mouth, hat: hat ?? base.hat, item: item ?? base.item, }; const l = layers(resolved); const seed = hash(agentId ?? Object.values(resolved).join('/')); const layer = (content: string, extra?: { className?: string; style?: CSSProperties; motion?: string }) => content && ( <svg className={cn(layerClass, extra?.className)} viewBox={`${box.x} ${box.y} ${box.size} ${box.size}`} style={extra?.style} data-motion={extra?.motion} aria-hidden="true" dangerouslySetInnerHTML={{ __html: `<g ${strokes}>${content}</g>` }} /> ); return ( <span ref={ref} data-slot="monster-avatar" data-animated={animated ? '' : undefined} role={label ? 'img' : undefined} aria-label={label} aria-hidden={label ? undefined : true} className={cn('sprout-monster', className)} style={ { '--sprout-monster-size': `${size}px`, '--sm-delay': `-${(seed % 5000) / 1000}s`, '--sm-blink': `${4 + ((seed >>> 13) % 30) / 10}s`, ...style, } as CSSProperties } {...props} > <span className="sprout-monster-figure"> {layer(l.back)} {layer(l.wave, { motion: 'wave', style: { transformOrigin: l.waveOrigin } })} {layer(l.body)} {layer(l.eyes, { className: 'sprout-monster-eyes', style: { transformOrigin: l.eyeOrigin } })} {layer(l.hat, { motion: l.hatSway ? 'sway' : undefined, style: { transformOrigin: l.hatOrigin } })} {layer(l.item, { className: 'sprout-monster-item', motion: l.itemMotion, style: { transformOrigin: l.itemOrigin }, })} </span> </span> ); }And the files it imports:
lib/sprout/hash.tslib/sprout/monster-avatar-parts.tslib/sprout/monster-avatar-presets.ts
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-monster { --sprout-monster-size: 4rem; width: var(--sprout-monster-size); height: var(--sprout-monster-size); vertical-align: middle; user-select: none; flex-shrink: 0; display: inline-block; position: relative; } .sprout-monster-figure, .sprout-monster-layer { width: 100%; height: 100%; position: absolute; inset: 0; } .sprout-monster-layer { overflow: visible; } @media (prefers-reduced-motion: no-preference) { .sprout-monster[data-animated] .sprout-monster-figure { transform-origin: 50% 92.6%; animation: sprout-monster-breathe 3.4s ease-in-out var(--sm-delay) infinite; } .sprout-monster[data-animated] .sprout-monster-eyes { animation: sprout-monster-blink var(--sm-blink) linear var(--sm-delay) infinite; } .sprout-monster[data-animated] [data-motion="bob"] { animation: sprout-monster-bob 2.8s ease-in-out var(--sm-delay) infinite; } .sprout-monster[data-animated] [data-motion="sway"] { animation: sprout-monster-sway 3.6s ease-in-out var(--sm-delay) infinite; } .sprout-monster[data-animated] [data-motion="wave"] { animation: sprout-monster-wave 2.4s ease-in-out var(--sm-delay) infinite; } .sprout-monster[data-animated] [data-motion="float"] { animation: sprout-monster-float 2.6s ease-in-out var(--sm-delay) infinite; } .sprout-monster[data-animated] [data-motion="pulse"] { animation: sprout-monster-pulse 1.8s ease-in-out var(--sm-delay) infinite; } .sprout-monster[data-animated] [data-motion="ring"] { animation: sprout-monster-ring 3.2s ease-in-out var(--sm-delay) infinite; } .sprout-monster[data-animated] .sm-dot { animation: 1.2s ease-in-out infinite sprout-monster-dot; } .sprout-monster[data-animated] .sm-dot:nth-child(2) { animation-delay: .2s; } .sprout-monster[data-animated] .sm-dot:nth-child(3) { animation-delay: .4s; } .sprout-monster[data-animated] .sm-steam { animation: 2s ease-in-out infinite sprout-monster-steam; } .sprout-monster[data-offscreen], .sprout-monster[data-offscreen] * { animation-play-state: paused !important; } } @keyframes sprout-monster-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(.985, 1.03); } } @keyframes sprout-monster-blink { 0%, 93%, 99%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.08); } } @keyframes sprout-monster-bob { 0%, 100% { transform: rotate(0) translateY(0); } 50% { transform: rotate(-4deg) translateY(-1.5%); } } @keyframes sprout-monster-sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } } @keyframes sprout-monster-wave { 0%, 50%, 100% { transform: rotate(0); } 12%, 37% { transform: rotate(-10deg); } 25% { transform: rotate(4deg); } } @keyframes sprout-monster-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4%); } } @keyframes sprout-monster-pulse { 0%, 60%, 100% { transform: scale(1); } 30% { transform: scale(1.08); } } @keyframes sprout-monster-ring { 0%, 66%, 92%, 100% { transform: rotate(0); } 72% { transform: rotate(-10deg); } 78% { transform: rotate(9deg); } 84% { transform: rotate(-6deg); } 88% { transform: rotate(3deg); } } @keyframes sprout-monster-dot { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } } @keyframes sprout-monster-steam { 0%, 100% { opacity: .2; } 50% { opacity: 1; } } }Import it from
@/components/ui/monster-avatar. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/monster-avatar.
Usage
import { MonsterAvatar, monsterAvatarPresets } from "@tulipfarm/sprout/monster-avatar";
<MonsterAvatar agentId={agent.id} size={48} />
<MonsterAvatar color="yellow" hat="headphones" item="email" />
<MonsterAvatar config={monsterAvatarPresets[0].config} label="Marketing agent" />Part props override the character from agentId or config. Passanimated={false} for a still avatar. Use monsterAvatarSrc(config) for a stilldata: URL.
Mix your own
<MonsterAvatar color="yellow" body="blob" pattern="fur" ears="cat" eyes="round" mouth="smile" hat="headphones" item="email" />Animations
Every monster breathes and blinks. What it holds sets the rest of its motion, and each avatar starts at its own point in the loop so a grid never moves in step.
- BreatheEvery body, always
- BlinkOpen eyes, every few seconds
- BobLaptop, email, chart…
- SwayMagnifier, globe, plant…
- FloatRocket, plane, cloud…
- PulseHeart, shield, bulb…
- RingBell, megaphone, gift
- WaveCheer body
- TypingChat bubble dots
- SteamCoffee
- Hat swaySprout, tulip, halo
- Stillanimated={false} or reduced motion
Presets
- Marketing
- Growth
- Sales
- Strategy
- Research
- Data Science
- Analytics
- Product
- Operations
- Engineering
- Support
- Customer Success
- Content
- Design
- HR
- Finance
- Business Intelligence
- Project Manager
- Product Launch
- Developer
- Security
- Go-to-Market
- Localization
- Legal
- Learning
- Education
- Writing
- Documentation
- Meeting
- Calendar
- Workflow
- Investigator
- Experiment
- Reporting
- Notifications
- Audio
- Video
- Visual
- Travel
- Maps
- Real Estate
- Commerce
- Recipe
- Sustainability
- Health
- Fitness
- Weather
- Lifestyle
- Trip Planner
- Transport
- Home
- Gardening
- Pet Care
- Gaming
- Entertainment
- News
- Astrology
- Database
- Ideas
- Rewards
- Celebration
- Morning Brief
- Bud
- Monitoring
- Shopping
- Podcast
- Explorer
- Tracker
- Courier
- Cheerleader
- Greeter
- Champion
- Guardian
Performance
The artwork is inline SVG, built from strings and cached, with no images to load. Breathing, blinking, and item motion are CSS animations that change only transform and opacity on separate layers, so the browser runs them on the compositor. A shared observer pauses avatars that are off screen, and they stay still when the user prefers reduced motion.
Accessibility
Without label the avatar is decorative and hidden from assistive technology. Put the agent's name in nearby text, or pass label.