// Personagens "de recorte": peças rígidas (cabeça, cabelo, tronco, braços, pernas) que se mexem por inteiro — // sem boca sincronizada, como na referência. Multidão = silhuetas. import React from "react"; import { COLORS } from "./colors"; import { rng } from "./random"; import type { Crowd, Person } from "./spec"; import type { CharacterLook } from "./character"; import { CharacterFigure } from "./CharacterFigure"; import { evaluate } from "./motion"; /** Pessoa em pé num viewBox 200×420; (0,0) do grupo = pés no centro. */ export function PersonFigure({ p, frame, fps }: { p: Person; frame: number; fps: number }) { const skin = p.skin ?? "#c98a5e"; const outfit = p.outfit ?? "#9b7be0"; const hair = p.hairColor ?? "#e8e8ee"; const sway = Math.sin(frame / (fps * 0.9)) * 1.5; const arm = p.pointing ? -70 + Math.sin(frame / (fps * 0.5)) * 4 : 6 + Math.sin(frame / fps) * 2; return ( {[0, 1, 2, 3, 4, 5].map((i) => )} {p.hair === "bun" && <>} {(p.hair ?? "short") === "short" && } {p.glasses && ( )} ); } const SKINS = ["#f1c7a3", "#e0b48f", "#d09a70", "#c08055", "#a8704a", "#8d5a3b", "#6e4630"]; const HAIRS = ["#2a1e16", "#3a2a1e", "#6b4226", "#c9c9cf", "#e8c35a", "#1e1612", "#8a8a92"]; const CLOTHES = ["#3f6b8a", "#c8443a", "#5b6b3a", "#e8b13a", "#7a5ce0", "#2f6db3", "#d98a5c", "#4f7a4a", "#8a6f9e", "#56704a", "#e9ecef"]; const pick = (r: () => number, list: readonly T[]): T => list[Math.floor(r() * list.length) % list.length]; /** Aparência sorteada de quem está na multidão: cada um diferente (cabeça, altura, cabelo, roupa, acessório). */ export function crowdLook(seed: number): CharacterLook { const r = rng(seed * 7919 + 17); const female = r() < 0.45; const old = r() < 0.25; const hairStyle = female ? pick(r, ["long", "bun", "curly", "side"] as const) : pick(r, ["short", "side", "bald", "curly", "spiky", "cap"] as const); const top = pick(r, female ? (["shirt", "dress", "hoodie", "jacket"] as const) : (["shirt", "jacket", "hoodie", "uniform", "shirt"] as const)); const acc: NonNullable = []; const roll = r(); if (!female && roll < 0.14) { acc.push("helmet", "vest"); } else if (roll < 0.22) acc.push("scarf"); else if (roll < 0.3) acc.push("watch"); return { build: pick(r, ["slim", "average", "average", "heavy"] as const), height: 0.86 + r() * 0.26, skin: pick(r, SKINS), hair: { style: hairStyle, color: old ? "#c9c9cf" : pick(r, HAIRS) }, beard: { style: female ? "none" : pick(r, ["none", "none", "stubble", "mustache", "full", "goatee"] as const), color: old ? "#b0b0b8" : pick(r, HAIRS) }, glasses: r() < 0.22 ? pick(r, ["round", "square"] as const) : "none", brows: r() < 0.5 ? "thick" : "thin", top: { style: top, color: pick(r, CLOTHES), accent: pick(r, CLOTHES) }, bottom: { style: female && r() < 0.3 ? "skirt" : "pants", color: pick(r, ["#2c3346", "#3a3f4a", "#5a4a3a", "#2b3a5a"]) }, shoes: pick(r, ["#1d1d24", "#5a3a22", "#f2f2f2"]), head: pick(r, ["round", "oval", "square", "wide"] as const), nose: pick(r, ["curve", "round", "button", "wide", "long"] as const), lids: 0.1 + r() * 0.35, wrinkles: old ? 0.6 : 0, belly: !female && r() < 0.2, ...(acc.length ? { accessories: acc, accessoryColor: acc[0] === "helmet" ? "#f2a31a" : undefined } : {}), }; } /** Multidão: pessoas desenhadas com o mesmo traço dos personagens, cada uma diferente, em duas fileiras. */ export function CrowdFigure({ c, frame, fps = 30 }: { c: Crowd; frame: number; fps?: number }) { const rand = rng(c.count * 31 + 3); const people = Array.from({ length: c.count }, (_, i) => ({ i, x: (i + 0.5) / c.count + (rand() - 0.5) * 0.04, back: i % 2 === 1, p: rand() * 6 })) .sort((a, b) => Number(b.back) - Number(a.back)); const t = frame / fps; return (
{people.map((m) => { const h = m.back ? 78 : 92; const st = evaluate({ x: 0, expression: pick(rng(m.i + 5), ["neutral", "smile", "happy", "neutral", "smirk", "surprised"] as const) }, t, 3600, m.i * 7 + 3); return (
); })}
); }