Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): enrich generated avatars

Gus531912ab5df8
diff --git a/src/web/src/lib/avatar/boring-palettes.test.ts b/src/web/src/lib/avatar/boring-palettes.test.ts
index 61b81b071..b649461d4 100644
--- a/src/web/src/lib/avatar/boring-palettes.test.ts
+++ b/src/web/src/lib/avatar/boring-palettes.test.ts
@@ -21,4 +21,9 @@ describe("paletteFromSeed", () => {
it("first palette is the official boringavatars.com sample", () => {
expect(PALETTES[0]).toEqual(["#00686c", "#32c2b9", "#edecb3", "#fad928", "#ff9915"])
})
+
+ it("ships the approved 25 color worlds", () => {
+ expect(PALETTES).toHaveLength(25)
+ for (const palette of PALETTES) expect(palette).toHaveLength(5)
+ })
})
diff --git a/src/web/src/lib/avatar/boring-palettes.ts b/src/web/src/lib/avatar/boring-palettes.ts
index b71702f8f..89fad2f3a 100644
--- a/src/web/src/lib/avatar/boring-palettes.ts
+++ b/src/web/src/lib/avatar/boring-palettes.ts
@@ -1,12 +1,13 @@
/**
* Color palettes for boring-avatars, chosen deterministically per seed.
*
- * Set 0 is the official boringavatars.com sample palette; the rest are the
- * opening entries of Matt DesLauriers' Nice Color Palettes (the same source
- * boringavatars.com's own playground samples from). Three template entries
- * (idx 3, 6, 7) were replaced with lively, curated sets — the originals were
- * muddy/dark or had clashing hues (the template-residue bug DESIGN.md calls
- * out). No global desaturation: it dropped contrast, so the vibrant hues stand.
+ * Set 0 is the official boringavatars.com sample palette. Sets 1–12 began from
+ * opening entries of Matt DesLauriers' Nice Color Palettes (the same source the
+ * boringavatars.com playground samples from), with three muddy/clashing entries
+ * replaced by curated sets. Sets 13–24 are Alook's approved expansion: each has
+ * a deliberate dark anchor, bright body hues, and a light relief color so every
+ * generated wrapper can find a readable background. No global desaturation: it
+ * dropped contrast, so the vibrant hues stand.
*
* Selection reuses the same hash + mulberry32 PRNG as `gradient-from-seed.ts`
* so the "looks random, never flickers" behavior matches the rest of the app.
@@ -26,6 +27,18 @@ export const PALETTES: readonly (readonly string[])[] = [
["#e94e77", "#d68189", "#c6a49a", "#c6e5d9", "#f4ead5"],
["#3fb8af", "#7fc7af", "#dad8a7", "#ff9e9d", "#ff3d7f"],
["#00a8c6", "#40c0cb", "#f9f2e7", "#aee239", "#8fbe00"],
+ ["#23352f", "#7bc95a", "#dce95c", "#ffd65a", "#fff1b8"],
+ ["#17394a", "#35aeb4", "#77d9d5", "#b9eff0", "#f3d978"],
+ ["#3e233d", "#8b4771", "#dc6b9d", "#ff9fb3", "#ffe1dd"],
+ ["#4a2e25", "#d6664c", "#f58c64", "#ffc173", "#ffe2ad"],
+ ["#24372e", "#55744f", "#90aa62", "#c8d685", "#f0efc0"],
+ ["#25294f", "#4d5c9a", "#7587d6", "#a9b6ff", "#ebe9ff"],
+ ["#493044", "#eb7c8b", "#ffb46d", "#ffe08b", "#c8ecdc"],
+ ["#3c302b", "#8d5d4d", "#c27f65", "#e7ae85", "#f3dfc7"],
+ ["#16202a", "#32d48e", "#c4f342", "#ffdf3f", "#ff7597"],
+ ["#17192e", "#3f477f", "#7457a8", "#c47edb", "#f3c8ef"],
+ ["#362a52", "#7d60a9", "#b699dc", "#dfc7f0", "#fff0d9"],
+ ["#432526", "#c6403f", "#f0654b", "#ffab62", "#ffe0a6"],
] as const
function hashStr(s: string): number {
diff --git a/src/web/src/lib/avatar/face.test.ts b/src/web/src/lib/avatar/face.test.ts
index 2f9bb5b97..49f4f5891 100644
--- a/src/web/src/lib/avatar/face.test.ts
+++ b/src/web/src/lib/avatar/face.test.ts
@@ -1,5 +1,6 @@
import { describe, it, expect } from "vitest"
-import { renderFaceSvg, ink } from "./face"
+import { FACE_HAT_LINE, FACE_SHAPE_PATHS, FACE_VOCABULARY, renderFaceSvg, ink } from "./face"
+import { PALETTES } from "./boring-palettes"
const PALETTE = ["#00686c", "#32c2b9", "#edecb3", "#fad928", "#ff9915"]
@@ -76,13 +77,12 @@ describe("renderFaceSvg", () => {
it("keeps the tilt gentle (upright, human) — never a full spin", () => {
// Faces ride the shape rotation; a big spin flips them upside-down ("not a
- // face anymore"). Rotation must stay within ±8° (rot = i%17 − 8). A wider
- // tilt would also eat the crown-reserve budget (radial shapes are rotation-
- // invariant in max radius, but the closed-form bound assumes this cap).
+ // face anymore"). Rotation must stay within ±20° (rot = i%41 − 20). A wider
+ // tilt would also eat the crown-reserve budget of the grounded paths.
for (let n = 0; n < 80; n++) {
const svg = renderFaceSvg(`r-${n}`, PALETTE)
const rot = parseFloat((svg.match(/rotate\((-?\d+(?:\.\d+)?)/) ?? ["", "0"])[1])
- expect(Math.abs(rot)).toBeLessThanOrEqual(8)
+ expect(Math.abs(rot)).toBeLessThanOrEqual(20)
}
})
@@ -123,13 +123,7 @@ describe("renderFaceSvg", () => {
}
})
- it("reserves the top ~20% (y<7.2) for a hat — the crown never pokes into the band", () => {
- // The head is placed low (center y23.5) and sized (R14.45) so the top of the
- // canvas stays clear for a future hat ("头的最高点不能超过帽子"). Recompute the
- // transformed topmost point of the wrapper path for many seeds and assert it
- // stays >= HAT_LINE. This mirrors the closed-form bound (worst crown ~8.76);
- // if a shape/geometry change lowered the crown into the band, this fails.
- const HAT_LINE = 7.2
+ it("keeps the slim future hat band clear without changing approved shapes", () => {
const CX = 18
const CYh = 23.5
for (let n = 0; n < 400; n++) {
@@ -154,24 +148,52 @@ describe("renderFaceSvg", () => {
crown = Math.min(crown, y)
}
void tx
- expect(crown).toBeGreaterThanOrEqual(HAT_LINE)
+ expect(crown).toBeGreaterThanOrEqual(FACE_HAT_LINE)
}
})
- it("picks shape, eye, and mouth independently and near-uniformly (no digit%6 clustering)", () => {
+ it("keeps every approved shape control point below the slim hat line at every ±20° angle", () => {
+ const CX = 18
+ const CYh = 23.5
+ const scale = 1.02
+ for (const d of FACE_SHAPE_PATHS) {
+ const points = [...d.matchAll(/(-?\d+(?:\.\d+)?) (-?\d+(?:\.\d+)?)/g)].map((match) => [
+ parseFloat(match[1]),
+ parseFloat(match[2]),
+ ])
+ for (let rotation = -20; rotation <= 20; rotation++) {
+ const rad = (rotation * Math.PI) / 180
+ for (const [px, py] of points) {
+ const dx = (px - CX) * scale
+ const dy = (py - CYh) * scale
+ const y = CYh + dx * Math.sin(rad) + dy * Math.cos(rad)
+ expect(y).toBeGreaterThanOrEqual(FACE_HAT_LINE)
+ }
+ }
+ }
+ })
+
+ it("ships the approved 11 × 21 × 22 vocabulary", () => {
+ expect(FACE_VOCABULARY).toEqual({
+ shapes: 11,
+ eyes: 21,
+ mouths: 22,
+ combinations: 5082,
+ })
+ })
+
+ it("picks shape, eye, and mouth independently (no shared-digit clustering)", () => {
// The old code coupled features to a shared 0–9 digit %6, making idx 4/5 only
- // ~10% and collapsing the combination space. Radix slicing (i%8, (i/8)%6,
- // (i/48)%6) gives each feature its own uniform, decorrelated index. Count how
- // many distinct shapes/eyes/mouths appear across many seeds — all should show.
+ // ~10% and collapsed the combination space. Radix slicing gives each feature
+ // its own uniform, decorrelated index. Count distinct wrapper paths and whole
+ // outputs across many seeds to catch accidental vocabulary collapse.
const shapes = new Set<string>()
const svgs: string[] = []
for (let n = 0; n < 4000; n++) svgs.push(renderFaceSvg(`d-${n}`, PALETTE))
- // Distinct wrapper paths ≈ distinct shapes (8 shapes → the path d differs).
- for (const svg of svgs) shapes.add(svg.match(/<path d="([^"]+)"/)![1].slice(0, 24))
- // All 8 shapes should appear; if features collapsed, far fewer distinct heads.
- expect(shapes.size).toBeGreaterThanOrEqual(8)
+ for (const svg of svgs) shapes.add(svg.match(/<path d="([^"]+)"/)![1])
+ expect(shapes.size).toBe(11)
// The full head (shape+eye+mouth) space is large: expect many distinct faces.
- expect(new Set(svgs).size).toBeGreaterThan(100)
+ expect(new Set(svgs).size).toBeGreaterThan(500)
})
it("keeps face wrapper and background readably apart on every palette (no low-contrast melt)", () => {
@@ -183,14 +205,15 @@ describe("renderFaceSvg", () => {
const h = hex.replace("#", "")
return (parseInt(h.slice(0, 2), 16) * 299 + parseInt(h.slice(2, 4), 16) * 587 + parseInt(h.slice(4, 6), 16) * 114) / 1000
}
- const seeds = Array.from({ length: 40 }, (_, n) => `seed-${n}`)
- // A single-hue palette genuinely can't separate — use the real 5-color set.
- for (const seed of seeds) {
- const svg = renderFaceSvg(seed, PALETTE)
- // first two rects are bg then wrapper; pull their fills in document order
- const fills = [...svg.matchAll(/fill="(#[0-9a-fA-F]{6})"/g)].map((m) => m[1])
- const [bg, wrapper] = fills
- expect(Math.abs(lum(bg) - lum(wrapper))).toBeGreaterThan(15)
+ const seeds = Array.from({ length: 400 }, (_, n) => `seed-${n}`)
+ for (const palette of PALETTES) {
+ for (const seed of seeds) {
+ const svg = renderFaceSvg(seed, palette)
+ // first two fills are bg then wrapper; pull them in document order
+ const fills = [...svg.matchAll(/fill="(#[0-9a-fA-F]{6})"/g)].map((m) => m[1])
+ const [bg, wrapper] = fills
+ expect(Math.abs(lum(bg) - lum(wrapper))).toBeGreaterThan(40)
+ }
}
})
})
diff --git a/src/web/src/lib/avatar/face.ts b/src/web/src/lib/avatar/face.ts
index 0f574ad25..48a7134b9 100644
--- a/src/web/src/lib/avatar/face.ts
+++ b/src/web/src/lib/avatar/face.ts
@@ -2,15 +2,14 @@
// fixed beam geometry. Ported from the approved design prototype (Alli). Same
// 36-unit canvas, same PRNG + auto-contrast ink as the lib's beam, so it reads
// as "more of the same face", not a new style. The feature vocabulary grew:
-// 8 shapes (silhouette-distinct) · 6 eyes · 6 mouths.
+// 11 grounded shapes · 21 eyes · 22 mouths.
// Each seed picks its shape/eye/mouth deterministically (INDEPENDENTLY), so a
// given id always renders the same face and never flickers across renames.
//
-// TOP-RESERVE: the head sits in the LOWER band of the canvas, leaving the top
-// ~20% (y ≤ HAT_LINE) clear for a future hat system — a hat must be able to sit
-// ABOVE the crown ("头的最高点不能超过帽子"). The crown is guaranteed ≥ HAT_LINE
-// for every shape under every random tilt/scale/nudge (see the closed-form
-// bound + brute-force check in the design harness).
+// TOP-RESERVE: the approved head + ±20° pose leaves a slim top band clear for a
+// possible future hat. Hats do not exist in the product today, so this reserve
+// follows the QA-approved avatar geometry — the geometry must never be retuned
+// to satisfy a speculative accessory constraint (Gus, uiux#609–612).
//
// `beam` only. Marble (server/channel icons, banner) stays on the lib.
@@ -21,16 +20,7 @@ const CX = 18
// Only the top is reserved — the sides/chin fill the crop like a normal avatar
// (an earlier R=11.2 shrank the whole head to reserve the top → "太小", Gus #99).
const CYh = 23.5
-// Base head radius. Solved from the reserve constraint alone: worst-case crown =
-// CYh − sMax·R·maxMod ≥ HAT_LINE. With maxMod≈1.10 (fattest shape), sMax=1.02,
-// HAT_LINE=7.2 → R ≤ 14.45. That fills ~80% of the disc at the widest band
-// (matches the lib's beam presence), chin clips off-canvas at the bottom.
-const R = 14.45
-const HAT_LINE = 7.2
-const TAU = Math.PI * 2
-// Dense sampling — the 8 shapes include 5-lobed stars; too few points and the
-// lobes flatten into a blob. 200 keeps the silhouette crisp at any render size.
-const N = 200
+export const FACE_HAT_LINE = 4
// boring-avatars PRNG helpers (verbatim from the lib bundle, so the base
// transform matches the lib's beam feel exactly).
@@ -84,56 +74,61 @@ function farthestByLuminance(wrapper: string, palette: readonly string[]): strin
return best
}
-// A closed radial curve r(a) = R * mod(a) about the head center (CX, CYh).
-function polyPath(mod: (a: number) => number): string {
- let d = ""
- for (let i = 0; i <= N; i++) {
- const a = (i / N) * TAU
- const r = R * mod(a)
- const x = CX + r * Math.cos(a)
- const y = CYh + r * Math.sin(a)
- d += (i === 0 ? "M" : "L") + x.toFixed(2) + " " + y.toFixed(2) + " "
- }
- return d + "Z"
-}
-// Superellipse radius at angle a — a soft rounded-square (n≈3), the "rounded"
-// silhouette without literal corners (a <rect> can't be used: under the
-// circular avatar crop a full-canvas rect fills the whole crop top, leaving no
-// room to reserve the hat band, and its corners poke straight up under tilt).
-const superell = (a: number, n: number): number =>
- 1 / Math.pow(Math.pow(Math.abs(Math.cos(a)), n) + Math.pow(Math.abs(Math.sin(a)), n), 1 / n)
-
-// Wrapper shapes: soft, chunky, distinct by SILHOUETTE (proportion + gentle
-// asymmetry), not corner-radius — corner differences vanish at 32px under the
-// circular crop. All are bounded radial curves: a radial shape's max radius is
-// rotation-invariant, so tilt never pushes the crown higher than the closed-
-// form bound — that's what lets the hat reserve hold under every random tilt.
-// The three lobed shapes (clover/trilobe/star5) use Alli's approved formulas
-// (uiux#87) verbatim; do not retune the coefficients.
-const SHAPES: Record<string, (a: number) => number> = {
- round: () => 1,
- rounded: (a) => superell(a, 3.2) * 0.95,
- wide: (a) => Math.hypot(1.06 * Math.cos(a), 0.74 * Math.sin(a)),
- potato: (a) => 0.95 * (1 + 0.11 * Math.sin(a + 0.5) + 0.06 * Math.cos(2 * a - 0.8)),
- drop: (a) => 0.94 * (1 + 0.14 * Math.cos(a - Math.PI / 2)),
- clover: (a) => 0.8 * (1 + 0.17 * Math.cos(4 * a)),
- trilobe: (a) => 0.86 * (1 + 0.14 * Math.cos(3 * a - Math.PI / 2)),
- star5: (a) => 0.8 * (1 + 0.15 * Math.cos(5 * a - Math.PI / 2)),
+// Grounded wrapper shapes from the approved component review (uiux#591–593).
+// Their lower half shares a sturdy, almost-straight body and a broad rounded
+// finish; identity lives in the crown. That keeps every avatar complete when a
+// transform exposes more of the bottom without reintroducing sharp stars,
+// pinched waists, scalloped chins, or the rejected bump/mushroom silhouettes.
+// These path literals are the QA-approved geometry. Do not retune them to make a
+// future accessory easier; adapt the accessory/reserve to the avatar instead.
+const SHAPES: Record<string, string> = {
+ dome: "M2 29V23C2 14.8 8.2 9 17.2 8.2C26.9 7.3 34 13.2 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ loaf: "M2 29V23C2 15.7 6.2 11.2 12.3 10.4C14.5 10.1 15.4 7.1 20.3 7.1C28.5 7.1 34 14.1 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ tall: "M4 29V22C4 12.8 9.5 7 18 7C26.5 7 32 12.8 32 22V29C32 34.2 27.5 37.2 18 37.2C8.5 37.2 4 34.2 4 29Z",
+ twin: "M2 29V23C2 16.4 5.8 13.8 10 12.4C9.1 9.1 11.5 7.3 14.2 9.4C16.4 11 19.8 11 22 9.3C24.8 7.1 27.7 9.1 26.8 12.5C31 13.9 34 16.7 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ cloud: "M2 29V23C2 17 5.4 14 9.8 13C9.6 9.5 12.4 7.8 15.1 10C16.2 6.9 20.7 6.9 21.7 10.1C24.8 7.8 28 9.8 27.6 13.2C31.6 14.4 34 17.1 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ block: "M3 29V13C3 9.6 5.7 7.7 9.2 7.7H26.8C30.3 7.7 33 9.6 33 13V29C33 34.2 28.5 37.2 18 37.2C7.5 37.2 3 34.2 3 29Z",
+ slope: "M2 29V23C2 15.4 7.2 12 12.7 11.6C15.9 11.3 17.2 8.1 22.5 8.1C29.6 8.1 34 14.4 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ bean: "M2 29V23C2 16.4 5.7 13 10.4 11.8C11.3 8.8 14.2 7.6 17 9.6C19.8 6.9 24.5 7.8 26.2 11.2C31.1 12.6 34 16.5 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ flat: "M2 29V23C2 15.1 8 9.2 15.4 9.2H22.6C29.7 9.2 34 15.1 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ notch: "M2 29V23C2 15.5 7.6 10.6 14.1 9.4C15.5 9.2 16.1 11.8 18 11.8C19.9 11.8 20.5 9.2 21.9 9.4C28.4 10.6 34 15.5 34 23V29C34 34.5 29 37.5 18 37.5C7 37.5 2 34.5 2 29Z",
+ squash: "M1.5 29V23C1.5 14.7 8.1 10.2 18 10.2C27.9 10.2 34.5 14.7 34.5 23V29C34.5 34.5 29.2 37.5 18 37.5C6.8 37.5 1.5 34.5 1.5 29Z",
}
const SHAPE_KEYS = Object.keys(SHAPES)
+export const FACE_SHAPE_PATHS = Object.values(SHAPES)
-// Eyes — big, chunky, bold strokes (ESW). Baseline is beam's dot, enlarged.
+// Eyes — bold, rounded, and legible at 32px. Pair-level functions keep gaze,
+// asymmetry, and one-eye expressions coherent instead of mixing two half-sets.
const ESW = 1.6
-type EyeFn = (x: number, y: number, c: string, right?: boolean) => string
+type EyeFn = (spread: number, c: string) => string
+const eyeCenters = (spread: number): readonly [number, number] => [14 - spread, 22 + spread]
+const oppositeInk = (c: string): string => c === "#000000" ? "#ffffff" : "#000000"
+const pupilPair = (spread: number, dxLeft = 0, dxRight = 0, dy = 0): string => {
+ const [left, right] = eyeCenters(spread)
+ return `<ellipse cx="${left}" cy="20" rx="2.15" ry="2.1" fill="#ffffff"/><circle cx="${left + dxLeft}" cy="${20.25 + dy}" r="1.02" fill="#000000"/><ellipse cx="${right}" cy="20" rx="2.15" ry="2.1" fill="#ffffff"/><circle cx="${right + dxRight}" cy="${20.25 + dy}" r="1.02" fill="#000000"/>`
+}
const EYES: Record<string, EyeFn> = {
- dot: (x, y, c) => `<circle cx="${x}" cy="${y}" r="1.6" fill="${c}"/>`,
- round: (x, y, c) => `<circle cx="${x}" cy="${y}" r="1.9" fill="${c}"/>`,
- wide: (x, y, c) => `<g><circle cx="${x}" cy="${y}" r="2.1" fill="#fff"/><circle cx="${x}" cy="${y + 0.3}" r="1.15" fill="${c}"/></g>`,
- sleepy: (x, y, c) => `<path d="M${x - 1.8} ${y} q1.8 1.7 3.6 0" stroke="${c}" stroke-width="${ESW}" fill="none" stroke-linecap="round"/>`,
- wink: (x, y, c, right) => right
- ? `<path d="M${x - 1.8} ${y} q1.8 1.7 3.6 0" stroke="${c}" stroke-width="${ESW}" fill="none" stroke-linecap="round"/>`
- : `<circle cx="${x}" cy="${y}" r="1.9" fill="${c}"/>`,
- happy: (x, y, c) => `<path d="M${x - 1.8} ${y + 0.7} q1.8 -2 3.6 0" stroke="${c}" stroke-width="${ESW}" fill="none" stroke-linecap="round"/>`,
+ bead: (spread, c) => { const [l, r] = eyeCenters(spread); return `<circle cx="${l}" cy="20" r="1.7" fill="${c}"/><circle cx="${r}" cy="20" r="1.7" fill="${c}"/>` },
+ wide: (spread) => pupilPair(spread),
+ sleepy: (spread, c) => { const [l, r] = eyeCenters(spread); return `<path d="M${l - 2} 20q2 2 4 0M${r - 2} 20q2 2 4 0" fill="none" stroke="${c}" stroke-width="${ESW}" stroke-linecap="round"/>` },
+ happy: (spread, c) => { const [l, r] = eyeCenters(spread); return `<path d="M${l - 2} 21q2-2.4 4 0M${r - 2} 21q2-2.4 4 0" fill="none" stroke="${c}" stroke-width="${ESW}" stroke-linecap="round"/>` },
+ winkRight: (spread, c) => { const [l, r] = eyeCenters(spread); return `<circle cx="${l}" cy="20" r="1.8" fill="${c}"/><path d="M${r - 2} 20q2 2 4 0" fill="none" stroke="${c}" stroke-width="${ESW}" stroke-linecap="round"/>` },
+ winkLeft: (spread, c) => { const [l, r] = eyeCenters(spread); return `<path d="M${l - 2} 20q2 2 4 0" fill="none" stroke="${c}" stroke-width="${ESW}" stroke-linecap="round"/><circle cx="${r}" cy="20" r="1.8" fill="${c}"/>` },
+ lookRight: (spread) => pupilPair(spread, 1, 1),
+ crossEyed: (spread) => pupilPair(spread, 1, -1),
+ lookUp: (spread) => pupilPair(spread, 0, 0, -0.8),
+ uneven: (spread, c) => { const [l, r] = eyeCenters(spread); return `<circle cx="${l}" cy="20" r="2.5" fill="#ffffff"/><circle cx="${l}" cy="20.3" r="1.1" fill="#000000"/><circle cx="${r}" cy="20" r="1.45" fill="${c}"/>` },
+ oneBig: (spread) => { const [l, r] = eyeCenters(spread); return `<circle cx="${l}" cy="20" r="2.8" fill="#ffffff"/><circle cx="${l}" cy="20.35" r="1.25" fill="#000000"/><circle cx="${r}" cy="20" r="1.65" fill="#ffffff"/><circle cx="${r}" cy="20.2" r="0.8" fill="#000000"/>` },
+ bug: (spread) => { const [l, r] = eyeCenters(spread); return `<ellipse cx="${l}" cy="20" rx="1.7" ry="2.55" fill="#ffffff"/><circle cx="${l}" cy="20.5" r="0.9" fill="#000000"/><ellipse cx="${r}" cy="20" rx="1.7" ry="2.55" fill="#ffffff"/><circle cx="${r}" cy="20.5" r="0.9" fill="#000000"/>` },
+ glossy: (spread, c) => { const [l, r] = eyeCenters(spread); const detail = oppositeInk(c); return `<circle cx="${l}" cy="20" r="2.2" fill="${c}"/><circle cx="${l - 0.7}" cy="19.3" r="0.65" fill="${detail}"/><circle cx="${r}" cy="20" r="2.2" fill="${c}"/><circle cx="${r - 0.7}" cy="19.3" r="0.65" fill="${detail}"/>` },
+ squint: (spread, c) => { const [l, r] = eyeCenters(spread); return `<path d="M${l - 1.5} 20h3M${r - 1.5} 20h3" stroke="${c}" stroke-width="1.9" stroke-linecap="round"/>` },
+ closeSet: (_spread, c) => `<circle cx="16" cy="20" r="1.55" fill="${c}"/><circle cx="20" cy="20" r="1.55" fill="${c}"/>`,
+ farSet: (_spread, c) => `<circle cx="12.6" cy="20" r="1.55" fill="${c}"/><circle cx="23.4" cy="20" r="1.55" fill="${c}"/>`,
+ tallPins: (spread, c) => { const [l, r] = eyeCenters(spread); return `<ellipse cx="${l}" cy="20" rx="1.25" ry="2.15" fill="${c}"/><ellipse cx="${r}" cy="20" rx="1.25" ry="2.15" fill="${c}"/>` },
+ halfLid: (spread) => { const [l, r] = eyeCenters(spread); return `<ellipse cx="${l}" cy="20" rx="2.2" ry="2" fill="#ffffff"/><circle cx="${l}" cy="20.55" r="1" fill="#000000"/><ellipse cx="${r}" cy="20" rx="2.2" ry="2" fill="#ffffff"/><circle cx="${r}" cy="20.55" r="1" fill="#000000"/><path d="M${l - 2.2} 19.1h4.4M${r - 2.2} 19.1h4.4" stroke="#000000" stroke-width="1.35" stroke-linecap="round"/>` },
+ droopy: (spread) => { const [l, r] = eyeCenters(spread); return `<ellipse cx="${l}" cy="20" rx="2.1" ry="2.45" fill="#ffffff" transform="rotate(-8 ${l} 20)"/><circle cx="${l + 0.25}" cy="20.65" r="1" fill="#000000"/><ellipse cx="${r}" cy="20" rx="2.1" ry="2.45" fill="#ffffff" transform="rotate(8 ${r} 20)"/><circle cx="${r - 0.25}" cy="20.65" r="1" fill="#000000"/>` },
+ rings: (spread, c) => { const [l, r] = eyeCenters(spread); return `<circle cx="${l}" cy="20" r="1.8" fill="none" stroke="${c}" stroke-width="1.25"/><circle cx="${r}" cy="20" r="1.8" fill="none" stroke="${c}" stroke-width="1.25"/>` },
+ wobble: (spread, c) => { const [l, r] = eyeCenters(spread); return `<circle cx="${l}" cy="19.4" r="1.7" fill="${c}"/><circle cx="${r}" cy="20.6" r="1.7" fill="${c}"/>` },
}
const EYE_KEYS = Object.keys(EYES)
@@ -142,15 +137,38 @@ const EYE_KEYS = Object.keys(EYES)
const MSW = 1.5
type MouthFn = (spread: number, c: string) => string
const MOUTHS: Record<string, MouthFn> = {
- smile: (s, c) => `<path d="M14.5 ${24 + s}q3.5 2.6 7 0" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
- arc: (s, c) => `<path d="M13.5 ${24 + s} a1,0.85 0 0,0 9,0" fill="${c}"/>`,
+ soft: (s, c) => `<path d="M14.5 ${24.2 + s}q3.5 2.6 7 0" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
+ tinySmile: (s, c) => `<path d="M16.2 ${24.5 + s}q1.8 1.5 3.6 0" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
+ bigSmile: (s, c) => `<path d="M13.2 ${23.8 + s}q4.8 4 9.6 0" stroke="${c}" stroke-width="1.7" fill="none" stroke-linecap="round"/>`,
flat: (s, c) => `<path d="M15 ${24.5 + s}h6" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
+ smirk: (s, c) => `<path d="M15 ${25 + s}q3.5 0.7 6-1.2" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
+ crooked: (s, c) => `<path d="M14.5 ${25 + s}q2.2-1.6 4 0.1q1.6 1.4 3-0.4" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
+ pout: (s, c) => `<path d="M14.5 ${26 + s}q3.5-2.5 7 0" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
+ deepFrown: (s, c) => `<path d="M13.8 ${26.4 + s}q4.2-3.8 8.4 0" stroke="${c}" stroke-width="1.65" fill="none" stroke-linecap="round"/>`,
open: (s, c) => `<circle cx="18" cy="${25 + s}" r="2.3" fill="${c}"/>`,
- grin: (s, c) => `<path d="M13.5 ${23.6 + s}q4.5 3.4 9 0" stroke="${c}" stroke-width="1.8" fill="none" stroke-linecap="round"/>`,
+ gasp: (s, c) => `<ellipse cx="18" cy="${25 + s}" rx="2.05" ry="3.05" fill="${c}"/>`,
+ ooh: (s, c) => `<ellipse cx="18" cy="${25 + s}" rx="1.55" ry="2.3" fill="none" stroke="${c}" stroke-width="1.45"/>`,
+ grin: (s, c) => `<path d="M13.7 ${23.8 + s}q4.3 3.8 8.6 0q-0.4 4.2-4.3 4.2t-4.3-4.2Z" fill="${oppositeInk(c)}" stroke="${c}" stroke-width="1.15" stroke-linejoin="round"/>`,
+ bigGrin: (s, c) => `<rect x="12.8" y="${23.8 + s}" width="10.4" height="5.2" rx="2.6" fill="${c}"/><path d="M14.3 ${25 + s}q3.7 1.8 7.4 0" fill="none" stroke="${oppositeInk(c)}" stroke-width="1.5" stroke-linecap="round"/>`,
cat: (s, c) => `<path d="M14 ${24 + s}q2 1.8 4 0 q2 1.8 4 0" stroke="${c}" stroke-width="${MSW}" fill="none" stroke-linecap="round"/>`,
+ littleW: (s, c) => `<path d="M15 ${24.2 + s}q1.5 2 3 0q1.5 2 3 0" stroke="${c}" stroke-width="1.65" fill="none" stroke-linecap="round"/>`,
+ underbite: (s, c) => `<rect x="14.3" y="${23.8 + s}" width="7.4" height="4.8" rx="2.4" fill="${c}"/><rect x="16.2" y="${26.25 + s}" width="1.8" height="1.55" rx="0.5" fill="${oppositeInk(c)}"/><rect x="18" y="${26.25 + s}" width="1.8" height="1.55" rx="0.5" fill="${oppositeInk(c)}"/>`,
+ tongue: (s, c) => `<rect x="14.3" y="${23.6 + s}" width="7.4" height="5" rx="2.5" fill="${c}"/><ellipse cx="18" cy="${27 + s}" rx="2" ry="1.2" fill="${oppositeInk(c)}"/>`,
+ sideTongue: (s, c) => `<rect x="14.3" y="${23.6 + s}" width="7.4" height="5" rx="2.5" fill="${c}"/><ellipse cx="19.3" cy="${27.1 + s}" rx="1.8" ry="1.15" fill="${oppositeInk(c)}" transform="rotate(-12 19.3 ${27.1 + s})"/>`,
+ gummy: (s, c) => `<rect x="14.2" y="${23.7 + s}" width="7.6" height="4.9" rx="2.45" fill="${c}"/><rect x="18.1" y="${24.05 + s}" width="1.75" height="1.8" rx="0.5" fill="${oppositeInk(c)}"/>`,
+ chew: (s, c) => `<rect x="15" y="${23.7 + s}" width="6.6" height="3.2" rx="1.6" fill="${c}"/><circle cx="16.5" cy="${25.25 + s}" r="0.7" fill="${oppositeInk(c)}"/>`,
+ kiss: (s, c) => `<path d="M15.3 ${24.8 + s}q1.4-1.8 2.7-0.4q1.3-1.4 2.7 0.4q-1.1 1.8-2.7 1.8t-2.7-1.8Z" fill="${c}"/>`,
+ bubble: (s, c) => `<circle cx="18.8" cy="${25 + s}" r="1.6" fill="${c}"/><circle cx="16" cy="${24.5 + s}" r="0.65" fill="${c}"/>`,
}
const MOUTH_KEYS = Object.keys(MOUTHS)
+export const FACE_VOCABULARY = {
+ shapes: SHAPE_KEYS.length,
+ eyes: EYE_KEYS.length,
+ mouths: MOUTH_KEYS.length,
+ combinations: SHAPE_KEYS.length * EYE_KEYS.length * MOUTH_KEYS.length,
+} as const
+
// Render a generated beam face to an SVG string for the given seed + palette.
// Feature choice is deterministic on the seed hash; the head is placed in the
// lower band so the top ~20% stays clear for a hat.
@@ -164,19 +182,18 @@ export function renderFaceSvg(seed: string, palette: readonly string[]): string
// used i%len for shape but digit(i,4)%6 / digit(i,5)%6 for eye/mouth — a
// single 0–9 digit %6 makes idx 4/5 (wink/happy, grin/cat) only ~10% each
// (non-uniform), and coupling all three to the same source collapses the
- // 8×6×6 space. Radix slicing gives each feature its own uniform, decorrelated
- // index: shape = i mod 8, eye = (i/8) mod 6, mouth = (i/48) mod 6.
- const shapeFn = SHAPES[SHAPE_KEYS[i % SHAPE_KEYS.length]]
+ // 11×21×22 space. Radix slicing gives each feature its own uniform,
+ // decorrelated index regardless of vocabulary size.
+ const shapePath = SHAPES[SHAPE_KEYS[i % SHAPE_KEYS.length]]
const eyeFn = EYES[EYE_KEYS[Math.floor(i / SHAPE_KEYS.length) % EYE_KEYS.length]]
const mouthFn = MOUTHS[MOUTH_KEYS[Math.floor(i / (SHAPE_KEYS.length * EYE_KEYS.length)) % MOUTH_KEYS.length]]
// Per-seed variation, all BOUNDED so the crown-reserve bound above holds:
- // tilt ±8°, scale-about-center 0.98–1.02, horizontal nudge tx free, and
- // ty DOWNWARD ONLY (0..+1.6). No upward nudge: with the enlarged head the
- // crown bound (CYh − sMax·R·maxMod ≈ 7.34) has almost no top slack, so any
- // upward shift would poke into the hat band. Down is always safe (chin just
- // clips further off-canvas).
- const rot = (i % 17) - 8
+ // tilt ±20°, scale-about-center 0.98–1.02, horizontal nudge tx free, and
+ // ty DOWNWARD ONLY (0..+1.6). No upward nudge: the lowest approved crown
+ // control-points intentionally keep only a small hat-band margin. Down is
+ // always safe (the fully rounded chin simply clips further off-canvas).
+ const rot = (i % 41) - 20
const scale = 1 + unit(i, 3) / 100
const tx = ((i % 27) / 26 - 0.5) * 4.0
const ty = ((digit(i, 3) % 5) / 4) * 1.6
@@ -187,9 +204,8 @@ export function renderFaceSvg(seed: string, palette: readonly string[]): string
const eyeSpread = i % 2
const mouthSpread = i % 2
- const wrapperEl = `<path d="${polyPath(shapeFn)}" fill="${wrapper}"/>`
- const leftEye = eyeFn(14 - eyeSpread, 20, c, false)
- const rightEye = eyeFn(22 + eyeSpread, 20, c, true)
+ const wrapperEl = `<path d="${shapePath}" fill="${wrapper}"/>`
+ const eyes = eyeFn(eyeSpread, c)
const mouth = mouthFn(mouthSpread, c)
// The face is nested inside the head's transform group and shares its EXACT
@@ -204,5 +220,5 @@ export function renderFaceSvg(seed: string, palette: readonly string[]): string
// would collide across the many faces on one page (member lists, message
// streams). The 36×36 viewBox + the caller's `overflow-hidden` crop already
// bound the drawing; anything outside the box is clipped by the container.
- return `<svg viewBox="0 0 ${C} ${C}" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><rect width="${C}" height="${C}" fill="${bg}"/><g transform="${faceXf}">${wrapperEl}${leftEye}${rightEye}${mouth}</g></svg>`
+ return `<svg viewBox="0 0 ${C} ${C}" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><rect width="${C}" height="${C}" fill="${bg}"/><g transform="${faceXf}">${wrapperEl}${eyes}${mouth}</g></svg>`
}