Cartoon: mãos, membros e cenários novos; elenco de Noé e a Arca

- Mãos com formas e rotações próprias, membros articulados (limbs) e animais.
- Elementos de cenário separados (natureza, construções, interiores) e testes de lugares.
- Personagens reaproveitáveis de Noé e a Arca (Noé, esposa, Sem, Cam e Jafé) e a fonte Barlow Semi Condensed.
- História noe-e-a-arca: pauta, bíblia, roteiro do ep. 1, tomadas Cartoon e montagem.
- Montagem: narração mais corrida (tira silêncios longos) e cabeçalho com o número do vídeo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 01:51:11 -03:00
co-authored by Claude Opus 5.5
parent 3f600c55b1
commit 2d8b1a582d
66 changed files with 19575 additions and 455 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ export function CharacterCard({ figures, background = "#2a2e45", framing = "full
{f.label && <div style={{ marginBottom: "4%" }}><TagLabel text={f.label} size={n > 3 ? 2.2 : 3.4} /></div>}
{framing === "face" ? (
<div style={{ width: "92%", aspectRatio: "1 / 1", overflow: "hidden", position: "relative" }}>
<div style={{ position: "absolute", left: "-60%", top: "-64%", width: "220%", aspectRatio: "200 / 440" }}>
<div style={{ position: "absolute", left: "-15%", top: "-36%", width: "130%", aspectRatio: "200 / 440" }}>
<CharacterFigure look={f.look} expression={f.expression} pose={f.pose} item={f.item} t={frame / fps} />
</div>
</div>
+613 -189
View File
@@ -3,48 +3,92 @@
// viewBox 200×440, pés em (100, 440). O movimento (andar, pular, falar…) vem de motion.ts como `state`; sem ele,
// usa a expressão/pose pedida com a "vida" (piscar, respirar). Posição, giro e espelho ficam por conta de quem
// desenha a cena (Shot.tsx).
//
// Acabamento de ilustração (v2): cabeça grande (~1/3 da altura), tronco em "pera" com ombros redondos, membros
// afinando na ponta, SOMBREADO CEL em 2 tons em tudo (luz de um lado só, `shadeSide`), sem contorno preto (a borda
// é o tom escuro da própria cor), sobrancelha como forma, nariz de traço, pálpebra pesada, mãos com dedos que
// seguram o objeto por cima, roupa com gola/zíper/botões/dobras/barra e sapato com volume.
import React, { useId } from "react";
import { Icon } from "./icons";
import type { IconId } from "./spec";
import { DEFAULT_LOOK, type CharacterLook } from "./character";
import { evaluate, type ActorState } from "./motion";
import type { BodyParams, FaceParams, Limb } from "./rig";
import { POSE_PRESETS, type BodyParams, type FaceParams, type Limb } from "./rig";
import { armLayer } from "./limbs";
import { GRIP, HandArt, TWO_HANDED, handPlacement, wristForHold, type HandShape } from "./hands";
const INK = "#15161f";
const INK = "#1d1a22";
/** Escala da cabeça sobre o desenho-base da cabeça (centro (100,106), queixo em y 156). */
const HEAD_SCALE = 1.2;
function shade(hex: string, k: number): string {
export function shade(hex: string, k: number): string {
const n = parseInt(hex.slice(1), 16);
const c = (v: number) => Math.max(0, Math.min(255, Math.round(v * k))).toString(16).padStart(2, "0");
return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`;
}
/** Sombra com um pouco de azul (sombra fria sob luz quente, como na ilustração). */
function cool(hex: string, k = 0.78): string {
const n = parseInt(hex.slice(1), 16);
const r = ((n >> 16) & 255) * k * 0.94, g = ((n >> 8) & 255) * k * 0.97, b = (n & 255) * k + 10;
const c = (v: number) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0");
return `#${c(r)}${c(g)}${c(b)}`;
}
/** Ponta de um segmento: ângulo de tela em graus (0 = para baixo). */
const tip = (x: number, y: number, deg: number, len: number) => {
const r = (deg * Math.PI) / 180;
return { x: x - Math.sin(r) * len, y: y + Math.cos(r) * len };
};
function Segment({ x, y, deg, len, w, fill }: { x: number; y: number; deg: number; len: number; w: number; fill: string }) {
return <rect x={x - w / 2} y={y - w / 2} width={w} height={len + w / 2} rx={w / 2} fill={fill} transform={`rotate(${deg} ${x} ${y})`} />;
/**
* Forma com sombra cel: desenha a forma no tom da sombra e por cima a cópia iluminada deslocada para o lado da
* luz, recortada pela própria forma. Sobra um crescente de sombra no lado oposto à luz (e embaixo).
*/
function Cel({ id, d, fill, side, dx = 8, dy = -4, k = 0.8, transform }: { id: string; d: string; fill: string; side: number; dx?: number; dy?: number; k?: number; transform?: string }) {
return (
<g transform={transform}>
<defs><clipPath id={id}><path d={d} /></clipPath></defs>
<g clipPath={`url(#${id})`}>
<path d={d} fill={cool(fill, k)} />
<path d={d} fill={fill} transform={`translate(${-side * dx} ${dy})`} />
</g>
</g>
);
}
function Mouth({ f, uid }: { f: FaceParams; uid: string }) {
const w = 32 * f.mouthWidth * (1 - f.mouthRound * 0.35);
const cy = 137 - f.smile * 6;
/** Membro afinando (ombro→cotovelo, cotovelo→punho, quadril→joelho…), com sombra cel no lado oposto à luz. */
export function Limb2({ id, x, y, deg, len, w1, w2, fill, side }: { id: string; x: number; y: number; deg: number; len: number; w1: number; w2: number; fill: string; side: number }) {
const d = `M${-w1 / 2} 0 L${-w2 / 2} ${len} A${w2 / 2} ${w2 / 2} 0 0 0 ${w2 / 2} ${len} L${w1 / 2} 0 A${w1 / 2} ${w1 / 2} 0 0 0 ${-w1 / 2} 0 Z`;
// A sombra fica do lado da tela oposto à luz; no sistema local do membro esse lado gira junto.
const r = (deg * Math.PI) / 180;
const local = Math.cos(r) >= 0 ? side : -side;
return <Cel id={id} d={d} fill={fill} side={local} dx={w1 * 0.32} dy={0} transform={`translate(${x} ${y}) rotate(${deg})`} />;
}
function Mouth({ f, uid, skin }: { f: FaceParams; uid: string; skin: string }) {
const w = 30 * f.mouthWidth * (1 - f.mouthRound * 0.35);
const cy = 138 - f.smile * 6;
if (f.mouthOpen < 0.06 && f.mouthRound < 0.3) {
return <path d={`M${100 - w / 2} ${cy} Q100 ${137 + f.smile * 12} ${100 + w / 2} ${cy}`} stroke={INK} strokeWidth={5} fill="none" strokeLinecap="round" />;
return (
<g>
<path d={`M${100 - w / 2} ${cy} Q100 ${138 + f.smile * 12} ${100 + w / 2} ${cy}`} stroke={shade(skin, 0.42)} strokeWidth={4.6} fill="none" strokeLinecap="round" />
{/* Lábio de baixo: sombra curta sob a boca. */}
<path d={`M${100 - w * 0.22} ${cy + 7 + f.smile * 5} Q100 ${cy + 10 + f.smile * 6} ${100 + w * 0.22} ${cy + 7 + f.smile * 5}`} stroke={shade(skin, 0.82)} strokeWidth={3} fill="none" strokeLinecap="round" />
</g>
);
}
const open = Math.max(f.mouthOpen, f.mouthRound * 0.25);
// A curva quadrática só chega à metade do ponto de controle: os controles ficam no dobro da abertura desejada.
const up = cy + f.smile * 2 - open * 8 - f.mouthRound * 6;
const low = cy + open * 46 * (1 + f.mouthRound * 0.3) + f.smile * 12;
// A boca aberta (riso, grito) nunca passa do queixo (y ≈ 156): cresce até ali e para.
const low = Math.min(152, cy + open * 44 * (1 + f.mouthRound * 0.3) + f.smile * 12);
const d = `M${100 - w / 2} ${cy} Q100 ${up} ${100 + w / 2} ${cy} Q100 ${low} ${100 - w / 2} ${cy} Z`;
return (
<g>
<defs><clipPath id={`m${uid}`}><path d={d} /></clipPath></defs>
<path d={d} fill={INK} />
<path d={d} fill="#4a1f24" />
<g clipPath={`url(#m${uid})`}>
{f.teeth && open > 0.12 && <rect x={60} y={Math.min(up, cy) - 10} width={80} height={(cy - Math.min(up, cy)) + 10 + (low - cy) * 0.16} fill="#f7f7f2" />}
{open > 0.4 && <ellipse cx={100} cy={cy + (low - cy) * 0.5} rx={w * 0.3} ry={(low - cy) * 0.16} fill="#d9534f" />}
{f.teeth && open > 0.12 && <rect x={60} y={Math.min(up, cy) - 10} width={80} height={(cy - Math.min(up, cy)) + 10 + (low - cy) * 0.16} fill="#f7f4ec" />}
{open > 0.35 && <ellipse cx={100} cy={cy + (low - cy) * 0.55} rx={w * 0.32} ry={(low - cy) * 0.2} fill="#d9606a" />}
</g>
</g>
);
@@ -52,83 +96,129 @@ function Mouth({ f, uid }: { f: FaceParams; uid: string }) {
function Eyes({ f, lid, skin, uid }: { f: FaceParams; lid: number; skin: string; uid: string }) {
const big = Math.max(f.eyeL, f.eyeR);
const r = 10.5 + Math.max(0, big - 1) * 7;
const r = 11 + Math.max(0, big - 1) * 7;
const cover = Math.max(0, Math.min(0.85, lid));
const eye = (x: number, open: number) => {
const lidColor = shade(skin, 0.96);
const crease = shade(skin, 0.7);
const eye = (x: number, open: number, sideSign: number) => {
// Olho de riso: fechado em arco para cima quando quase fechado e sorrindo.
if (open < 0.3 && f.smile > 0.55) return <path key={x} d={`M${x - 10} 110 Q${x} 98 ${x + 10} 110`} stroke={INK} strokeWidth={4.5} fill="none" strokeLinecap="round" />;
if (open < 0.14) return <path key={x} d={`M${x - 10} 108 Q${x} 113 ${x + 10} 108`} stroke={INK} strokeWidth={4} fill="none" strokeLinecap="round" />;
if (open < 0.3 && f.smile > 0.55) return <path key={x} d={`M${x - 11} 110 Q${x} 97 ${x + 11} 110`} stroke={INK} strokeWidth={4.5} fill="none" strokeLinecap="round" />;
if (open < 0.14) return <path key={x} d={`M${x - 11} 108 Q${x} 114 ${x + 11} 108`} stroke={shade(skin, 0.45)} strokeWidth={4} fill="none" strokeLinecap="round" />;
const rx = r * 1.12;
return (
<g key={x} transform={`translate(${x} 108) scale(1 ${Math.min(1.2, open)})`}>
<defs><clipPath id={`e${uid}${x}`}><circle r={r} /></clipPath></defs>
<circle r={r} fill="#ffffff" />
<circle r={Math.max(2.2, 5 * f.pupil)} cx={f.gazeX * 4} cy={f.gazeY * 3 + cover * 3} fill={INK} />
<circle r={1.6} cx={f.gazeX * 4 + 1.8} cy={f.gazeY * 3 - 1.8 + cover * 3} fill="#ffffff" opacity={0.85} />
{cover > 0.02 && (
<g clipPath={`url(#e${uid}${x})`}>
<rect x={-r - 1} y={-r - 1} width={2 * r + 2} height={2 * r * cover + 1} fill={skin} />
<path d={`M${-r} ${-r + 2 * r * cover} Q0 ${-r + 2 * r * cover + 3} ${r} ${-r + 2 * r * cover}`} stroke={shade(skin, 0.6)} strokeWidth={2.6} fill="none" />
</g>
)}
<defs><clipPath id={`e${uid}${x}`}><ellipse rx={rx} ry={r} /></clipPath></defs>
{/* Cavidade: leve sombra ao redor do olho. */}
<ellipse rx={rx + 3} ry={r + 2.5} fill={shade(skin, 0.9)} />
<ellipse rx={rx} ry={r} fill="#fbfaf6" />
<g clipPath={`url(#e${uid}${x})`}>
<ellipse cx={0} cy={-r * 0.55} rx={rx} ry={r * 0.5} fill="#000" opacity={0.07} />
<circle r={Math.max(2.6, 4.6 * f.pupil + 0.6)} cx={f.gazeX * 4.5 + sideSign * 0.6} cy={f.gazeY * 3 + cover * 3.5 + 1} fill="#2a2228" />
<circle r={1.5} cx={f.gazeX * 4.5 + 1.6} cy={f.gazeY * 3 - 1 + cover * 3.5} fill="#ffffff" opacity={0.9} />
{cover > 0.02 && <>
<rect x={-rx - 1} y={-r - 1} width={2 * rx + 2} height={2 * r * cover + 1} fill={lidColor} />
<path d={`M${-rx} ${-r + 2 * r * cover} Q0 ${-r + 2 * r * cover + 3.5} ${rx} ${-r + 2 * r * cover}`} stroke={crease} strokeWidth={3} fill="none" />
</>}
</g>
{/* Dobra da pálpebra acima do olho. */}
<path d={`M${-rx * 0.9} ${-r - 3} Q0 ${-r - 8} ${rx * 0.9} ${-r - 3}`} stroke={crease} strokeWidth={2.2} fill="none" strokeLinecap="round" opacity={0.75} />
</g>
);
};
return <g>{eye(82, f.eyeL)}{eye(118, f.eyeR)}</g>;
return <g>{eye(81, f.eyeL, -1)}{eye(119, f.eyeR, 1)}</g>;
}
/** Sobrancelha como FORMA grossa (afina na ponta de fora), girando pelo rig. */
function Brows({ f, thick, color }: { f: FaceParams; thick: boolean; color: string }) {
return (
<g stroke={color} strokeWidth={thick ? 7 : 4.5} strokeLinecap="round">
<line x1={71} y1={89 + f.browL.y} x2={92} y2={89 + f.browL.y} transform={`rotate(${-f.browL.tilt} 92 ${89 + f.browL.y})`} />
<line x1={108} y1={89 + f.browR.y} x2={129} y2={89 + f.browR.y} transform={`rotate(${f.browR.tilt} 108 ${89 + f.browR.y})`} />
</g>
);
}
function Extras({ f, t }: { f: FaceParams; t: number }) {
const h = thick ? 8 : 5.5;
const brow = (x0: number, x1: number, y: number, tilt: number, pivotX: number, inner: number) => {
// Ponta de dentro (pivô) mais grossa; a de fora afina.
const outer = x0 === pivotX ? x1 : x0;
const d = `M${pivotX} ${y - h * 0.55} Q${(pivotX + outer) / 2} ${y - h * 1.15} ${outer} ${y - h * 0.1} Q${(pivotX + outer) / 2} ${y + h * 0.15} ${pivotX} ${y + h * 0.55} Z`;
return <path d={d} fill={color} transform={`rotate(${inner * tilt} ${pivotX} ${y})`} />;
};
return (
<g>
{f.blush > 0.02 && <><ellipse cx={72} cy={124} rx={11} ry={6} fill="#ff6b8b" opacity={0.55 * f.blush} /><ellipse cx={128} cy={124} rx={11} ry={6} fill="#ff6b8b" opacity={0.55 * f.blush} /></>}
{f.sweat && <path d="M146 74 Q152 86 146 92 Q140 86 146 74 Z" fill="#8fd3ff" stroke="#3a8fd0" strokeWidth={1.5} />}
{f.tears && [78, 122].map((x, i) => {
const k = ((t * 1.4 + i * 0.5) % 1);
return <path key={x} d={`M${x} ${116 + k * 26} q4 6 0 9 q-4 -3 0 -9 Z`} fill="#8fd3ff" opacity={1 - k * 0.6} />;
})}
{f.anger && <g stroke="#e8463d" strokeWidth={4} strokeLinecap="round" fill="none"><path d="M128 62 q6 4 12 0" /><path d="M128 74 q6 -4 12 0" /><path d="M128 62 q-4 6 0 12" /><path d="M140 62 q4 6 0 12" /></g>}
{brow(68, 93, 88 + f.browL.y, f.browL.tilt, 93, -1)}
{brow(107, 132, 88 + f.browR.y, f.browR.tilt, 107, 1)}
</g>
);
}
function Beard({ style, color }: { style: CharacterLook["beard"]["style"]; color: string }) {
function Extras({ f, t, skin }: { f: FaceParams; t: number; skin: string }) {
return (
<g>
{/* Bochechas: rubor leve sempre; mais forte com vergonha. */}
<ellipse cx={72} cy={126} rx={12} ry={7} fill="#e8707a" opacity={0.16 + 0.45 * f.blush} />
<ellipse cx={128} cy={126} rx={12} ry={7} fill="#e8707a" opacity={0.16 + 0.45 * f.blush} />
{f.sweat && <path d="M148 74 Q155 87 148 94 Q141 87 148 74 Z" fill="#9fdcff" />}
{f.tears && [80, 120].map((x, i) => {
const k = ((t * 1.4 + i * 0.5) % 1);
return <path key={x} d={`M${x} ${118 + k * 26} q4 6 0 9 q-4 -3 0 -9 Z`} fill="#9fdcff" opacity={1 - k * 0.6} />;
})}
{f.anger && <g stroke="#e8463d" strokeWidth={4} strokeLinecap="round" fill="none"><path d="M130 60 q6 4 12 0" /><path d="M130 72 q6 -4 12 0" /><path d="M130 60 q-4 6 0 12" /><path d="M142 60 q4 6 0 12" /></g>}
{skin && null}
</g>
);
}
function Beard({ style, color, uid, side }: { style: CharacterLook["beard"]["style"]; color: string; uid: string; side: number }) {
const strands = (d: string) => <path d={d} stroke={shade(color, 1.18)} strokeWidth={2.2} fill="none" strokeLinecap="round" opacity={0.6} />;
switch (style) {
case "full": return <path d="M56 108 Q58 168 100 172 Q142 168 144 108 Q138 128 124 126 Q100 122 76 126 Q62 128 56 108 Z" fill={color} />;
case "stubble": return <path d="M60 116 Q64 162 100 166 Q136 162 140 116 Q130 132 100 128 Q70 132 60 116 Z" fill={color} opacity={0.35} />;
case "goatee": return <path d="M88 150 Q100 168 112 150 Q100 156 88 150 Z" fill={color} />;
case "mustache": return <path d="M76 134 Q80 117 100 121 Q120 117 124 134 Q113 128 100 131 Q87 128 76 134 Z" fill={color} />;
case "full": {
const d = "M54 106 Q56 166 100 174 Q144 166 146 106 Q140 128 125 127 Q100 122 75 127 Q60 128 54 106 Z";
return <g><Cel id={`bd${uid}`} d={d} fill={color} side={side} dx={9} />{strands("M78 150 Q84 162 92 166 M108 166 Q116 162 122 150")}
<path d="M74 136 Q80 118 100 122 Q120 118 126 136 Q113 129 100 132 Q87 129 74 136 Z" fill={shade(color, 0.9)} /></g>;
}
case "stubble": return <path d="M58 116 Q62 164 100 168 Q138 164 142 116 Q130 133 100 129 Q70 133 58 116 Z" fill={color} opacity={0.3} />;
case "goatee": return <g><path d="M86 150 Q100 172 114 150 Q100 157 86 150 Z" fill={color} /><path d="M80 136 Q88 124 100 127 Q112 124 120 136 Q110 131 100 133 Q90 131 80 136 Z" fill={color} /></g>;
case "mustache": return (
<g>
{/* Bigode cheio, com volume (claro em cima, escuro embaixo). */}
<path d="M70 140 Q74 116 100 121 Q126 116 130 140 Q120 131 110 134 Q104 128 100 129 Q96 128 90 134 Q80 131 70 140 Z" fill={color} />
<path d="M72 138 Q80 132 90 134 Q96 128 100 129 Q104 128 110 134 Q120 132 128 138 Q118 137 110 137 Q100 133 90 137 Q80 137 72 138 Z" fill={shade(color, 0.78)} />
{strands("M84 126 L86 131 M96 124 L97 129 M106 124 L105 129 M116 126 L114 131")}
</g>
);
// Barba longa: desce do rosto até o peito em ponta, com fios marcados e bigode por cima.
case "long": {
const d = "M54 104 Q52 152 68 192 Q84 230 100 246 Q116 230 132 192 Q148 152 146 104 Q138 128 124 126 Q100 121 76 126 Q62 128 54 104 Z";
return (
<g>
<Cel id={`bd${uid}`} d={d} fill={color} side={side} dx={12} dy={-2} k={0.84} />
<path d="M80 160 Q84 196 94 222 M100 168 L100 236 M120 160 Q116 196 106 222 M68 140 Q70 170 78 192 M132 140 Q130 170 122 192" stroke={shade(color, 0.82)} strokeWidth={2.6} fill="none" strokeLinecap="round" />
<path d="M72 138 Q80 118 100 122 Q120 118 128 138 Q114 130 100 133 Q86 130 72 138 Z" fill={shade(color, 0.9)} />
</g>
);
}
default: return null;
}
}
function Nose({ kind, skin }: { kind: NonNullable<CharacterLook["nose"]>; skin: string }) {
const dark = shade(skin, 0.72);
/** Nariz: traço curvo simples no tom escuro da pele (padrão, como na ilustração) ou formas cheias. */
function Nose({ kind, skin }: { kind: CharacterLook["nose"]; skin: string }) {
const dark = shade(skin, 0.62);
const shadow = <ellipse cx={101} cy={131} rx={9} ry={3} fill={shade(skin, 0.82)} opacity={0.8} />;
switch (kind) {
case "curve": return <path d="M97 110 Q86 123 95 128 Q101 131 105 126" stroke={dark} strokeWidth={3.6} fill="none" strokeLinecap="round" />;
case "round": return <><circle cx={100} cy={121} r={9} fill={shade(skin, 0.9)} /><circle cx={97} cy={118} r={2.5} fill="#ffffff" opacity={0.35} /></>;
case "long": return <path d="M99 104 L104 126 Q100 131 94 127" stroke={dark} strokeWidth={3.4} fill="none" strokeLinecap="round" strokeLinejoin="round" />;
case "wide": return <><ellipse cx={100} cy={123} rx={11} ry={7} fill={shade(skin, 0.9)} /><circle cx={95} cy={125} r={2} fill={dark} /><circle cx={105} cy={125} r={2} fill={dark} /></>;
default: return <ellipse cx={100} cy={123} rx={6} ry={4.5} fill={shade(skin, 0.86)} />;
case "round": return <>{shadow}<circle cx={100} cy={121} r={10} fill={shade(skin, 0.93)} /><path d="M92 126 Q100 132 108 126" stroke={dark} strokeWidth={2.8} fill="none" strokeLinecap="round" /><circle cx={96} cy={117} r={2.6} fill="#ffffff" opacity={0.35} /></>;
case "long": return <>{shadow}<path d="M98 102 Q104 116 106 126 Q101 132 93 128" stroke={dark} strokeWidth={3.4} fill="none" strokeLinecap="round" strokeLinejoin="round" /></>;
case "wide": return <>{shadow}<path d="M88 126 Q92 116 100 116 Q108 116 112 126 Q106 131 100 129 Q94 131 88 126 Z" fill={shade(skin, 0.92)} /><path d="M89 126 Q94 131 100 129 Q106 131 111 126" stroke={dark} strokeWidth={2.6} fill="none" strokeLinecap="round" /></>;
case "button": return <>{shadow}<path d="M95 124 Q100 128 105 124" stroke={dark} strokeWidth={3} fill="none" strokeLinecap="round" /></>;
default: return <>{shadow}<path d="M99 106 Q89 121 95 127 Q101 131 107 126" stroke={dark} strokeWidth={3.6} fill="none" strokeLinecap="round" /></>;
}
}
function Wrinkles({ k, skin }: { k: number; skin: string }) {
if (k <= 0.05) return null;
const c = shade(skin, 0.78);
const c = shade(skin, 0.8);
return (
<g stroke={c} strokeWidth={3} fill="none" strokeLinecap="round" opacity={Math.min(1, 0.5 + k * 0.5)}>
<path d="M80 72 Q100 66 120 72" />
{k > 0.35 && <path d="M84 80 Q100 75 116 80" />}
{k > 0.5 && <><path d="M62 104 l-6 -3 M62 110 l-7 0" /><path d="M138 104 l6 -3 M138 110 l7 0" /></>}
{k > 0.4 && <><path d="M76 128 Q72 138 76 146" /><path d="M124 128 Q128 138 124 146" /></>}
<g stroke={c} strokeWidth={2.6} fill="none" strokeLinecap="round" opacity={Math.min(0.85, 0.4 + k * 0.4)}>
{/* Testa: arcos suaves no tom da pele. */}
<path d="M78 70 Q100 62 122 70" />
{k > 0.3 && <path d="M83 78 Q100 72 117 78" />}
{k > 0.6 && <path d="M88 63 Q100 58 112 63" />}
{k > 0.5 && <><path d="M60 104 l-6 -3 M60 110 l-7 0" /><path d="M140 104 l6 -3 M140 110 l7 0" /></>}
{k > 0.4 && <><path d="M75 126 Q70 137 75 146" /><path d="M125 126 Q130 137 125 146" /><path d="M74 120 Q81 123 88 121" opacity={0.6} /><path d="M112 121 Q119 123 126 120" opacity={0.6} /></>}
</g>
);
}
@@ -136,225 +226,559 @@ function Wrinkles({ k, skin }: { k: number; skin: string }) {
/** Formato da cabeça (centro (100,106)). */
function headPath(shape: CharacterLook["head"]): string {
switch (shape) {
case "oval": return "M100 54 C126 54 143 76 143 106 C143 140 124 160 100 160 C76 160 57 140 57 106 C57 76 74 54 100 54 Z";
case "square": return "M100 56 C130 56 147 72 147 100 L146 128 C144 150 126 158 100 158 C74 158 56 150 54 128 L53 100 C53 72 70 56 100 56 Z";
case "wide": return "M100 58 C124 58 140 74 143 98 C148 124 140 154 100 158 C60 154 52 124 57 98 C60 74 76 58 100 58 Z";
default: return "M100 56 C126 56 147 78 147 106 C147 134 126 156 100 156 C74 156 53 134 53 106 C53 78 74 56 100 56 Z";
case "oval": return "M100 52 C127 52 144 76 144 106 C144 141 124 162 100 162 C76 162 56 141 56 106 C56 76 73 52 100 52 Z";
case "square": return "M100 54 C131 54 149 71 149 100 L148 128 C146 151 127 160 100 160 C73 160 54 151 52 128 L51 100 C51 71 69 54 100 54 Z";
case "wide": return "M100 56 C128 56 146 72 149 98 C153 128 142 158 100 160 C58 158 47 128 51 98 C54 72 72 56 100 56 Z";
default: return "M100 54 C127 54 148 77 148 106 C148 135 127 158 100 158 C73 158 52 135 52 106 C52 77 73 54 100 54 Z";
}
}
function Glasses({ kind }: { kind: CharacterLook["glasses"] }) {
if (kind === "none") return null;
const frame = kind === "sun" ? "#1c1a20" : "#4a2e1e";
const lens = (x: number) => kind === "square"
? <rect x={x - 17} y={94} width={34} height={28} rx={7} />
: <ellipse cx={x} cy={108} rx={17} ry={15} />;
return (
<g stroke={INK} strokeWidth={4} fill={kind === "sun" ? INK : "none"}>
{kind === "square"
? <><rect x={67} y={95} width={30} height={25} rx={5} /><rect x={103} y={95} width={30} height={25} rx={5} /></>
: <><circle cx={82} cy={108} r={15} /><circle cx={118} cy={108} r={15} /></>}
<line x1={97} y1={107} x2={103} y2={107} />
<line x1={55} y1={104} x2={67} y2={106} /><line x1={133} y1={106} x2={145} y2={104} />
<g>
<g fill={kind === "sun" ? "#1c1a20" : "#ffffff"} opacity={kind === "sun" ? 0.92 : 0.1}>{lens(81)}{lens(119)}</g>
{/* Reflexo diagonal na lente. */}
<g stroke="#ffffff" strokeWidth={3} strokeLinecap="round" opacity={kind === "sun" ? 0.5 : 0.45}><path d="M71 101 L78 96" /><path d="M109 101 L116 96" /></g>
<g stroke={frame} strokeWidth={4.4} fill="none">{lens(81)}{lens(119)}</g>
<path d="M97 106 Q100 103 103 106" stroke={frame} strokeWidth={4} fill="none" />
<path d="M52 103 L64 105 M136 105 L148 103" stroke={frame} strokeWidth={5} strokeLinecap="round" />
</g>
);
}
function HairFront({ look }: { look: CharacterLook }) {
function HairFront({ look, uid, side }: { look: CharacterLook; uid: string; side: number }) {
const c = look.hair.color;
const lite = shade(c, 1.25);
const cel = (d: string, k = 0.78) => <Cel id={`hf${uid}`} d={d} fill={c} side={side} dx={10} dy={4} k={k} />;
switch (look.hair.style) {
case "bald": return <><path d="M53 112 Q50 86 62 80 L62 112 Z" fill={c} /><path d="M147 112 Q150 86 138 80 L138 112 Z" fill={c} /></>;
case "short": return <path d="M53 104 Q52 50 100 50 Q148 50 147 104 Q140 76 100 74 Q60 76 53 104 Z" fill={c} />;
case "side": return <path d="M53 106 Q50 48 104 50 Q150 54 147 104 Q134 70 92 80 Q66 86 53 106 Z" fill={c} />;
case "bun": return <><circle cx={100} cy={46} r={20} fill={c} /><path d="M53 104 Q52 52 100 52 Q148 52 147 104 Q138 74 100 72 Q62 74 53 104 Z" fill={c} /></>;
case "long": return <path d="M53 108 Q50 50 100 50 Q150 50 147 108 Q136 72 100 70 Q64 72 53 108 Z" fill={c} />;
case "curly": return <g fill={c}>{[[60, 84], [72, 64], [90, 54], [110, 54], [128, 64], [140, 84], [100, 62], [80, 74], [120, 74]].map(([x, y], i) => <circle key={i} cx={x} cy={y} r={15} />)}</g>;
case "spiky": return <path d="M54 102 L58 66 L72 76 L80 48 L94 70 L104 44 L114 70 L128 50 L132 76 L146 66 L146 102 Q130 80 100 80 Q70 80 54 102 Z" fill={c} />;
case "cap": return <><path d="M54 96 Q54 50 100 50 Q146 50 146 96 Z" fill={c} /><path d="M120 92 Q160 92 172 100 L120 102 Z" fill={shade(c, 0.8)} /></>;
case "bald": return <>{cel("M50 100 Q46 78 64 68 Q72 82 62 100 Z M150 100 Q154 78 136 68 Q128 82 138 100 Z")}</>;
case "short": return <>{cel("M51 104 Q50 48 100 48 Q150 48 149 104 Q141 74 100 72 Q59 74 51 104 Z")}<path d="M70 62 Q86 56 100 58 M110 56 Q124 58 134 66" stroke={lite} strokeWidth={3} fill="none" strokeLinecap="round" opacity={0.6} /></>;
case "side": return <>{cel("M51 106 Q48 46 104 48 Q152 52 149 104 Q134 68 92 78 Q64 86 51 106 Z")}<path d="M74 70 Q92 60 120 60" stroke={lite} strokeWidth={3} fill="none" strokeLinecap="round" opacity={0.6} /></>;
case "bun": return <><circle cx={100} cy={42} r={21} fill={shade(c, 0.9)} />{cel("M51 104 Q50 50 100 50 Q150 50 149 104 Q139 72 100 70 Q61 72 51 104 Z")}</>;
case "long": return <>{cel("M51 110 Q48 48 100 48 Q152 48 149 110 Q137 70 100 68 Q63 70 51 110 Z")}<path d="M72 64 Q88 56 104 58" stroke={lite} strokeWidth={3} fill="none" strokeLinecap="round" opacity={0.55} /></>;
case "curly": return <g>{[[58, 86], [70, 64], [89, 52], [111, 52], [130, 64], [142, 86], [100, 62], [79, 74], [121, 74]].map(([x, y], i) => <g key={i}><circle cx={x} cy={y} r={16} fill={shade(c, 0.8)} /><circle cx={x - 3} cy={y - 3} r={12} fill={c} /></g>)}</g>;
case "spiky": return cel("M52 102 L56 64 L71 75 L79 46 L94 69 L104 42 L115 69 L129 48 L133 75 L148 64 L148 102 Q130 79 100 79 Q70 79 52 102 Z");
case "cap": return <><Cel id={`hf${uid}`} d="M52 96 Q52 46 100 46 Q148 46 148 96 Z" fill={c} side={side} dx={10} dy={4} /><path d="M118 92 Q162 90 176 100 L118 103 Z" fill={shade(c, 0.78)} /><circle cx={100} cy={47} r={4} fill={shade(c, 0.7)} /></>;
default: return null;
}
}
/** Cabeça inteira no sistema antigo (centro ~ (100,106)); `turn` desloca o rosto para fingir 3/4, `nod` sobe/desce. */
function Head({ look, f, b, t, uid }: { look: CharacterLook; f: FaceParams; b: BodyParams; t: number; uid: string }) {
const fx = b.headTurn * 9;
const fy = b.headNod * 6;
/** Cabeça inteira no sistema de 200×440 (centro ~ (100,106)); `turn` desloca o rosto para fingir 3/4, `nod` sobe/desce. */
function Head({ look, f, b, t, uid, side }: { look: CharacterLook; f: FaceParams; b: BodyParams; t: number; uid: string; side: number }) {
// Girar/acenar a cabeça: o rosto anda pouco e o contorno da cabeça acompanha um pouco (senão o rosto parece um
// adesivo descolando). Barba e bigode ficam presos ao queixo (andam junto com o contorno, não com os olhos).
const fx = b.headTurn * 6;
const fy = b.headNod * 4;
const hx = fx * 0.35;
const browColor = look.hair.style === "bald" || look.hair.style === "cap" ? look.beard.color : look.hair.color;
const skinDark = shade(look.skin, 0.72);
return (
<g>
{[53, 147].map((x, i) => (
{[52, 148].map((x, i) => (
<g key={x} transform={`translate(${x + b.headTurn * 7} 112) scale(${1 - (i === 0 ? Math.max(0, b.headTurn) : -Math.min(0, b.headTurn)) * 0.5} 1)`}>
<ellipse rx={9} ry={12} fill={shade(look.skin, 0.94)} />
<path d={i === 0 ? "M3 -6 Q-4 0 3 6" : "M-3 -6 Q4 0 -3 6"} stroke={shade(look.skin, 0.72)} strokeWidth={2.4} fill="none" strokeLinecap="round" />
<ellipse rx={11} ry={15} fill={(i === 0 ? -1 : 1) === side ? cool(look.skin, 0.86) : look.skin} />
{/* Dobra interna da orelha em tom escuro. */}
<path d={i === 0 ? "M4 -8 Q-5 -2 1 4 Q5 7 2 10" : "M-4 -8 Q5 -2 -1 4 Q-5 7 -2 10"} stroke={skinDark} strokeWidth={3} fill="none" strokeLinecap="round" />
</g>
))}
<defs><clipPath id={`h${uid}`}><path d={headPath(look.head)} /></clipPath></defs>
<path d={headPath(look.head)} fill={look.skin} />
{/* Sombra suave do lado de baixo/direito e brilho na testa: volume de ilustração. */}
<g clipPath={`url(#h${uid})`}>
<ellipse cx={128} cy={140} rx={44} ry={34} fill={shade(look.skin, 0.86)} opacity={0.55} />
<ellipse cx={86} cy={72} rx={22} ry={12} fill="#ffffff" opacity={0.12} />
<g transform={`translate(${hx} 0)`}>
<Cel id={`hd${uid}`} d={headPath(look.head)} fill={look.skin} side={side} dx={14} dy={-8} k={0.8} />
{/* Brilho suave na testa (lado da luz). */}
<ellipse cx={100 - side * 16} cy={72} rx={20} ry={11} fill="#ffffff" opacity={0.1} />
</g>
<g transform={`translate(${fx} ${fy})`}>
<Wrinkles k={look.wrinkles ?? 0} skin={look.skin} />
<Beard style={look.beard.style} color={look.beard.color} />
<Extras f={f} t={t} />
<Extras f={f} t={t} skin={look.skin} />
</g>
{/* Barba presa ao queixo: segue o contorno da cabeça e só um pouco o aceno. */}
<g transform={`translate(${hx} ${fy * 0.4})`}>
<Beard style={look.beard.style} color={look.beard.color} uid={uid} side={side} />
</g>
<g transform={`translate(${fx} ${fy})`}>
<Eyes f={f} lid={(look.lids ?? 0) + f.lid} skin={look.skin} uid={uid} />
{look.nose && <Nose kind={look.nose} skin={look.skin} />}
<Nose kind={look.nose} skin={look.skin} />
<Brows f={f} thick={look.brows === "thick"} color={browColor} />
<Glasses kind={look.glasses} />
<Mouth f={f} uid={uid} />
<Mouth f={f} uid={uid} skin={look.skin} />
{(look.beard.style === "full" || look.beard.style === "long") && <path d="M74 136 Q80 118 100 122 Q120 118 126 136 Q113 129 100 132 Q87 129 74 136 Z" fill={shade(look.beard.color, 0.9)} opacity={0} />}
</g>
<g transform={`translate(${fx * 0.4} 0)`}><HairFront look={look} /></g>
<g transform={`translate(${fx * 0.4} 0)`}><HairFront look={look} uid={uid} side={side} /></g>
{look.accessories?.includes("helmet") && (
<g transform={`translate(${fx * 0.4} 0)`}>
<path d="M50 92 Q50 42 100 42 Q150 42 150 92 Z" fill={look.accessoryColor ?? "#f2c230"} />
<rect x={42} y={88} width={116} height={10} rx={5} fill={shade(look.accessoryColor ?? "#f2c230", 0.85)} />
<path d="M100 44 L100 90" stroke={shade(look.accessoryColor ?? "#f2c230", 0.85)} strokeWidth={6} />
<Cel id={`hm${uid}`} d="M48 92 Q48 38 100 38 Q152 38 152 92 Z" fill={look.accessoryColor ?? "#f2c230"} side={side} dx={12} dy={4} />
<rect x={40} y={88} width={120} height={11} rx={5} fill={shade(look.accessoryColor ?? "#f2c230", 0.82)} />
<path d="M100 40 L100 90" stroke={shade(look.accessoryColor ?? "#f2c230", 0.85)} strokeWidth={8} />
<ellipse cx={78} cy={56} rx={12} ry={6} fill="#ffffff" opacity={0.3} />
</g>
)}
{look.accessories?.includes("headset") && (
<g><path d="M52 100 Q52 44 100 44 Q148 44 148 100" stroke={INK} strokeWidth={6} fill="none" /><rect x={142} y={96} width={14} height={26} rx={6} fill={INK} /><path d="M150 120 Q140 142 116 140" stroke={INK} strokeWidth={3} fill="none" /></g>
<g><path d="M50 100 Q50 42 100 42 Q150 42 150 100" stroke={INK} strokeWidth={6} fill="none" /><rect x={144} y={96} width={14} height={26} rx={6} fill={INK} /><path d="M152 120 Q142 142 116 140" stroke={INK} strokeWidth={3} fill="none" /></g>
)}
</g>
);
}
/** Acessórios por cima da roupa (combináveis). Capacete e fone são desenhados na cabeça. */
function Accessories({ look, x0, x1, top, bottom, hipY }: { look: CharacterLook; x0: number; x1: number; top: number; bottom: number; hipY: number }) {
const acc = look.accessories ?? [];
const c = look.accessoryColor;
/**
* Mão: escolhe a forma desenhada da biblioteca (hands.tsx) pelo estado — gesto, apontar, pegada de borda, punho
* segurando, mão no rosto, braço erguido (aberta) ou caída — e a põe no pulso (x, y) com o giro do antebraço (`deg`).
* `scale` = escala do desenho de 120×120. `layer`: com objeto, "back" = atrás dele e "front" = na frente.
*/
function Hand({ x, y, deg, s, skin, curl, point, gesture, scale = 1, uid, light = 1, layer = "all", thumbFront, onFace }: {
x: number; y: number; deg: number; s: number; skin: string; curl: number; point?: boolean; gesture?: "thumbs_up";
scale?: number; uid: string; light?: number; layer?: "all" | "back" | "front";
/** Pegada de borda (objeto largo, em par): dedos atrás do objeto e só o polegar por cima dele. */
thumbFront?: boolean;
/** Mão apoiada no rosto (queixo, boca, testa). */
onFace?: boolean;
}) {
const raised = Math.cos((deg * Math.PI) / 180) < -0.2;
// Joinha só com o antebraço perto do ângulo para o qual o desenho foi feito (subindo na diagonal); fora disso,
// o polegar apontaria para o lado: vira punho fechado.
const thumbOk = Math.abs(((deg - 135 * (s >= 0 ? 1 : -1) + 540) % 360) - 180) <= 70;
const shape: HandShape = gesture === "thumbs_up" ? (thumbOk ? "thumbs_up" : "fist") : point ? "point" : thumbFront ? (raised ? "pinch_low" : "pinch_edge")
: curl >= 0.6 ? "grip" : onFace ? "on_face" : raised ? "open" : "relaxed";
return <HandArt shape={shape} x={x} y={y} foreDeg={deg} s={s} k={scale} skin={skin} light={light} layer={layer} uid={uid} />;
}
/**
* Fim da manga: barra (punho) com espessura e dobra, a abertura escura por dentro e o pulso saindo DE DENTRO dela,
* com a sombra da manga caindo sobre a pele. Eixo local: (x, y) = borda da manga, +y = para fora (para a mão).
* `w` = largura da manga na borda. Sem `cuff` (manga curta), a barra fica no tom escuro do pano.
*/
export function SleeveEnd({ x, y, deg, w, cloth, cuff, skin, wrist, light, uid, scale = 1, part = "all" }: {
x: number; y: number; deg: number; w: number; cloth: string; cuff?: string; skin: string; wrist: number; light: number; uid: string; scale?: number;
/** "back" = abertura escura (e o pulso, se `wrist` > 0), antes da mão; "front" = sombra no pulso e barra, depois. */
part?: "all" | "back" | "front";
}) {
const up = Math.cos((deg * Math.PI) / 180) >= 0;
const band = cuff ?? shade(cloth, 0.86);
const h = cuff ? 7.5 : 5;
return (
<g>
{acc.includes("vest") && <>
<path d={`M${x0 + 2} ${top + 8} L${x0 + 30} ${top + 4} L${x0 + 30} ${bottom} L${x0 + 2} ${bottom} Z`} fill={c ?? "#ff8a2a"} />
<path d={`M${x1 - 2} ${top + 8} L${x1 - 30} ${top + 4} L${x1 - 30} ${bottom} L${x1 - 2} ${bottom} Z`} fill={c ?? "#ff8a2a"} />
<rect x={x0 + 2} y={hipY - 70} width={x1 - x0 - 4} height={8} fill="#d9dde3" opacity={0.95} />
<rect x={x0 + 2} y={hipY - 40} width={x1 - x0 - 4} height={8} fill="#d9dde3" opacity={0.95} />
<g transform={`translate(${x} ${y}) rotate(${deg}) scale(${scale})`}>
{/* Abertura da manga (o escuro de dentro) e o pulso saindo dela. */}
{part !== "front" && <>
<ellipse cx={0} cy={0} rx={w * 0.5} ry={w * 0.17} fill={shade(cloth, 0.32)} />
{wrist > 0 && <rect x={-wrist / 2} y={-1.5} width={wrist} height={7} fill={skin} />}
</>}
{part !== "back" && <>
{/* Sombra da manga caindo no pulso e a barra do punho por cima da sobra do pulso. */}
<path d={`M${-8.6} -1.5 L${8.6} -1.5 L${8.6} 2.2 Q0 4.4 ${-8.6} 2.2 Z`} fill={cool(skin, 0.72)} opacity={0.9} />
<Cel id={`cf${uid}`} d={`M${-w / 2} ${-h} L${w / 2} ${-h} Q${w / 2 + 1} 0 ${w / 2} 0.6 Q0 2.4 ${-w / 2} 0.6 Q${-w / 2 - 1} 0 ${-w / 2} ${-h} Z`}
fill={band} side={up ? light : -light} dx={w * 0.22} dy={0} k={0.8} />
<path d={`M${-w / 2 + 1.5} ${-h + 2.2} Q0 ${-h + 3.6} ${w / 2 - 1.5} ${-h + 2.2}`} stroke={shade(band, 0.78)} strokeWidth={1.2} fill="none" strokeLinecap="round" />
</>}
{acc.includes("apron") && <path d={`M${x0 + 10} ${top + 30} L${x1 - 10} ${top + 30} L${x1 - 4} ${hipY + 70} L${x0 + 4} ${hipY + 70} Z`} fill={c ?? "#e9ecef"} />}
{acc.includes("tie") && <><path d={`M95 ${top + 4} L105 ${top + 4} L102 ${top + 14} L98 ${top + 14} Z`} fill={c ?? "#2b3a67"} /><path d={`M98 ${top + 14} L102 ${top + 14} L108 ${top + 80} L100 ${top + 92} L92 ${top + 80} Z`} fill={c ?? "#2b3a67"} /></>}
{acc.includes("scarf") && <><rect x={82} y={top - 6} width={36} height={16} rx={7} fill={c ?? "#c8443a"} /><rect x={104} y={top + 6} width={12} height={40} rx={5} fill={c ?? "#c8443a"} /></>}
{acc.includes("whistle") && <><path d={`M86 ${top + 4} L100 ${top + 52} L114 ${top + 4}`} stroke="#e8463d" strokeWidth={2.5} fill="none" /><rect x={94} y={top + 50} width={14} height={9} rx={4} fill="#c0c4cc" /></>}
{acc.includes("chain") && <path d={`M84 ${top + 4} Q100 ${top + 48} 116 ${top + 4}`} stroke="#d4a63a" strokeWidth={3.5} fill="none" strokeDasharray="4 2" />}
{acc.includes("badge") && <rect x={x0 + 14} y={top + 26} width={18} height={12} rx={2} fill={c ?? "#d4a63a"} />}
{acc.includes("towel") && <path d={`M${x1 - 26} ${top - 4} Q${x1 - 6} ${top - 6} ${x1 - 4} ${top + 12} L${x1 - 10} ${hipY - 20} L${x1 - 34} ${hipY - 24} L${x1 - 36} ${top + 6} Z`} fill={c ?? "#efe6d2"} stroke={shade(c ?? "#efe6d2", 0.85)} strokeWidth={2} />}
</g>
);
}
export function CharacterFigure({ look = DEFAULT_LOOK, expression, pose, item, t = 0, state }: {
/**
* Acessórios em camadas: "torso" = parte da roupa (colete, avental), por baixo de qualquer braço; "chest" = sobre o
* peito (toalha, cachecol, gravata, apito, corrente, crachá), entre o braço ao lado do corpo e o braço na frente do
* peito; "drape" = o pano da toalha apoiado no ombro, sempre por cima da raiz do braço daquele lado.
*/
function Accessories({ look, x0, x1, top, bottom, hipY, side, part, uid }: { look: CharacterLook; x0: number; x1: number; top: number; bottom: number; hipY: number; side: number; part: "torso" | "chest" | "drape"; uid: string }) {
const acc = look.accessories ?? [];
const c = look.accessoryColor;
if (part === "drape") return acc.includes("towel") ? <TowelDrape x1={x1} top={top} color={c ?? "#efe8d6"} side={side} uid={uid} /> : null;
if (part === "chest") {
return (
<g>
{acc.includes("tie") && <><path d={`M95 ${top + 6} L105 ${top + 6} L102 ${top + 16} L98 ${top + 16} Z`} fill={c ?? "#2b3a67"} /><path d={`M98 ${top + 16} L102 ${top + 16} L109 ${top + 82} L100 ${top + 94} L91 ${top + 82} Z`} fill={c ?? "#2b3a67"} /><path d={`M100 ${top + 16} L100 ${top + 92}`} stroke={shade(c ?? "#2b3a67", 0.75)} strokeWidth={2} /></>}
{acc.includes("scarf") && <><rect x={78} y={top - 6} width={44} height={18} rx={8} fill={c ?? "#c8443a"} /><rect x={106} y={top + 8} width={13} height={44} rx={5} fill={shade(c ?? "#c8443a", 0.85)} /></>}
{acc.includes("whistle") && <><path d={`M86 ${top + 4} L100 ${top + 54} L114 ${top + 4}`} stroke="#e8463d" strokeWidth={2.8} fill="none" /><rect x={93} y={top + 52} width={16} height={10} rx={4} fill="#c0c4cc" /><rect x={93} y={top + 52} width={16} height={4} rx={2} fill="#ffffff" opacity={0.5} /></>}
{acc.includes("chain") && <path d={`M84 ${top + 4} Q100 ${top + 48} 116 ${top + 4}`} stroke="#d4a63a" strokeWidth={3.5} fill="none" strokeDasharray="4 2" />}
{acc.includes("badge") && <><rect x={x0 + 16} y={top + 28} width={20} height={14} rx={2} fill={c ?? "#d4a63a"} /><rect x={x0 + 19} y={top + 31} width={8} height={8} rx={1} fill="#ffffff" opacity={0.6} /></>}
{acc.includes("towel") && <TowelBody x1={x1} top={top} hipY={hipY} color={c ?? "#efe8d6"} side={side} uid={uid} />}
</g>
);
}
return (
<g>
{acc.includes("vest") && <>
<path d={`M${x0 + 4} ${top + 12} L${x0 + 32} ${top + 6} L${x0 + 30} ${bottom} L${x0 + 6} ${bottom} Z`} fill={c ?? "#ff8a2a"} />
<path d={`M${x1 - 4} ${top + 12} L${x1 - 32} ${top + 6} L${x1 - 30} ${bottom} L${x1 - 6} ${bottom} Z`} fill={shade(c ?? "#ff8a2a", side > 0 ? 0.82 : 1)} />
<rect x={x0 + 4} y={hipY - 66} width={28} height={9} fill="#e3e6ea" /><rect x={x1 - 32} y={hipY - 66} width={28} height={9} fill="#cfd3d8" />
<rect x={x0 + 4} y={hipY - 36} width={28} height={9} fill="#e3e6ea" /><rect x={x1 - 32} y={hipY - 36} width={28} height={9} fill="#cfd3d8" />
</>}
{acc.includes("apron") && <path d={`M${x0 + 14} ${top + 34} L${x1 - 14} ${top + 34} L${x1 - 6} ${hipY + 70} L${x0 + 6} ${hipY + 70} Z`} fill={c ?? "#eceae3"} />}
</g>
);
}
/**
* Toalha no ombro, parte de baixo: pano largo caindo pela frente do peito, com volume (sombra cel), dobras, listras
* e franja na ponta, e a sombra que ela faz no casaco.
*/
function TowelBody({ x1, top, hipY, color, side, uid }: { x1: number; top: number; hipY: number; color: string; side: number; uid: string }) {
const end = hipY - 18;
const d = `M${x1 - 47} ${top + 6} C${x1 - 44} ${top + 40} ${x1 - 49} ${end - 30} ${x1 - 47} ${end} L${x1 - 9} ${end + 4} C${x1 - 8} ${end - 30} ${x1 - 4} ${top + 40} ${x1 - 6} ${top + 10} Z`;
const stripe = shade(color, 0.72);
return (
<g>
{/* Sombra do pano no casaco (lado de dentro). */}
<path d={`M${x1 - 47} ${top + 10} C${x1 - 44} ${top + 40} ${x1 - 49} ${end - 30} ${x1 - 47} ${end} L${x1 - 53} ${end - 2} C${x1 - 54} ${end - 30} ${x1 - 50} ${top + 40} ${x1 - 52} ${top + 12} Z`} fill="#000000" opacity={0.16} />
<Cel id={`tw${uid}`} d={d} fill={color} side={side} dx={9} dy={0} k={0.82} />
{/* Dobras verticais do pano. */}
<path d={`M${x1 - 33} ${top + 16} C${x1 - 31} ${top + 50} ${x1 - 35} ${end - 30} ${x1 - 33} ${end - 6} M${x1 - 20} ${top + 18} C${x1 - 18} ${top + 52} ${x1 - 22} ${end - 30} ${x1 - 20} ${end - 4}`} stroke={shade(color, 0.86)} strokeWidth={2.4} fill="none" strokeLinecap="round" />
{/* Duas listras perto da ponta e a franja. */}
<path d={`M${x1 - 47.5} ${end - 22} L${x1 - 8.5} ${end - 18} M${x1 - 47.5} ${end - 13} L${x1 - 8.5} ${end - 9}`} stroke={stripe} strokeWidth={3.2} />
<path d={Array.from({ length: 7 }, (_, i) => { const x = x1 - 45 + i * 5.6; const y = end + 0.6 + i * 0.6; return `M${x} ${y} L${x - 0.6} ${y + 5}`; }).join(" ")} stroke={shade(color, 0.8)} strokeWidth={2} strokeLinecap="round" />
</g>
);
}
/** Toalha no ombro, parte de cima: a dobra arredondada sobre o ombro, por cima da raiz do braço. */
function TowelDrape({ x1, top, color, side, uid }: { x1: number; top: number; color: string; side: number; uid: string }) {
// Pano dobrado deitado sobre o ombro (segue a linha do ombro, não sobe no pescoço) e caindo um pouco para trás.
const d = `M${x1 - 48} ${top + 10} C${x1 - 44} ${top - 4} ${x1 - 16} ${top - 9} ${x1 + 4} ${top - 4} C${x1 + 14} ${top} ${x1 + 17} ${top + 12} ${x1 + 13} ${top + 24}`
+ ` C${x1 + 9} ${top + 29} ${x1 + 2} ${top + 27} ${x1} ${top + 20} C${x1 - 6} ${top + 8} ${x1 - 28} ${top + 6} ${x1 - 48} ${top + 16} Z`;
return (
<g>
<Cel id={`td${uid}`} d={d} fill={shade(color, 1.03)} side={side} dx={6} dy={-2} k={0.8} />
{/* Dobra do pano por cima do ombro e a borda de baixo que cai para trás. */}
<path d={`M${x1 - 40} ${top + 7} C${x1 - 28} ${top - 1} ${x1 - 8} ${top - 3} ${x1 + 6} ${top + 5}`} stroke={shade(color, 0.84)} strokeWidth={2} fill="none" strokeLinecap="round" />
<path d={`M${x1 + 13} ${top + 24} C${x1 + 9} ${top + 29} ${x1 + 2} ${top + 27} ${x1} ${top + 20}`} stroke={shade(color, 0.7)} strokeWidth={2} fill="none" strokeLinecap="round" />
</g>
);
}
export function CharacterFigure({ look = DEFAULT_LOOK, expression, pose, item, t = 0, state, shadeSide = 1, gesture }: {
look?: CharacterLook; expression?: string; pose?: string; item?: IconId; t?: number;
/** Gesto da mão direita quando ela não segura nem aponta ("thumbs_up" = polegar para cima). */
gesture?: "thumbs_up";
/** Estado calculado pela linha do tempo (motion.ts). Sem ele: expressão/pose pedidas + piscar/respirar. */
state?: Pick<ActorState, "face" | "body" | "emote">;
/** Lado da sombra no desenho (1 = direita, -1 = esquerda). Quem espelha o personagem inverte para a luz ficar
* do mesmo lado da cena. */
shadeSide?: 1 | -1;
}) {
const uid = useId().replace(/:/g, "");
const st = state ?? evaluate({ x: 0, expression, pose }, t, 3600, 1);
const f = st.face;
const b = st.body;
const w = look.build === "slim" ? 0.86 : look.build === "heavy" ? 1.22 : 1;
// Objeto largo (livro, tábua) vai nas DUAS mãos: os dois braços vão para a pose de segurar pelas bordas.
const twoHanded = !!item && TWO_HANDED.includes(item) && (st.body.armR.raise > 20 || st.body.armR.bend > 40);
const b: BodyParams = twoHanded ? { ...st.body, armL: { ...POSE_PRESETS.hold_both.arms }, armR: { ...POSE_PRESETS.hold_both.arms } } : st.body;
const gest = gesture ?? (pose === "thumbs_up" ? "thumbs_up" : undefined);
/** Escala do desenho da mão (quadro 120×120): mão ≈ do nariz ao queixo. */
const HAND_K = 0.62;
const side = shadeSide;
const w = look.build === "slim" ? 0.86 : look.build === "heavy" ? 1.2 : 1;
const breathe = Math.sin(t * 2.2) * 1.4;
const top = look.top;
// Quadril desce ao sentar; coxas abrem e encurtam (perspectiva), canelas voltam para baixo.
const hipY = 290 + b.crouch * 62;
const legW = 20 * w;
const pants = look.top.style === "dress" || look.bottom.style !== "pants" ? look.skin : look.bottom.color;
const hipY = 306 + b.crouch * 56;
const legW = 30 * w;
const longTop = top.style === "dress" || top.style === "robe";
const pants = longTop || look.bottom.style !== "pants" ? look.skin : look.bottom.color;
const footwear = look.footwear ?? "shoes";
const thighLen = 62 * (1 - 0.72 * b.crouch);
const leg = (s: 1 | -1, l: Limb) => {
const hx = 100 + s * 20 * w;
const hx = 100 + s * 24 * w;
const thighDeg = -s * (l.raise + b.crouch * 55);
const knee = tip(hx, hipY, thighDeg, 72 * (1 - 0.72 * b.crouch));
const knee = tip(hx, hipY, thighDeg, thighLen);
const shinDeg = thighDeg + s * (l.bend + b.crouch * 55);
const foot = tip(knee.x, knee.y, shinDeg, 68);
const shorts = look.bottom.style === "shorts" && look.top.style !== "dress";
const foot = tip(knee.x, knee.y, shinDeg, 58);
const shorts = look.bottom.style === "shorts" && !longTop;
const fw = legW + 14;
const fy = foot.y + 2;
return (
<g key={s}>
<Segment x={hx} y={hipY} deg={thighDeg} len={72 * (1 - 0.72 * b.crouch)} w={legW} fill={shorts ? look.bottom.color : pants} />
<Segment x={knee.x} y={knee.y} deg={shinDeg} len={68} w={legW * 0.95} fill={pants} />
<rect x={foot.x - legW * 0.5 - (s < 0 ? 6 : 0)} y={foot.y - 8} width={legW + 10} height={16} rx={7} fill={look.shoes} />
<Limb2 id={`th${uid}${s}`} x={hx} y={hipY} deg={thighDeg} len={thighLen} w1={legW + 4} w2={legW * 0.92} fill={shorts ? look.bottom.color : pants} side={side} />
<Limb2 id={`sh${uid}${s}`} x={knee.x} y={knee.y} deg={shinDeg} len={58} w1={legW * 0.92} w2={legW * 0.78} fill={pants} side={side} />
{/* Barra da calça. */}
{pants !== look.skin && <rect x={foot.x - legW * 0.48} y={foot.y - 9} width={legW * 0.96} height={6} rx={3} fill={shade(pants, 0.8)} />}
{footwear === "shoes" && <>
<path d={`M${foot.x - fw / 2} ${fy + 6} Q${foot.x - fw / 2} ${fy - 12} ${foot.x} ${fy - 12} Q${foot.x + fw / 2} ${fy - 12} ${foot.x + fw / 2} ${fy + 6} Z`} fill={look.shoes} />
<rect x={foot.x - fw / 2 - 1} y={fy + 3} width={fw + 2} height={6} rx={3} fill={shade(look.shoes, look.shoes === "#f2f2f2" ? 0.8 : 0.6)} />
<ellipse cx={foot.x - side * 4} cy={fy - 6} rx={fw * 0.2} ry={3} fill="#ffffff" opacity={0.22} />
</>}
{footwear !== "shoes" && <path d={`M${foot.x - fw / 2 + 3} ${fy + 6} Q${foot.x - fw / 2 + 3} ${fy - 10} ${foot.x} ${fy - 10} Q${foot.x + fw / 2 - 3} ${fy - 10} ${foot.x + fw / 2 - 3} ${fy + 6} Z`} fill={shade(look.skin, 0.95)} />}
{/* Sandália: sola fina e duas tiras cruzando o peito do pé. */}
{footwear === "sandals" && <>
<rect x={foot.x - fw / 2 + 1} y={fy + 3} width={fw - 2} height={6} rx={3} fill={look.shoes} />
<path d={`M${foot.x - fw / 2 + 6} ${fy - 6} L${foot.x + fw / 2 - 6} ${fy + 3} M${foot.x + fw / 2 - 6} ${fy - 6} L${foot.x - fw / 2 + 6} ${fy + 3}`} stroke={look.shoes} strokeWidth={3.6} strokeLinecap="round" />
</>}
</g>
);
};
const sx = 34 * w;
const shY = hipY - 122;
const longSleeve = ["jacket", "hoodie", "uniform"].includes(look.top.style);
const sleeve = look.top.style === "dress" ? look.skin : look.top.color;
const arm = (s: 1 | -1, l: Limb, holds?: IconId) => {
const x = 100 + s * sx;
const shY = hipY - 100;
const torsoTop = hipY - 114;
const longSleeve = ["jacket", "hoodie", "uniform", "robe"].includes(top.style);
const sleeve = top.style === "dress" ? look.skin : top.color;
const holdItem = !twoHanded && (b.armR.raise > 20 || b.armR.bend > 40) ? item : undefined;
const arm = (s: 1 | -1, l: Limb, holds?: IconId, part: "all" | "upper" | "lower" = "all") => {
const x = 100 + s * 54 * w;
const upperDeg = -s * l.raise;
const elbow = tip(x, shY, upperDeg, 54);
const elbow = tip(x, shY, upperDeg, 56);
const foreDeg = upperDeg + s * l.bend;
const hand = tip(elbow.x, elbow.y, foreDeg, 50);
// Aponta com o braço esticado para a frente (point, reach); erguido acima da cabeça (wave, arms_up) a mão fica aberta.
const pointing = !holds && s > 0 && l.raise > 60 && l.raise < 125 && Math.abs(l.bend) < 30;
// Manga longa termina numa borda (punho) e o pulso sai de dentro dela; manga curta: o braço segue em pele até a
// mão. A mão nasce do pulso, com a mesma pele e a mesma luz do rosto.
const HAND = HAND_K;
const cuffL = 40;
const wristL = longSleeve ? 43 : 41;
const wrist = tip(elbow.x, elbow.y, foreDeg, wristL);
// Objeto de uma mão: o cabo passa por dentro do punho (ponto `hold` da forma "grip"), em pé.
const gp = handPlacement("grip", wrist.x, wrist.y, foreDeg, s, HAND);
const gi = holds ? (GRIP[holds] ?? { x: 50, y: 60, rot: 0 }) : null;
const cuffEnd = tip(elbow.x, elbow.y, foreDeg, cuffL);
const bareArm = !longSleeve;
// Borda de dentro do braço no tom escuro do pano: separa o braço caído do tronco da mesma cor.
const innerEdge = (px: number, py: number, d: number, len: number, w1: number, w2: number, color: string) => {
const ix = Math.cos((d * Math.PI) / 180) >= 0 ? -s : s;
return <path d={`M${(ix * w1) / 2} 3 L${(ix * w2) / 2} ${len - 2}`} transform={`translate(${px} ${py}) rotate(${d})`} stroke={shade(color, 0.55)} strokeWidth={2.4} strokeLinecap="round" opacity={0.85} />;
};
const hand = { x: wrist.x, y: wrist.y, deg: foreDeg, s, skin: look.skin, light: side, scale: HAND, uid: `${uid}${s}`, onFace: (s > 0 ? layerR : layerL) === "face" };
// Parte de cima (braço e manga curta) e de baixo (antebraço, punho, mão e objeto) podem ir em camadas diferentes:
// o antebraço que cruza o peito passa por cima do pano no ombro, a raiz do braço fica por baixo dele.
const up = part !== "lower";
const low = part !== "upper";
return (
<g key={s}>
<Segment x={x} y={shY} deg={upperDeg} len={54} w={18} fill={sleeve} />
<Segment x={elbow.x} y={elbow.y} deg={foreDeg} len={50} w={16} fill={longSleeve ? sleeve : look.skin} />
<circle cx={hand.x} cy={hand.y} r={11} fill={look.skin} />
<ellipse cx={hand.x - s * 8} cy={hand.y - 6} rx={4.5} ry={7} fill={shade(look.skin, 0.94)} transform={`rotate(${-s * 25} ${hand.x - s * 8} ${hand.y - 6})`} />
{s < 0 && look.accessories?.includes("watch") && <rect x={hand.x - 9} y={hand.y - 22} width={18} height={8} rx={3} fill="#d4a63a" />}
{holds && <svg x={hand.x - 26} y={hand.y - 30} width={52} height={52} viewBox="0 0 100 100" overflow="visible"><Icon id={holds} /></svg>}
<g key={`${s}${part}`}>
{up && <>
<Limb2 id={`ua${uid}${s}`} x={x} y={shY} deg={upperDeg} len={56} w1={33 * Math.max(0.9, w * 0.95)} w2={26} fill={bareArm && top.style !== "dress" ? look.skin : sleeve} side={side} />
{!bareArm && innerEdge(x, shY, upperDeg, 56, 33 * Math.max(0.9, w * 0.95), 26, sleeve)}
{!longSleeve && top.style !== "dress" && <>
{/* Manga curta com a ponta reta (borda de pano), não arredondada: o braço sai de dentro dela. */}
<Cel id={`sl${uid}${s}`} d="M-18.5 0 L-16.2 34 Q0 35.6 16.2 34 L18.5 0 A18.5 18.5 0 0 0 -18.5 0 Z" fill={sleeve}
side={Math.cos((upperDeg * Math.PI) / 180) >= 0 ? side : -side} dx={11} dy={0} transform={`translate(${x} ${shY - 2}) rotate(${upperDeg})`} />
{innerEdge(x, shY - 2, upperDeg, 34, 37, 32.4, sleeve)}
{(() => { const e = tip(x, shY - 2, upperDeg, 34.4); return <SleeveEnd x={e.x} y={e.y} deg={upperDeg} w={32.6} cloth={sleeve} skin={look.skin} wrist={28} light={side} uid={`${uid}s${s}`} />; })()}
</>}
</>}
{low && <>
{longSleeve
? <Limb2 id={`fa${uid}${s}`} x={elbow.x} y={elbow.y} deg={foreDeg} len={cuffL - 11} w1={25} w2={23} fill={sleeve} side={side} />
: <Limb2 id={`fa${uid}${s}`} x={elbow.x} y={elbow.y} deg={foreDeg} len={wristL + 4} w1={22} w2={17} fill={look.skin} side={side} />}
{longSleeve && innerEdge(elbow.x, elbow.y, foreDeg, cuffL - 6, 25, 23, sleeve)}
{/* Dobra no cotovelo e punho da manga. */}
{longSleeve && <path d={`M${elbow.x - 7} ${elbow.y - 3} Q${elbow.x} ${elbow.y + 3} ${elbow.x + 7} ${elbow.y - 3}`} stroke={shade(sleeve, 0.72)} strokeWidth={2.4} fill="none" strokeLinecap="round" transform={`rotate(${foreDeg} ${elbow.x} ${elbow.y})`} />}
{/* Punho da manga com espessura e a abertura escura; o pulso sai de dentro, com a sombra da manga por cima. */}
{longSleeve && <SleeveEnd x={cuffEnd.x} y={cuffEnd.y} deg={foreDeg} w={25.5} cloth={sleeve} skin={look.skin} wrist={0} light={side} uid={`${uid}${s}`} part="back" />}
{s < 0 && look.accessories?.includes("watch") && (() => { const c = tip(elbow.x, elbow.y, foreDeg, wristL + 1); return <rect x={c.x - 10} y={c.y - 4.5} width={20} height={8} rx={3} fill="#d4a63a" transform={`rotate(${foreDeg} ${c.x} ${c.y})`} />; })()}
{/* Segurando: dorso atrás do objeto, dedos dobrados e polegar por cima dele. */}
{holds && gi && gp.hold && (
<g transform={`translate(${gp.hold.x} ${gp.hold.y}) rotate(${gp.rot + gi.rot}) scale(0.88) translate(${-gi.x} ${-gi.y})`}>
<svg width={100} height={100} viewBox="0 0 100 100" overflow="visible"><Icon id={holds} /></svg>
</g>
)}
{/* Duas mãos num objeto largo: aqui só a parte de trás (dedos atrás do objeto); objeto e polegares depois. */}
{twoHanded && <Hand {...hand} curl={1} thumbFront layer="back" />}
{!twoHanded && <Hand {...hand} curl={holds ? 1 : 0.35} point={pointing} gesture={s > 0 && !holds && !pointing ? gest : undefined} layer={holds ? "front" : "all"} />}
{longSleeve && <SleeveEnd x={cuffEnd.x} y={cuffEnd.y} deg={foreDeg} w={25.5} cloth={sleeve} skin={look.skin} wrist={17} light={side} uid={`${uid}${s}`} part="front"
cuff={top.style === "uniform" || top.style === "jacket" ? (top.accent ?? shade(sleeve, 0.8)) : undefined} />}
</>}
</g>
);
};
// Mão perto do rosto (pensar, tapar a boca, mão na testa) é desenhada por cima da cabeça.
const handOnFace = b.armR.raise < 45 && b.armR.bend > 135;
// Profundidade de cada braço pelo estado do rig (limbs.ts): ao lado do corpo, na frente do peito ou no rosto.
// Com o personagem de frente, braço e mão nunca somem atrás do tronco, de acessório ou da barba.
const layerL = armLayer(b, -1, { w, holds: twoHanded });
const layerR = armLayer(b, 1, { w, holds: !!holdItem || twoHanded });
// Objeto largo: entre as duas pegadas de borda, na frente do tronco; os polegares por cima dele.
const twoHand = () => {
if (!twoHanded || !item) return null;
const grab = (s: 1 | -1) => {
const l = s > 0 ? b.armR : b.armL;
const upperDeg = -s * l.raise;
const elbow = tip(100 + s * 54 * w, shY, upperDeg, 56);
const foreDeg = upperDeg + s * l.bend;
const wrist = tip(elbow.x, elbow.y, foreDeg, longSleeve ? 43 : 41);
return { s, wrist, foreDeg, hold: handPlacement("pinch_edge", wrist.x, wrist.y, foreDeg, s, HAND_K).hold! };
};
const [L, R] = [grab(-1), grab(1)];
// Borda do desenho do ícone (fração da largura): o livro vai de 8 a 92, a tábua de 14 a 86.
const span = item === "tablet" ? 0.72 : 0.84;
const size = Math.abs(R.hold.x - L.hold.x) / span;
const cx = (L.hold.x + R.hold.x) / 2;
const cy = (L.hold.y + R.hold.y) / 2;
return <>
<svg x={cx - size / 2} y={cy - size * 0.56} width={size} height={size} viewBox="0 0 100 100" overflow="visible"><Icon id={item} /></svg>
{[L, R].map((g) => <Hand key={g.s} x={g.wrist.x} y={g.wrist.y} deg={g.foreDeg} s={g.s} skin={look.skin} light={side} scale={HAND_K} uid={`${uid}${g.s}`} curl={1} thumbFront layer="front" />)}
</>;
};
// Braço "side" inteiro na camada dele; braço "front"/"face": a raiz junto com os de lado (por baixo do pano do
// ombro) e o antebraço/mão na camada própria (por cima do pano, do peito ou do rosto).
const arms = (layer: string) => <>
{layer === "side" && <>
{layerL === "side" ? arm(-1, b.armL) : arm(-1, b.armL, undefined, "upper")}
{layerR === "side" ? arm(1, b.armR, holdItem) : arm(1, b.armR, undefined, "upper")}
</>}
{layer !== "side" && layerL === layer && arm(-1, b.armL, undefined, "lower")}
{layer !== "side" && layerR === layer && arm(1, b.armR, layer === "face" ? undefined : holdItem, "lower")}
</>;
const top = look.top;
const x0 = 100 - 36 * w;
const x1 = 100 + 36 * w;
const torsoTop = hipY - 134;
const torsoBottom = top.style === "dress" ? hipY + 55 : hipY;
const flare = top.style === "dress" ? 14 : 0;
const x0 = 100 - 56 * w;
const x1 = 100 + 56 * w;
const torsoBottom = top.style === "dress" ? hipY + 58 : top.style === "robe" ? hipY + 108 - b.crouch * 40 : hipY + 6;
const flare = top.style === "dress" ? 16 : top.style === "robe" ? 20 : 0;
const accent = top.accent ?? shade(top.color, 1.3);
const belly = !!look.belly;
const torsoPath = `M${x0} ${torsoTop + 16} Q${x0} ${torsoTop + 2} ${x0 + 14} ${torsoTop} L${x1 - 14} ${torsoTop} Q${x1} ${torsoTop + 2} ${x1} ${torsoTop + 16} L${x1 + flare} ${torsoBottom} L${x0 - flare} ${torsoBottom} Z`;
const holdItem = b.armR.raise > 20 || b.armR.bend > 40 ? item : undefined;
const bulge = look.belly ? 14 : look.build === "heavy" ? 8 : 2;
// Tronco em "pera": ombros redondos, cintura e barriga mais largas embaixo.
const torsoPath = `M${100 - 36 * w} ${torsoTop} C${x0 - 6} ${torsoTop + 2} ${x0 - 8} ${torsoTop + 34} ${x0 - 2} ${torsoTop + 62}`
+ ` C${x0 - bulge} ${torsoTop + 88} ${x0 - flare - bulge * 0.6} ${torsoBottom - 10} ${x0 - flare + 2} ${torsoBottom}`
+ ` L${x1 + flare - 2} ${torsoBottom} C${x1 + flare + bulge * 0.6} ${torsoBottom - 10} ${x1 + bulge} ${torsoTop + 88} ${x1 + 2} ${torsoTop + 62}`
+ ` C${x1 + 8} ${torsoTop + 34} ${x1 + 6} ${torsoTop + 2} ${100 + 36 * w} ${torsoTop} Z`;
const fold = shade(top.color, 0.74);
const neckH = 28;
// Largura do pescoço proporcional à cabeça (≈ metade dela), um pouco mais grosso em corpo forte.
const nw = 26 * (HEAD_SCALE / 1.2) * (look.build === "heavy" ? 1.12 : look.build === "slim" ? 0.92 : 1);
const headTransform = `translate(0 ${torsoTop - neckH + 6 + breathe * 0.4}) rotate(${b.headTilt} 100 0) translate(100 0) scale(${HEAD_SCALE}) translate(-100 -156)`;
return (
<svg viewBox="0 0 200 440" width="100%" height="100%" overflow="visible">
<g transform={`translate(100 440) scale(${look.height}) translate(-100 -440)`}>
{/* Sombra de contato no chão. */}
<ellipse cx={100} cy={438} rx={66 * w} ry={8} fill="#000000" opacity={0.18} />
{look.hair.style === "long" && (
<g transform={`rotate(${b.lean} 100 ${hipY})`}>
<path d={`M50 ${torsoTop - 34} Q48 ${torsoTop - 94} 100 ${torsoTop - 96} Q152 ${torsoTop - 94} 150 ${torsoTop - 34} L156 ${torsoTop + 56} Q100 ${torsoTop + 71} 44 ${torsoTop + 56} Z`} fill={look.hair.color} />
<g transform={headTransform}>
<Cel id={`hb${uid}`} d="M50 104 Q46 46 100 46 Q154 46 150 104 L158 214 Q100 232 42 214 Z" fill={shade(look.hair.color, 0.9)} side={side} dx={10} dy={0} />
</g>
</g>
)}
{leg(-1, b.legL)}
{leg(1, b.legR)}
{look.bottom.style === "skirt" && look.top.style !== "dress" && (
<path d={`M${100 - 30 * w} ${hipY - 6} L${100 + 30 * w} ${hipY - 6} L${100 + 42 * w} ${hipY + 52} L${100 - 42 * w} ${hipY + 52} Z`} fill={look.bottom.color} />
{look.bottom.style === "skirt" && !longTop && (
<path d={`M${100 - 34 * w} ${hipY - 6} L${100 + 34 * w} ${hipY - 6} L${100 + 46 * w} ${hipY + 52} L${100 - 46 * w} ${hipY + 52} Z`} fill={look.bottom.color} />
)}
{!longTop && <path d={`M${100 - 40 * w} ${hipY - 4} L${100 + 40 * w} ${hipY - 4} L${100 + 38 * w} ${hipY + 16} L${100 - 38 * w} ${hipY + 16} Z`} fill={look.bottom.style === "pants" ? look.bottom.color : look.bottom.color} />}
<g transform={`rotate(${b.lean} 100 ${hipY}) translate(0 ${breathe * 0.3})`}>
{arm(-1, b.armL)}
<g>
{top.style === "hoodie" && <path d={`M${x0 + 6} ${torsoTop + 4} Q100 ${torsoTop - 24} ${x1 - 6} ${torsoTop + 4} Z`} fill={shade(top.color, 0.8)} />}
<defs><clipPath id={`t${uid}`}><path d={torsoPath} /></clipPath></defs>
<path d={torsoPath} fill={top.color} />
{belly && <ellipse cx={100} cy={hipY - 44} rx={44 * w} ry={40} fill={top.color} />}
<g clipPath={`url(#t${uid})`}>
<rect x={100 + 14 * w} y={torsoTop} width={40 * w} height={torsoBottom - torsoTop + 2} fill="#000000" opacity={0.1} />
</g>
{/* Volume da barriga: curva de baixo mais escura e brilho em cima, sem "mancha". */}
{belly && <><path d={`M${100 - 38 * w} ${hipY - 22} Q100 ${hipY + 4} ${100 + 38 * w} ${hipY - 22}`} stroke={shade(top.color, 0.72)} strokeWidth={4} fill="none" strokeLinecap="round" />
<ellipse cx={100 - 14 * w} cy={hipY - 62} rx={16 * w} ry={10} fill="#ffffff" opacity={0.035} /></>}
{(top.style === "shirt" || top.style === "uniform") && <path d={`M88 ${torsoTop} L100 ${torsoTop + 16} L112 ${torsoTop} Z`} fill={shade(top.color, 0.78)} />}
{(top.style === "jacket" || top.style === "hoodie") && <path d={`M100 ${torsoTop + 6} L100 ${torsoBottom}`} stroke={shade(top.color, 0.65)} strokeWidth={3} />}
{top.style === "uniform" && <rect x={x0} y={hipY - 42} width={x1 - x0} height={11} fill={accent} />}
{top.style === "shirt" && top.accent && <rect x={x0} y={hipY - 38} width={x1 - x0} height={9} fill={accent} />}
{top.style === "jacket" && <><path d={`M100 ${torsoTop + 2} L100 ${torsoBottom}`} stroke={shade(top.color, 0.6)} strokeWidth={4} /><path d={`M86 ${torsoTop + 2} L100 ${torsoTop + 30} L114 ${torsoTop + 2} Z`} fill={accent} /></>}
{top.style === "hoodie" && <rect x={84} y={hipY - 50} width={32} height={22} rx={6} fill={shade(top.color, 0.85)} />}
{top.style === "dress" && [0, 1, 2, 3].map((i) => <circle key={i} cx={84 + (i % 2) * 32} cy={torsoTop + 40 + Math.floor(i / 2) * 70} r={3.5} fill="#ffffff" opacity={0.5} />)}
<Accessories look={look} x0={x0} x1={x1} top={torsoTop} bottom={torsoBottom} hipY={hipY} />
{top.style === "hoodie" && <path d={`M${x0 + 4} ${torsoTop + 8} Q100 ${torsoTop - 30} ${x1 - 4} ${torsoTop + 8} Z`} fill={shade(top.color, 0.78)} />}
{/* Pescoço com a sombra do queixo. */}
{/* Pescoço visível: alarga na base (trapézio), sombra do queixo em cima e o lado da sombra mais escuro. */}
<path d={`M${100 - nw} ${torsoTop - neckH - 8} L${100 + nw} ${torsoTop - neckH - 8} L${100 + nw + 6} ${torsoTop + 10} L${100 - nw - 6} ${torsoTop + 10} Z`} fill={look.skin} />
<path d={`M${100 + side * 4} ${torsoTop - neckH - 8} L${100 + side * nw} ${torsoTop - neckH - 8} L${100 + side * (nw + 6)} ${torsoTop + 10} L${100 + side * 8} ${torsoTop + 10} Z`} fill={cool(look.skin, 0.84)} />
<path d={`M${100 - nw} ${torsoTop - neckH - 8} L${100 + nw} ${torsoTop - neckH - 8} L${100 + nw + 0.5} ${torsoTop - neckH + 6} Q100 ${torsoTop - neckH + 12} ${100 - nw - 0.5} ${torsoTop - neckH + 6} Z`} fill={cool(look.skin, 0.74)} />
<path d={`M${100 - 6} ${torsoTop - 4} Q100 ${torsoTop + 2} ${100 + 6} ${torsoTop - 4}`} stroke={shade(look.skin, 0.72)} strokeWidth={2} fill="none" strokeLinecap="round" />
<Cel id={`to${uid}`} d={torsoPath} fill={top.color} side={side} dx={16} dy={-4} k={0.8} />
{/* Barra / cós embaixo do tronco. */}
{!longTop && <path d={`M${x0 - 1} ${torsoBottom - 9} L${x1 + 1} ${torsoBottom - 9} L${x1 + 1} ${torsoBottom} L${x0 - 1} ${torsoBottom} Z`} fill={shade(top.color, 0.82)} />}
{/* Dobras do tecido: axilas, barriga. */}
<path d={`M${x0 + 8} ${torsoTop + 46} Q${x0 + 18} ${torsoTop + 58} ${x0 + 14} ${torsoTop + 72} M${x1 - 8} ${torsoTop + 46} Q${x1 - 18} ${torsoTop + 58} ${x1 - 14} ${torsoTop + 72}`} stroke={fold} strokeWidth={2.6} fill="none" strokeLinecap="round" />
{(look.belly || look.build === "heavy") && <path d={`M${100 - 30 * w} ${hipY - 16} Q100 ${hipY + 2} ${100 + 30 * w} ${hipY - 16}`} stroke={fold} strokeWidth={3} fill="none" strokeLinecap="round" />}
<path d={`M${100 - 18 * w} ${hipY - 34} Q${100 - 8} ${hipY - 28} ${100 - 4} ${hipY - 36}`} stroke={fold} strokeWidth={2.2} fill="none" strokeLinecap="round" opacity={0.7} />
{/* Construção da roupa por estilo. */}
{top.style === "shirt" && <>
<path d={`M84 ${torsoTop - 2} L100 ${torsoTop + 20} L94 ${torsoTop + 2} Z M116 ${torsoTop - 2} L100 ${torsoTop + 20} L106 ${torsoTop + 2} Z`} fill={shade(top.color, 1.15)} />
<path d={`M100 ${torsoTop + 20} L100 ${torsoBottom - 10}`} stroke={fold} strokeWidth={2} />
{[0, 1, 2].map((i) => <circle key={i} cx={103} cy={torsoTop + 34 + i * 24} r={2.6} fill={shade(top.color, 0.65)} />)}
{top.accent && <rect x={x0 - 4} y={hipY - 40} width={x1 - x0 + 8} height={9} fill={accent} />}
</>}
{top.style === "uniform" && <>
<path d={`M84 ${torsoTop - 2} L100 ${torsoTop + 16} L116 ${torsoTop - 2} L110 ${torsoTop + 6} L100 ${torsoTop + 12} L90 ${torsoTop + 6} Z`} fill={shade(top.color, 0.7)} />
<path d={`M100 ${torsoTop + 14} L100 ${torsoBottom - 10}`} stroke={fold} strokeWidth={2.4} />
{[0, 1, 2, 3].map((i) => <circle key={i} cx={103} cy={torsoTop + 28 + i * 20} r={2.6} fill={accent} />)}
<rect x={x0 + 12} y={torsoTop + 28} width={24} height={16} rx={3} fill={shade(top.color, 0.86)} />
<rect x={x0 - 4} y={hipY - 44} width={x1 - x0 + 8} height={10} fill={accent} />
</>}
{(top.style === "jacket" || top.style === "hoodie") && <>
{/* Camiseta clara por baixo, zíper com puxador, gola. */}
<path d={`M88 ${torsoTop} L100 ${torsoTop + 28} L112 ${torsoTop} Z`} fill={top.style === "jacket" ? "#efeae0" : shade(top.color, 0.8)} />
<path d={`M100 ${torsoTop + 26} L100 ${torsoBottom - 4}`} stroke={shade(top.color, 0.58)} strokeWidth={3.4} />
<rect x={97} y={torsoTop + 40} width={6} height={11} rx={2} fill={shade(top.color, 1.35)} />
{top.style === "jacket" && <>
<path d={`M80 ${torsoTop - 4} L100 ${torsoTop + 28} L92 ${torsoTop - 2} Z M120 ${torsoTop - 4} L100 ${torsoTop + 28} L108 ${torsoTop - 2} Z`} fill={accent} />
<path d={`M${x0 + 2} ${torsoTop + 58} L${x0 + 2} ${torsoBottom - 10} M${x1 - 2} ${torsoTop + 58} L${x1 - 2} ${torsoBottom - 10}`} stroke={accent} strokeWidth={5} />
</>}
{top.style === "hoodie" && <>
<rect x={80} y={hipY - 52} width={40} height={24} rx={7} fill={shade(top.color, 0.86)} />
<path d={`M93 ${torsoTop + 4} L91 ${torsoTop + 34} M107 ${torsoTop + 4} L109 ${torsoTop + 34}`} stroke="#efeae0" strokeWidth={2.4} strokeLinecap="round" />
</>}
</>}
{top.style === "dress" && <>
<path d={`M86 ${torsoTop} Q100 ${torsoTop + 20} 114 ${torsoTop}`} stroke={shade(top.color, 0.7)} strokeWidth={4} fill="none" />
{[0, 1, 2, 3, 4, 5].map((i) => <circle key={i} cx={78 + (i % 3) * 22} cy={torsoTop + 44 + Math.floor(i / 3) * 70} r={3.5} fill="#ffffff" opacity={0.45} />)}
<path d={`M${x0 - flare + 4} ${torsoBottom - 4} L${x1 + flare - 4} ${torsoBottom - 4}`} stroke={shade(top.color, 0.78)} strokeWidth={6} />
</>}
{top.style === "robe" && <>
{/* Gola em V, dobras do pano e faixa amarrada na cintura com a ponta caindo. */}
<path d={`M84 ${torsoTop} L100 ${torsoTop + 30} L116 ${torsoTop} Z`} fill={shade(top.color, 0.7)} />
<path d={`M${100 - 18 * w} ${hipY + 6} Q${100 - 22 * w} ${hipY + 50} ${100 - 26 * w} ${torsoBottom - 4} M${100 + 12 * w} ${hipY + 8} Q${100 + 16 * w} ${hipY + 50} ${100 + 22 * w} ${torsoBottom - 4} M100 ${hipY + 14} L100 ${torsoBottom - 6}`} stroke={fold} strokeWidth={3} fill="none" strokeLinecap="round" />
<rect x={x0 - 3} y={hipY - 30} width={x1 - x0 + 6} height={13} rx={5} fill={accent} />
<path d={`M${100 + 10 * w} ${hipY - 20} L${100 + 16 * w} ${hipY + 28} L${100 + 25 * w} ${hipY + 26} L${100 + 19 * w} ${hipY - 20} Z`} fill={shade(accent, 0.82)} />
<path d={`M${x0 - flare + 4} ${torsoBottom - 3} L${x1 + flare - 4} ${torsoBottom - 3}`} stroke={shade(top.color, 0.72)} strokeWidth={5} />
</>}
<Accessories look={look} x0={x0} x1={x1} top={torsoTop} bottom={torsoBottom} hipY={hipY} side={side} part="torso" uid={uid} />
</g>
{!handOnFace && arm(1, b.armR, holdItem)}
<rect x={90} y={torsoTop - 12} width={20} height={16} fill={shade(look.skin, 0.9)} />
<g transform={`translate(0 ${torsoTop - 156 + breathe * 0.4}) rotate(${b.headTilt} 100 150)`}>
<Head look={look} f={f} b={b} t={t} uid={uid} />
{/* Camadas: braço ao lado do corpo (e a raiz dos outros) → pano do peito → pano no ombro → antebraço/mão na
frente do peito → cabeça → mão no rosto. */}
{arms("side")}
<Accessories look={look} x0={x0} x1={x1} top={torsoTop} bottom={torsoBottom} hipY={hipY} side={side} part="chest" uid={uid} />
<Accessories look={look} x0={x0} x1={x1} top={torsoTop} bottom={torsoBottom} hipY={hipY} side={side} part="drape" uid={uid} />
{arms("front")}
{twoHand()}
<g transform={headTransform}>
<Head look={look} f={f} b={b} t={t} uid={uid} side={side} />
{st.emote && (
<g transform={`translate(150 30) scale(${0.4 + 0.6 * st.emote.k})`} opacity={st.emote.k}>
<circle r={24} fill="#ffffff" stroke={INK} strokeWidth={3} />
<text y={10} textAnchor="middle" fontSize={30} fontWeight={800} fill={st.emote.text === "!" || st.emote.text === "💢" ? "#e8463d" : INK}>{st.emote.text}</text>
<g transform={`translate(156 40) scale(${0.4 + 0.6 * st.emote.k})`} opacity={st.emote.k}>
<circle r={22} fill="#ffffff" />
<text y={10} textAnchor="middle" fontSize={28} fontWeight={800} fill={st.emote.text === "!" || st.emote.text === "💢" ? "#e8463d" : INK}>{st.emote.text}</text>
</g>
)}
</g>
{handOnFace && arm(1, b.armR)}
{arms("face")}
</g>
</g>
</svg>
);
}
/**
* Vista "insert": close das MÃOS fazendo algo (segurando o objeto, escrevendo), antebraços entrando por baixo
* com a manga da roupa do personagem. Ocupa a área inteira de quem desenha (viewBox 1080×1080).
*/
export function HandsInsert({ look = DEFAULT_LOOK, item, t = 0, shadeSide = 1 }: { look?: CharacterLook; item?: IconId; t?: number; shadeSide?: 1 | -1 }) {
const uid = useId().replace(/:/g, "");
const sway = Math.sin(t * 1.6) * 6;
const long = ["jacket", "hoodie", "uniform", "robe"].includes(look.top.style);
const cloth = look.top.style === "dress" ? look.skin : look.top.color;
const cuff = look.top.style === "uniform" || look.top.style === "jacket" ? (look.top.accent ?? shade(cloth, 0.8)) : undefined;
// Mão grande (close): a mesma biblioteca de mãos em escala; a manga/punho na mesma proporção do braço.
const K = 2.7;
const S = 5;
const cy = 560 + sway * 0.5;
const arms = ([-1, 1] as const).map((s) => {
// O antebraço sobe do canto de baixo, inclinado para dentro; no pulso a mão dobra: os dedos ficam ATRÁS da
// borda lateral do objeto e o polegar comprido apoia por cima da página (pegada de quem segura um livro aberto).
const deg = 180 - s * 30;
const edge = { x: 540 + s * 250 + (s > 0 ? sway : 0), y: 660 + (s > 0 ? -sway : 0) };
// Pegada de borda com o antebraço vindo de baixo: o pulso segue o eixo do antebraço até a mão.
const wrist = item ? wristForHold("pinch_low", edge.x, edge.y, deg, s, K) : { x: edge.x + s * 40, y: edge.y + 120 };
const end = tip(wrist.x, wrist.y, deg, -3 * S);
const start = tip(end.x, end.y, deg, -560);
const hand = { x: wrist.x, y: wrist.y, deg, s, skin: look.skin, light: shadeSide, scale: K, uid: `${uid}i${s}` };
return { s, deg, wrist, end, start, hand };
});
return (
<svg viewBox="0 0 1080 1080" width="100%" height="100%" overflow="visible">
{arms.map(({ s, deg, end, start, hand }) => (
<g key={s}>
{long
? <>
<Limb2 id={`if${uid}${s}`} x={start.x} y={start.y} deg={deg} len={560 - 11 * S} w1={34 * S} w2={23 * S} fill={cloth} side={shadeSide} />
{/* Dobras do pano no antebraço. */}
<path d={`M${-9 * S} 300 Q0 ${300 + 4 * S} ${8 * S} 296 M${-7 * S} 420 Q${-1 * S} ${420 + 3 * S} ${7 * S} 418`} stroke={shade(cloth, 0.74)} strokeWidth={2.2 * S} fill="none" strokeLinecap="round" transform={`translate(${start.x} ${start.y}) rotate(${deg})`} />
<SleeveEnd x={end.x} y={end.y} deg={deg} w={25.5} cloth={cloth} cuff={cuff} skin={look.skin} wrist={0} light={shadeSide} uid={`${uid}ie${s}`} scale={S} part="back" />
</>
: <Limb2 id={`if${uid}${s}`} x={start.x} y={start.y} deg={deg} len={560 + 6 * S} w1={26 * S} w2={17 * S} fill={look.skin} side={shadeSide} />}
{item && <Hand {...hand} curl={1} layer="back" thumbFront />}
</g>
))}
{item && <g transform={`translate(540 ${cy})`}><svg x={-300} y={-300} width={600} height={600} viewBox="0 0 100 100" overflow="visible"><Icon id={item} /></svg></g>}
{/* Só o polegar por cima do objeto; sem objeto, as mãos relaxadas inteiras. */}
{arms.map(({ s, hand }) => <Hand key={s} {...hand} curl={item ? 1 : 0.35} layer={item ? "front" : "all"} thumbFront={!!item} />)}
{/* Barra do punho por cima da sobra do pulso. */}
{long && arms.map(({ s, deg, end }) => <SleeveEnd key={`f${s}`} x={end.x} y={end.y} deg={deg} w={25.5} cloth={cloth} cuff={cuff} skin={look.skin} wrist={17} light={shadeSide} uid={`${uid}ie${s}`} scale={S} part="front" />)}
</svg>
);
}
+55 -10
View File
@@ -6,9 +6,10 @@ import { CrowdFigure, PersonFigure } from "./actors";
import { Icon } from "./icons";
import { Captions, CrossOut, Grain, Hud, Rings, TagLabel, TextLayer, pop, shake } from "./overlays";
import { SceneBackground } from "./scenes";
import { CharacterFigure } from "./CharacterFigure";
import { CharacterFigure, HandsInsert } from "./CharacterFigure";
import { evaluate } from "./motion";
import { LightLayer } from "./places";
import { LightLayer, PlaceForeground, WeatherLayer } from "./places";
import { AnimalFigure, BIRDS, SPECIES_HEIGHT } from "./animals";
import type { ShotSpec } from "./spec";
import { loadFonts } from "./theme";
@@ -29,30 +30,72 @@ export function Shot(spec: ShotSpec) {
const k = pop(frame, fps, a.enterS ?? 0);
if (a.kind === "crowd") {
return (
<div key={i} style={{ position: "absolute", left: "-2%", width: "104%", top: `${(a.y - 0.16) * 100}%`, height: "16%",
<div key={i} style={{ position: "absolute", left: "-2%", width: "104%", top: `${(a.y - 0.34) * 100}%`, height: "34%",
opacity: k, transform: `translateY(${(1 - k) * 8}%)` }}>
<CrowdFigure c={a} frame={frame} />
<CrowdFigure c={a} frame={frame} fps={fps} />
</div>
);
}
if (a.kind === "animal") {
// Animal (ou fila/casal): anda de x até walk.to; ave voando sobe e desce em onda. Olha para onde anda.
const t = frame / fps;
const w = a.walk;
const s0 = w?.startS ?? 0;
const d = w?.dur ?? Math.max(0.5, spec.durationS - s0);
const p = w ? Math.max(0, Math.min(1, (t - s0) / d)) : 0;
const moving = !!w && t >= s0 && p < 1;
const flip = w ? w.to < a.x !== !!a.flip : !!a.flip;
const h = height * SPECIES_HEIGHT[a.species] * (a.scale ?? 1);
const n = a.count ?? 1;
const gap = a.gap ?? 0.16 * (a.scale ?? 1) * (SPECIES_HEIGHT[a.species] / 0.12);
const dir = w ? Math.sign(w.to - a.x) || 1 : flip ? -1 : 1;
const fly = !!a.fly && BIRDS.includes(a.species);
return (
<React.Fragment key={i}>
{Array.from({ length: n }, (_, j) => (a.pair ? [0, 1] : [0]).map((m) => {
const x0 = a.x - dir * j * gap + (w ? (w.to - a.x) * p : 0);
const y = a.y - m * 0.012 + (fly ? Math.sin(t * 2.4 + j) * 0.012 : 0);
const x = x0 - dir * m * gap * 0.35;
return (
<div key={`${j}-${m}`} style={{ position: "absolute", left: x * width - h / 2, top: y * height - h, width: h, height: h,
opacity: Math.min(1, k * 1.5), transform: `scale(${flip ? -1 : 1}, 1) translateY(${(1 - k) * 10}%)`, zIndex: m ? 0 : 1 }}>
<AnimalFigure species={a.species} color={a.color} t={t} walking={moving && !fly} flying={fly} carry={a.carry} seed={j * 3 + m} />
</div>
);
}))}
</React.Fragment>
);
}
if (a.character) {
// Personagem da biblioteca: mesmo visual em toda cena. Expressão, pose, andar, pular, falar… saem da
// linha do tempo (motion.ts), com a boca na fala (palavras + volume do áudio).
const t = frame / fps;
const st = evaluate({ x: a.x, expression: a.expression, pose: a.pose, face: a.face, body: a.body, flip: a.flip, timeline: a.timeline },
t, spec.durationS, spec.seed + i * 13, { words: spec.words ?? [], env: spec.audioEnv });
// Meio corpo / de perto: o personagem cresce e os pés saem do quadro (cabeça perto do terço de cima).
const zoom = a.framing === "close" ? 2.9 : a.framing === "medium" ? 1.9 : 1;
const ch = height * 0.36 * (a.scale ?? 1) * zoom;
// Vista "insert": close das mãos (antebraços entrando por baixo) segurando o objeto.
if (a.framing === "insert") {
return (
<div key={i} style={{ position: "absolute", left: "-6%", width: "112%", top: `${(0.92 - 0.62) * 100}%`, aspectRatio: "1 / 1", opacity: Math.min(1, k * 1.5),
transform: `translateY(${(1 - k) * 8}%)` }}>
<HandsInsert look={a.character.look} item={a.item} t={t} />
</div>
);
}
// Caixa do desenho (200×440, cabeça ~1/3): corpo inteiro ~52% da altura do quadro; meio corpo corta nos
// joelhos; close corta na cintura, com a cabeça ocupando ~1/3 do quadro.
const box = a.framing === "close" ? 1.05 : a.framing === "medium" ? 0.8 : 0.52 * (a.scale ?? 1);
const zoom = box / 0.52;
const ch = height * box;
const cw = (ch * 200) / 440;
const baseY = a.framing === "close" ? 1.15 : a.framing === "medium" ? 0.98 : a.y;
const baseY = a.framing === "close" ? 1.17 : a.framing === "medium" ? 1.04 : a.y;
const label = a.label ?? a.character.name;
const showLabel = label && Math.abs(st.rot) < 30;
return (
<div key={i} style={{ position: "absolute", left: (st.x + st.dx) * width - cw / 2, top: (baseY + st.dy) * height - ch, width: cw, height: ch,
opacity: Math.min(1, k * 1.5), transformOrigin: "50% 100%",
transform: `translateY(${(1 - k) * 10}%) rotate(${st.rot}deg) scale(${(st.flip ? -1 : 1) * st.sx}, ${st.sy})` }}>
<CharacterFigure look={a.character.look} item={a.item} t={t} state={st} />
{/* A luz da cena vem sempre do mesmo lado: espelhado, a sombra do desenho troca de lado. */}
<CharacterFigure look={a.character.look} item={a.item} t={t} state={st} shadeSide={st.flip ? -1 : 1} />
{showLabel && (
<div style={{ position: "absolute", left: zoom > 1 ? "8%" : "50%", top: zoom > 1 ? "22%" : "-15%", transform: `translateX(-50%) scaleX(${st.flip ? -1 : 1})`, textAlign: "center" }}>
<TagLabel text={label} />
@@ -87,7 +130,9 @@ export function Shot(spec: ShotSpec) {
</div>
);
})}
<LightLayer light={spec.light} palette={spec.palette} />
{spec.scene.kind === "place" && <PlaceForeground spec={spec} frame={frame} progress={progress} />}
<WeatherLayer spec={spec} frame={frame} />
<LightLayer light={spec.light} palette={spec.palette} spec={spec} />
{(spec.texts ?? []).map((t, i) => <TextLayer key={i} t={t} frame={frame} fps={fps} />)}
</AbsoluteFill>
{(spec.grain ?? 0.11) > 0 && <Grain opacity={spec.grain ?? 0.11} seed={spec.seed} />}
+43 -13
View File
@@ -4,6 +4,9 @@ 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 }) {
@@ -44,23 +47,50 @@ export function PersonFigure({ p, frame, fps }: { p: Person; frame: number; fps:
);
}
/** Fila de silhuetas pretas (multidão no portão). */
export function CrowdFigure({ c, frame }: { c: Crowd; frame: number }) {
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 = <T,>(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<CharacterLook["accessories"]> = [];
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) => ({ x: (i + 0.5) / c.count, h: 0.8 + rand() * 0.35, p: rand() * 6 }));
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 (
<svg viewBox="0 0 1000 300" width="100%" height="100%" preserveAspectRatio="none" overflow="visible">
{people.map((m, i) => {
const bob = Math.sin(frame / 14 + m.p) * 3;
const x = m.x * 1000;
const h = 260 * m.h;
<div style={{ position: "absolute", inset: 0 }}>
{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 (
<g key={i} transform={`translate(${x} ${300 + bob})`} fill="#06070f">
<rect x={-26} y={-h * 0.62} width={52} height={h * 0.62} rx={18} />
<circle cx={0} cy={-h * 0.75} r={h * 0.13} />
</g>
<div key={m.i} style={{ position: "absolute", left: `${m.x * 100 - h * 0.11}%`, bottom: `${(m.back ? 8 : 0) + Math.sin(t * 2 + m.p) * 0.4}%`, height: `${h}%`, aspectRatio: "200 / 440",
filter: m.back ? "brightness(0.82)" : undefined }}>
<CharacterFigure look={crowdLook(m.i + c.count * 13)} t={t} state={st} shadeSide={1} />
</div>
);
})}
</svg>
</div>
);
}
+157
View File
@@ -0,0 +1,157 @@
// Animais do estilo Cartoon: figuras reaproveitáveis em qualquer história (não são cena pronta). Cada espécie
// é desenhada por formas chapadas no mesmo traço dos personagens, olhando para a direita, com as patas em
// (100, 200) num viewBox 200×200. Andar mexe as patas; ave voando bate as asas. Cor e escala vêm do spec.
import React from "react";
export const SPECIES = ["dove", "raven", "elephant", "giraffe", "lion", "sheep", "horse", "camel"] as const;
export type Species = (typeof SPECIES)[number];
/** Altura de referência de cada espécie (fração da altura do quadro, com scale 1). */
export const SPECIES_HEIGHT: Record<Species, number> = {
dove: 0.05, raven: 0.055, elephant: 0.2, giraffe: 0.3, lion: 0.12, sheep: 0.085, horse: 0.17, camel: 0.19,
};
/** Aves podem voar (asas batendo, sem patas no chão). */
export const BIRDS: readonly Species[] = ["dove", "raven"];
const INK = "#15161f";
const DEFAULT_COLOR: Record<Species, string> = {
dove: "#f4f4f8", raven: "#23242e", elephant: "#9aa0ab", giraffe: "#e8b54a", lion: "#d99a3a", sheep: "#f1ece0", horse: "#8a5a3a", camel: "#c9a06a",
};
function shade(hex: string, k: number): string {
const n = parseInt(hex.slice(1), 16);
const c = (v: number) => Math.max(0, Math.min(255, Math.round(v * k))).toString(16).padStart(2, "0");
return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`;
}
/** Perna que balança pelo quadril: `phase` vem do passo (0 parado). */
function Leg({ x, y, len, w, fill, swing }: { x: number; y: number; len: number; w: number; fill: string; swing: number }) {
return <rect x={x - w / 2} y={y} width={w} height={len} rx={w / 2.4} fill={fill} transform={`rotate(${swing} ${x} ${y})`} />;
}
function Eye({ x, y, r = 4.5, light }: { x: number; y: number; r?: number; light?: boolean }) {
return <g><circle cx={x} cy={y} r={r} fill={light ? "#ffffff" : INK} />{light ? <circle cx={x + 1} cy={y} r={r * 0.55} fill={INK} /> : <circle cx={x + 1.3} cy={y - 1.3} r={r * 0.3} fill="#ffffff" />}</g>;
}
/** Ramo de oliveira no bico (pomba da história do dilúvio, mas serve para qualquer ave). */
function Branch({ x, y }: { x: number; y: number }) {
return (
<g transform={`translate(${x} ${y})`}>
<path d="M0 0 Q14 6 30 4" stroke="#6b4a2a" strokeWidth={2.4} fill="none" strokeLinecap="round" />
{[[8, 2, -30], [16, 6, 30], [22, 2, -30], [28, 6, 25]].map(([lx, ly, r], i) => <ellipse key={i} cx={lx} cy={ly} rx={6} ry={2.6} fill={i % 2 ? "#7fa24a" : "#5f8a3a"} transform={`rotate(${r} ${lx} ${ly})`} />)}
</g>
);
}
export function AnimalFigure({ species, color, t = 0, walking = false, flying = false, carry, seed = 0 }: {
species: Species; color?: string; t?: number; walking?: boolean; flying?: boolean; carry?: "olive"; seed?: number;
}) {
const c = color ?? DEFAULT_COLOR[species];
const dark = shade(c, 0.78);
// Passo: pernas da frente e de trás em oposição; corpo sobe e desce de leve.
const ph = walking ? Math.sin((t + seed * 0.37) * Math.PI * 2 * 1.6) : 0;
const bob = walking ? Math.abs(ph) * -3 : Math.sin(t * 2 + seed) * 0.8;
const flap = flying ? Math.sin((t + seed * 0.21) * Math.PI * 2 * 3.2) : 0;
const body = (inner: React.ReactNode) => <svg viewBox="0 0 200 200" width="100%" height="100%" overflow="visible"><g transform={`translate(0 ${bob})`}>{inner}</g></svg>;
switch (species) {
case "dove": case "raven": {
const beak = species === "dove" ? "#e8a04a" : "#3a3b46";
if (flying) {
return body(<g>
<path d={`M78 112 Q60 ${100 - flap * 50} 30 ${96 - flap * 70} Q66 ${112 - flap * 20} 84 124 Z`} fill={dark} />
<ellipse cx={100} cy={122} rx={36} ry={18} fill={c} />
<path d="M66 120 L40 112 L44 132 Z" fill={dark} />
<circle cx={134} cy={112} r={15} fill={c} />
<path d="M147 110 L162 114 L147 118 Z" fill={beak} />
<Eye x={138} y={109} r={3.2} />
<path d={`M104 116 Q118 ${100 - flap * 48} 150 ${92 - flap * 64} Q124 ${114 - flap * 18} 112 126 Z`} fill={c} stroke={dark} strokeWidth={2} />
{carry === "olive" && <Branch x={156} y={116} />}
</g>);
}
return body(<g>
<path d="M86 186 L84 200 M106 186 L108 200" stroke="#e07a4a" strokeWidth={4} strokeLinecap="round" />
<ellipse cx={96} cy={164} rx={36} ry={26} fill={c} />
<path d="M64 160 L36 150 L42 176 Z" fill={dark} />
<path d="M80 158 Q100 146 118 166 Q100 178 80 158 Z" fill={dark} />
<circle cx={128} cy={134} r={17} fill={c} />
<path d="M143 132 L160 137 L143 142 Z" fill={beak} />
<Eye x={132} y={130} r={3.4} />
{carry === "olive" && <Branch x={154} y={138} />}
</g>);
}
case "elephant": return body(<g>
<Leg x={52} y={128} len={70} w={26} fill={dark} swing={-ph * 10} />
<Leg x={128} y={128} len={70} w={26} fill={dark} swing={ph * 10} />
<ellipse cx={92} cy={112} rx={66} ry={50} fill={c} />
<Leg x={72} y={130} len={68} w={26} fill={c} swing={ph * 10} />
<Leg x={148} y={128} len={70} w={26} fill={c} swing={-ph * 10} />
<path d="M28 104 Q16 116 22 134" stroke={dark} strokeWidth={5} fill="none" strokeLinecap="round" />
<circle cx={154} cy={90} r={34} fill={c} />
<path d={`M176 98 Q192 128 182 158 Q178 ${170 + ph * 4} 190 ${172 + ph * 4}`} stroke={c} strokeWidth={16} fill="none" strokeLinecap="round" />
<path d="M130 70 Q100 74 104 108 Q116 132 140 116 Z" fill={dark} />
<path d="M172 112 L184 124" stroke="#f4f0e4" strokeWidth={6} strokeLinecap="round" />
<Eye x={166} y={84} r={4} />
</g>);
case "giraffe": return body(<g>
<Leg x={58} y={118} len={80} w={11} fill={dark} swing={-ph * 12} />
<Leg x={118} y={118} len={80} w={11} fill={dark} swing={ph * 12} />
<ellipse cx={90} cy={112} rx={44} ry={24} fill={c} />
<Leg x={70} y={120} len={78} w={11} fill={c} swing={ph * 12} />
<Leg x={128} y={118} len={80} w={11} fill={c} swing={-ph * 12} />
<path d="M116 100 L150 10 L166 16 L134 108 Z" fill={c} />
{[[80, 104], [100, 116], [66, 116], [104, 98], [138, 60], [148, 34], [130, 84]].map(([x, y], i) => <circle key={i} cx={x} cy={y} r={6} fill={shade(c, 0.62)} />)}
<ellipse cx={168} cy={14} rx={22} ry={12} fill={c} />
<path d="M156 0 L154 -14 M164 0 L164 -14" stroke={dark} strokeWidth={4} strokeLinecap="round" />
<Eye x={170} y={9} r={3.4} />
<path d="M46 104 Q36 120 40 136" stroke={dark} strokeWidth={3} fill="none" />
</g>);
case "lion": {
const mane = shade(c, 0.62);
return body(<g>
<Leg x={58} y={138} len={60} w={15} fill={dark} swing={-ph * 12} />
<Leg x={124} y={138} len={60} w={15} fill={dark} swing={ph * 12} />
<ellipse cx={92} cy={138} rx={52} ry={26} fill={c} />
<Leg x={72} y={140} len={58} w={15} fill={c} swing={ph * 12} />
<Leg x={136} y={138} len={60} w={15} fill={c} swing={-ph * 12} />
<path d={`M42 132 Q20 ${120 + ph * 6} 22 102`} stroke={c} strokeWidth={6} fill="none" strokeLinecap="round" />
<circle cx={22} cy={100} r={7} fill={mane} />
<circle cx={146} cy={112} r={34} fill={mane} />
<circle cx={150} cy={116} r={22} fill={c} />
<ellipse cx={164} cy={124} rx={9} ry={7} fill={shade(c, 1.15)} />
<circle cx={168} cy={121} r={3.4} fill={INK} />
<Eye x={156} y={108} r={3.4} />
</g>);
}
case "sheep": return body(<g>
<Leg x={70} y={150} len={50} w={9} fill="#3a3540" swing={-ph * 12} />
<Leg x={118} y={150} len={50} w={9} fill="#3a3540" swing={ph * 12} />
{[[66, 140], [86, 128], [108, 128], [126, 140], [96, 152], [76, 156], [116, 156]].map(([x, y], i) => <circle key={i} cx={x} cy={y} r={22} fill={c} />)}
<Leg x={82} y={160} len={40} w={9} fill="#2e2a33" swing={ph * 12} />
<Leg x={128} y={156} len={44} w={9} fill="#2e2a33" swing={-ph * 12} />
<ellipse cx={152} cy={128} rx={16} ry={20} fill="#3a3540" />
<ellipse cx={140} cy={116} rx={10} ry={5} fill="#3a3540" transform="rotate(-20 140 116)" />
<circle cx={146} cy={110} r={12} fill={c} />
<Eye x={158} y={124} r={3.2} light />
</g>);
case "horse": case "camel": {
const camel = species === "camel";
return body(<g>
<Leg x={60} y={116} len={84} w={13} fill={dark} swing={-ph * 14} />
<Leg x={124} y={116} len={84} w={13} fill={dark} swing={ph * 14} />
<ellipse cx={92} cy={110} rx={52} ry={28} fill={c} />
{camel && <path d="M62 92 Q76 50 96 88 Q110 54 126 92 Z" fill={c} />}
<Leg x={74} y={118} len={82} w={13} fill={c} swing={ph * 14} />
<Leg x={134} y={116} len={84} w={13} fill={c} swing={-ph * 14} />
<path d={camel ? "M132 100 Q160 96 158 60 L174 56 Q178 104 142 116 Z" : "M128 96 L152 50 L170 58 L146 112 Z"} fill={c} />
<ellipse cx={camel ? 178 : 168} cy={camel ? 56 : 56} rx={camel ? 17 : 22} ry={camel ? 11 : 13} fill={c} transform={`rotate(${camel ? 10 : 30} ${camel ? 178 : 168} 56)`} />
{!camel && <path d="M150 48 Q132 70 128 98" stroke={shade(c, 0.5)} strokeWidth={9} fill="none" strokeLinecap="round" />}
{!camel && <path d={`M42 104 Q24 ${120 + ph * 4} 30 146`} stroke={shade(c, 0.5)} strokeWidth={9} fill="none" strokeLinecap="round" />}
{camel && <path d="M42 106 Q34 120 38 134" stroke={dark} strokeWidth={4} fill="none" />}
<path d="M158 42 L156 30 L166 40 Z" fill={dark} />
<Eye x={camel ? 182 : 170} y={camel ? 52 : 50} r={3.4} />
</g>);
}
default: return null;
}
}
+8 -2
View File
@@ -4,13 +4,16 @@
export const BUILDS = ["slim", "average", "heavy"] as const;
export const HAIR_STYLES = ["short", "side", "bun", "long", "curly", "spiky", "bald", "cap"] as const;
export const BEARD_STYLES = ["none", "stubble", "mustache", "full", "goatee"] as const;
export const BEARD_STYLES = ["none", "stubble", "mustache", "full", "goatee", "long"] as const;
export const GLASSES = ["none", "round", "square", "sun"] as const;
export const BROWS = ["thin", "thick"] as const;
export const TOP_STYLES = ["shirt", "jacket", "hoodie", "dress", "uniform"] as const;
/** "robe" = túnica longa até a canela (com faixa na cintura), de roupa antiga. */
export const TOP_STYLES = ["shirt", "jacket", "hoodie", "dress", "uniform", "robe"] as const;
export const BOTTOM_STYLES = ["pants", "shorts", "skirt"] as const;
export const HEAD_SHAPES = ["round", "oval", "square", "wide"] as const;
export const NOSES = ["button", "curve", "round", "long", "wide"] as const;
/** Calçado: sapato fechado (cor em `shoes`), sandália de tiras ou pé descalço. */
export const FOOTWEAR = ["shoes", "sandals", "bare"] as const;
/** Acessórios desenhados por cima da roupa (combináveis). */
export const ACCESSORIES = ["towel", "whistle", "tie", "vest", "helmet", "watch", "badge", "apron", "scarf", "headset", "chain"] as const;
export type Accessory = (typeof ACCESSORIES)[number];
@@ -34,6 +37,8 @@ export type CharacterLook = {
top: { style: (typeof TOP_STYLES)[number]; color: string; accent?: string };
bottom: { style: (typeof BOTTOM_STYLES)[number]; color: string };
shoes: string;
/** Tipo de calçado (padrão "shoes"); a cor continua em `shoes`. */
footwear?: (typeof FOOTWEAR)[number];
/** Detalhe de ilustração (opcionais; sem eles o personagem sai no traço simples). */
head?: (typeof HEAD_SHAPES)[number];
nose?: (typeof NOSES)[number];
@@ -97,6 +102,7 @@ export function validateLook(look: unknown): string[] {
if (l.lids !== undefined && !(typeof l.lids === "number" && l.lids >= 0 && l.lids <= 0.8)) errors.push("lids entre 0 e 0,8");
if (l.wrinkles !== undefined && !(typeof l.wrinkles === "number" && l.wrinkles >= 0 && l.wrinkles <= 1)) errors.push("wrinkles entre 0 e 1");
if (l.accessories !== undefined && (!Array.isArray(l.accessories) || l.accessories.some((a) => !one(ACCESSORIES, a)))) errors.push(`accessories: ${ACCESSORIES.join("|")}`);
if (l.footwear !== undefined && !one(FOOTWEAR, l.footwear)) errors.push(`footwear: ${FOOTWEAR.join("|")}`);
if (l.accessoryColor !== undefined && !HEX.test(l.accessoryColor)) errors.push("accessoryColor: cor #rrggbb");
return errors;
}
+379
View File
@@ -0,0 +1,379 @@
// Construções e objetos de exterior: casa, prédio, muro, fachada com colunas, loja com toldo, cerca, poste…
// Base em (0,0); luz da esquerda (a face da direita fica na sombra). Medidas pensadas para uma pessoa de ~600.
import React from "react";
import { mix, type Paint } from "./paint";
import type { Draw } from "./nature";
/** Caixa em 2 tons: frente na cor base, faixa da direita na sombra e (opcional) topo iluminado. */
export function Box({ x, y, w, h, fill, p, side = 0.14, top = 0, rx = 0, k = 0.32 }: {
x: number; y: number; w: number; h: number; fill: string; p: Paint; side?: number; top?: number; rx?: number; k?: number;
}) {
return <g>
<rect x={x} y={y} width={w} height={h} rx={rx} fill={p.c(fill)} />
{side > 0 && <rect x={x + w * (1 - side)} y={y} width={w * side} height={h} rx={Math.min(rx, (w * side) / 2)} fill={p.lo(fill, k)} />}
{top > 0 && <rect x={x} y={y} width={w} height={top} rx={Math.min(rx, top / 2)} fill={p.hi(fill, 0.28)} />}
</g>;
}
/** Janela de fachada: moldura, vidro (aceso à noite, céu refletido de dia), cruz e peitoril. */
export function FacadeWindow({ x, y, w, h, p, lit, frame = "#efe6d6", arch = false }: { x: number; y: number; w: number; h: number; p: Paint; lit: boolean; frame?: string; arch?: boolean }) {
const glass = lit ? mix(p.pal.light, "#ffb050", 0.15) : mix(p.pal.sky[1], p.pal.ink, p.night ? 0.55 : 0.18);
const top = arch ? `M${x} ${y + w / 2} A${w / 2} ${w / 2} 0 0 1 ${x + w} ${y + w / 2} L${x + w} ${y + h} L${x} ${y + h} Z` : "";
const inset = 10;
return <g>
{arch ? <path d={top} fill={p.c(frame)} /> : <rect x={x} y={y} width={w} height={h} rx={4} fill={p.c(frame)} />}
{arch
? <path d={`M${x + inset} ${y + w / 2} A${w / 2 - inset} ${w / 2 - inset} 0 0 1 ${x + w - inset} ${y + w / 2} L${x + w - inset} ${y + h - inset} L${x + inset} ${y + h - inset} Z`} fill={p.c(glass)} />
: <rect x={x + inset} y={y + inset} width={w - inset * 2} height={h - inset * 2} fill={p.c(glass)} />}
<path d={`M${x + inset} ${y + h - inset} L${x + w - inset} ${y + h - inset} L${x + w - inset} ${y + h * 0.45} Z`} fill={lit ? p.hi(glass, 0.3) : p.lo(glass, 0.25)} opacity={0.6} />
{!lit && <path d={`M${x + w * 0.25} ${y + h * 0.75} L${x + w * 0.55} ${y + h * 0.2} L${x + w * 0.68} ${y + h * 0.2} L${x + w * 0.38} ${y + h * 0.75} Z`} fill="#ffffff" opacity={0.18} />}
<rect x={x + w / 2 - 4} y={y + inset} width={8} height={h - inset * 2} fill={p.c(frame)} />
<rect x={x + inset} y={y + h * 0.48} width={w - inset * 2} height={8} fill={p.c(frame)} />
<rect x={x - 8} y={y + h - 4} width={w + 16} height={14} rx={3} fill={p.hi(frame, 0.2)} />
<rect x={x - 8} y={y + h + 10} width={w + 16} height={8} fill={p.lo(frame, 0.5)} opacity={0.6} />
</g>;
}
/** Linhas de telha num trapézio (um path só: fileiras + juntas desencontradas). */
function tiles(x0: number, x1: number, y0: number, y1: number, rows: number, inset: number): string {
let d = "";
for (let k = 1; k <= rows; k++) {
const t = k / rows;
const y = y0 + (y1 - y0) * t;
const l = x0 + inset * (1 - t);
const r = x1 - inset * (1 - t);
d += `M${l} ${y} L${r} ${y} `;
const yPrev = y0 + (y1 - y0) * ((k - 1) / rows);
for (let x = l + (k % 2 ? 22 : 0); x < r; x += 44) d += `M${x} ${y} L${x} ${yPrev + 6} `;
}
return d;
}
export const BUILT: Record<string, Draw> = {
house: (p, color) => {
const wall = color ?? mix(p.pal.near, "#f2e2c6", 0.45);
const roof = mix("#c4613a", p.pal.near, 0.15);
const lit = () => p.night && p.r() > 0.35;
const doorX = p.r() > 0.5 ? 60 : -170;
return <g>
{/* lado da casa (fundo, na sombra) */}
<polygon points="300,0 300,-460 392,-430 392,-14" fill={p.lo(wall, 0.42)} />
<polygon points="300,-460 392,-430 392,-400 300,-424" fill={p.lo(wall, 0.6)} />
<rect x={-300} y={-460} width={600} height={460} fill={p.c(wall)} />
<rect x={-300} y={-460} width={26} height={460} fill={p.hi(wall, 0.14)} />
{[[-240, -120, 70, 26], [140, -320, 90, 22], [-80, -380, 60, 18]].map(([x, y, w, h], i) => <rect key={i} x={x} y={y} width={w} height={h} rx={h / 2} fill={p.lo(wall, 0.14)} />)}
<rect x={-300} y={-36} width={600} height={36} fill={p.lo(wall, 0.38)} />
{/* telhado de telha: frente, quina iluminada à esquerda e água da direita na sombra */}
<polygon points="-350,-452 -235,-660 235,-660 350,-452" fill={p.c(roof)} />
<path d={tiles(-350, 350, -660, -452, 5, 115)} stroke={p.lo(roof, 0.4)} strokeWidth={5} fill="none" />
<polygon points="-350,-452 -235,-660 -205,-660 -300,-452" fill={p.hi(roof, 0.22)} />
<polygon points="235,-660 350,-452 430,-430 300,-640" fill={p.lo(roof, 0.4)} />
<rect x={-356} y={-458} width={712} height={16} rx={4} fill={p.lo(roof, 0.2)} />
<rect x={-300} y={-442} width={600} height={30} fill={p.lo(wall, 0.5)} opacity={0.8} />
<rect x={150} y={-720} width={54} height={90} fill={p.c(mix(roof, "#8a5a4a", 0.4))} /><rect x={184} y={-720} width={20} height={90} fill={p.lo(roof, 0.5)} />
{/* janelas e porta */}
{(doorX > 0 ? [-230, -60] : [-20, 160]).map((x) => <FacadeWindow key={x} x={x} y={-330} w={110} h={130} p={p} lit={lit()} />)}
<rect x={doorX - 12} y={-282} width={124} height={282} rx={4} fill={p.c("#efe6d6")} />
<rect x={doorX} y={-270} width={100} height={270} fill={p.c(mix("#7a4a2c", wall, 0.1))} />
<rect x={doorX + 74} y={-270} width={26} height={270} fill={p.lo("#7a4a2c", 0.4)} />
<rect x={doorX + 14} y={-250} width={60} height={90} rx={3} fill={p.lo("#7a4a2c", 0.25)} />
<circle cx={doorX + 80} cy={-130} r={7} fill={p.c("#e6c27a")} />
<rect x={doorX - 24} y={-12} width={148} height={12} fill={p.hi("#b0a898", 0.1)} />
</g>;
},
building: (p, color) => {
const floors = 4 + Math.floor(p.r() * 4);
const fh = 150;
const H = floors * fh;
const body = color ?? p.pal.far;
const rows = Array.from({ length: floors - 1 }, (_, f) => f);
return <g>
<polygon points={`210,0 210,${-H} 276,${-H + 26} 276,0`} fill={p.lo(body, 0.42)} />
<rect x={-210} y={-H} width={420} height={H} fill={p.c(body)} />
<rect x={-210} y={-H} width={22} height={H} fill={p.hi(body, 0.14)} />
<rect x={-224} y={-H - 26} width={448} height={30} fill={p.hi(body, 0.2)} />
<polygon points={`224,${-H - 26} 290,${-H} 290,${-H + 4} 224,${-H + 4}`} fill={p.lo(body, 0.5)} />
{rows.map((f) => <rect key={f} x={-210} y={-(f + 1) * fh - 6} width={420} height={8} fill={p.lo(body, 0.2)} />)}
{rows.flatMap((f) => [-160, -40, 80].map((x) => (
<FacadeWindow key={`${f}${x}`} x={x} y={-(f + 2) * fh + 28} w={80} h={90} p={p} lit={p.night ? p.r() > 0.55 : false} frame={mix(body, "#ffffff", 0.45)} />
)))}
<rect x={-70} y={-130} width={140} height={130} fill={p.c(mix(body, p.pal.ink, 0.6))} />
<rect x={-60} y={-120} width={120} height={120} fill={p.c(p.night ? mix(p.pal.light, "#ffb050", 0.3) : mix(p.pal.sky[1], p.pal.ink, 0.4))} opacity={0.85} />
<rect x={-96} y={-150} width={192} height={22} fill={p.c(mix(body, p.pal.ink, 0.35))} />
<rect x={-210} y={-20} width={420} height={20} fill={p.lo(body, 0.45)} />
</g>;
},
wall: (p, color) => {
// Muro comprido de reboco com capa por cima e pilares (passa da borda do quadro).
const w = color ?? mix(p.pal.near, "#c8885e", 0.5);
const patches = Array.from({ length: 7 }, () => [-660 + p.r() * 1260, -250 + p.r() * 190, 40 + p.r() * 90]);
return <g>
<rect x={-720} y={-300} width={1440} height={300} fill={p.c(w)} />
{patches.map(([x, y, s], i) => <rect key={i} x={x} y={y} width={s} height={s * 0.36} rx={s * 0.18} fill={i % 2 ? p.lo(w, 0.14) : p.hi(w, 0.14)} />)}
{[-540, -180, 180, 540].map((x) => <g key={x}><rect x={x - 26} y={-312} width={52} height={312} fill={p.c(w)} /><rect x={x + 8} y={-312} width={18} height={312} fill={p.lo(w, 0.3)} /></g>)}
<rect x={-730} y={-324} width={1460} height={28} rx={4} fill={p.hi(w, 0.22)} />
<rect x={-730} y={-300} width={1460} height={22} fill={p.lo(w, 0.5)} opacity={0.75} />
<rect x={-720} y={-34} width={1440} height={34} fill={p.lo(w, 0.4)} />
</g>;
},
facade: (p, color) => {
// Prédio público visto de frente: escadaria, colunas, frontão triangular.
const stone = color ?? "#e6dac2";
const back = p.lo(stone, 0.42);
const cols = [-400, -240, -80, 80, 240, 400];
return <g>
<rect x={-470} y={-690} width={940} height={600} fill={back} />
{[-320, -160, 0, 160, 320].map((x) => <path key={x} d={`M${x - 42} -180 L${x - 42} -470 A42 42 0 0 1 ${x + 42} -470 L${x + 42} -180 Z`} fill={p.c(mix(p.pal.sky[1], p.pal.ink, p.night ? 0.7 : 0.45))} />)}
{[-320, -160, 0, 160, 320].map((x) => <rect key={x} x={x - 42} y={-200} width={84} height={20} fill={p.lo(stone, 0.45)} />)}
{cols.map((x) => <g key={x}>
<rect x={x - 32} y={-660} width={64} height={560} fill={p.c(stone)} />
<rect x={x - 32} y={-660} width={14} height={560} fill={p.hi(stone, 0.3)} />
<rect x={x + 8} y={-660} width={24} height={560} fill={p.lo(stone, 0.42)} />
<rect x={x - 46} y={-686} width={92} height={28} rx={4} fill={p.hi(stone, 0.12)} />
<rect x={x + 18} y={-686} width={28} height={28} fill={p.lo(stone, 0.3)} />
<rect x={x - 44} y={-120} width={88} height={24} fill={p.c(stone)} /><rect x={x + 16} y={-120} width={28} height={24} fill={p.lo(stone, 0.3)} />
</g>)}
<rect x={-500} y={-770} width={1000} height={86} fill={p.c(stone)} />
<rect x={-500} y={-704} width={1000} height={20} fill={p.lo(stone, 0.35)} />
<rect x={-500} y={-770} width={1000} height={14} fill={p.hi(stone, 0.3)} />
<polygon points="-530,-770 0,-930 530,-770" fill={p.c(stone)} />
<polygon points="-440,-786 0,-904 440,-786" fill={p.lo(stone, 0.22)} />
<polygon points="0,-930 530,-770 500,-770 0,-916" fill={p.lo(stone, 0.4)} />
<polygon points="-530,-770 0,-930 0,-916 -500,-770" fill={p.hi(stone, 0.3)} />
{/* base e degraus */}
<rect x={-490} y={-100} width={980} height={30} fill={p.c(stone)} />
{[0, 1, 2].map((i) => <g key={i}>
<rect x={-520 - i * 30} y={-70 + i * 24} width={1040 + i * 60} height={24} fill={p.c(mix(stone, "#a8a090", 0.2))} />
<rect x={-520 - i * 30} y={-70 + i * 24} width={1040 + i * 60} height={6} fill={p.hi(stone, 0.35)} />
</g>)}
</g>;
},
shopfront: (p, color) => {
// Loja/oficina de rua: toldo listrado, letreiro em branco, porta de enrolar meio aberta e o interior escuro.
const wall = mix(p.pal.near, "#eeb04a", 0.75);
const awn = color ?? "#d65a3a";
const inside = mix(wall, p.pal.ink, 0.62);
const n = 9;
const stripe = 800 / n;
return <g>
<polygon points="400,0 400,-700 470,-670 470,-10" fill={p.lo(wall, 0.42)} />
<rect x={-400} y={-700} width={800} height={700} fill={p.c(wall)} />
<rect x={-400} y={-700} width={24} height={700} fill={p.hi(wall, 0.16)} />
{/* vão da garagem com ferramentas na parede do fundo */}
<rect x={-300} y={-420} width={600} height={420} fill={p.c(inside)} />
<rect x={-300} y={-420} width={600} height={60} fill={p.lo(inside, 0.4)} />
<rect x={40} y={-330} width={220} height={150} rx={6} fill={p.c(mix(inside, "#8a6a4a", 0.35))} />
{[70, 110, 150, 190, 230].map((x, i) => <rect key={x} x={x - 6} y={-310} width={12} height={i % 2 ? 90 : 70} rx={5} fill={p.c(i % 3 ? "#b8bcc4" : "#e8b030")} />)}
<rect x={-270} y={-200} width={200} height={14} fill={p.c(mix(inside, "#8a6a4a", 0.4))} />
{[0, 1].map((i) => <ellipse key={i} cx={-200 + i * 50} cy={-60 - i * 10} rx={60} ry={60} fill={p.c("#2a2a32")} />)}
{[0, 1].map((i) => <ellipse key={i} cx={-200 + i * 50} cy={-60 - i * 10} rx={26} ry={26} fill={p.c("#4a4a56")} />)}
<rect x={-300} y={-440} width={600} height={70} fill={p.c(mix(wall, "#c8c8cc", 0.6))} />
{[0, 1, 2, 3].map((i) => <rect key={i} x={-300} y={-432 + i * 16} width={600} height={4} fill={p.lo("#c8c8cc", 0.35)} />)}
<rect x={-312} y={-452} width={24} height={452} fill={p.hi(wall, 0.1)} /><rect x={288} y={-452} width={24} height={452} fill={p.lo(wall, 0.25)} />
{/* letreiro */}
<rect x={-340} y={-580} width={680} height={110} rx={10} fill={p.c("#f4ecdc")} />
<rect x={-340} y={-490} width={680} height={20} rx={6} fill={p.lo("#f4ecdc", 0.28)} />
{/* toldo listrado com a borda em ondas */}
<polygon points="-380,-700 380,-700 450,-610 -450,-610" fill={p.c(awn)} />
{Array.from({ length: n }, (_, i) => i % 2 === 1 && (
<polygon key={i} points={`${-380 + i * (760 / n)},-700 ${-380 + (i + 1) * (760 / n)},-700 ${-450 + (i + 1) * stripe * 1.125},-610 ${-450 + i * stripe * 1.125},-610`} fill={p.lo(awn, 0.2)} />
))}
{Array.from({ length: n }, (_, i) => <path key={i} d={`M${-450 + i * 100} -610 a50 26 0 0 0 100 0 Z`} fill={i % 2 ? p.lo(awn, 0.2) : p.c(awn)} />)}
<rect x={-450} y={-614} width={900} height={10} fill={p.lo(awn, 0.25)} />
<rect x={-400} y={-584} width={800} height={16} fill={p.lo(wall, 0.45)} opacity={0.7} />
<rect x={-400} y={-28} width={800} height={28} fill={p.lo(wall, 0.4)} />
</g>;
},
fence: (p, color) => {
const wood = color ?? mix(p.pal.trunk, "#d8c0a0", 0.35);
const xs = Array.from({ length: 13 }, (_, i) => -450 + i * 75);
const body = xs.map((x) => `M${x - 18} 0 L${x - 18} -200 L${x} -230 L${x + 18} -200 L${x + 18} 0 Z`).join(" ");
const side = xs.map((x) => `M${x + 6} 0 L${x + 6} -212 L${x} -230 L${x + 18} -200 L${x + 18} 0 Z`).join(" ");
return <g>
<rect x={-470} y={-170} width={940} height={26} fill={p.lo(wood, 0.35)} />
<rect x={-470} y={-70} width={940} height={26} fill={p.lo(wood, 0.35)} />
<path d={body} fill={p.c(wood)} />
<path d={side} fill={p.lo(wood, 0.36)} />
</g>;
},
bench: (p, color) => {
const wood = color ?? "#a0663e";
const iron = p.pal.ink;
return <g>
{[-200, 200].map((x) => <g key={x}>
<path d={`M${x - 16} 0 L${x - 10} -150 L${x + 10} -150 L${x + 16} 0 Z`} fill={p.c(mix(iron, "#555a66", 0.4))} />
<path d={`M${x - 6} -150 L${x - 2} -300 L${x + 14} -300 L${x + 10} -150 Z`} fill={p.c(mix(iron, "#555a66", 0.4))} />
</g>)}
<Box x={-260} y={-168} w={520} h={22} fill={wood} p={p} side={0.08} top={6} rx={5} />
<Box x={-260} y={-140} w={520} h={18} fill={mix(wood, "#000000", 0.1)} p={p} side={0.08} rx={5} />
{[-300, -250].map((y) => <Box key={y} x={-260} y={y} w={520} h={36} fill={wood} p={p} side={0.08} top={8} rx={6} />)}
<rect x={-260} y={-146} width={520} height={10} fill={p.lo(wood, 0.55)} opacity={0.7} />
</g>;
},
lamp: (p) => {
const pole = mix(p.pal.ink, "#4a5060", 0.35);
return <g>
{p.night && <path d="M-40 -780 L-260 0 L260 0 L40 -780 Z" fill={p.pal.light} opacity={0.07} />}
<rect x={-34} y={-60} width={68} height={60} rx={8} fill={p.c(pole)} />
<rect x={-12} y={-820} width={24} height={780} fill={p.c(pole)} /><rect x={2} y={-820} width={10} height={780} fill={p.lo(pole, 0.4)} />
<path d="M-56 -800 L56 -800 L40 -870 L-40 -870 Z" fill={p.c(p.night ? p.pal.light : mix(p.pal.sky[2], "#ffffff", 0.4))} />
<rect x={-64} y={-806} width={128} height={14} rx={5} fill={p.c(pole)} />
<path d="M-50 -870 L50 -870 L0 -904 Z" fill={p.c(pole)} /><path d="M0 -904 L50 -870 L20 -870 Z" fill={p.lo(pole, 0.4)} />
{p.night && <circle cx={0} cy={-836} r={90} fill={p.pal.light} opacity={0.12} />}
</g>;
},
gravestone: (p, color) => {
const s = color ?? p.pal.stone;
return <g>
<path d="M-110 0 L-110 -240 Q-110 -340 0 -340 Q110 -340 110 -240 L110 0 Z" fill={p.c(s)} />
<path d="M60 -330 Q110 -310 110 -240 L110 0 L68 0 L68 -240 Q68 -300 60 -330 Z" fill={p.lo(s, 0.38)} />
<path d="M-110 -240 Q-110 -330 -20 -340 Q-80 -320 -88 -240 Z" fill={p.hi(s, 0.2)} />
{[-230, -192, -156].map((y, i) => <rect key={y} x={-56 + i * 6} y={y} width={112 - i * 12} height={10} rx={5} fill={p.lo(s, 0.5)} />)}
<path d="M-130 0 Q-100 -30 -80 0 M90 0 Q110 -26 130 0" stroke={p.c(p.pal.leaf)} strokeWidth={10} fill="none" />
</g>;
},
cross: (p, color) => {
const s = color ?? p.pal.stone;
return <g>
<rect x={-24} y={-400} width={48} height={400} fill={p.c(s)} /><rect x={6} y={-400} width={18} height={400} fill={p.lo(s, 0.38)} />
<rect x={-120} y={-320} width={240} height={44} fill={p.c(s)} /><rect x={-120} y={-288} width={240} height={12} fill={p.lo(s, 0.45)} />
<rect x={-120} y={-320} width={240} height={8} fill={p.hi(s, 0.25)} />
</g>;
},
car: (p, color) => {
const c = color ?? "#c8443a";
const glass = mix(p.pal.sky[1], "#ffffff", 0.25);
return <g transform="scale(2.5)">
<path d="M-150 -40 L-150 -90 Q-140 -110 -100 -112 L-60 -160 L70 -160 L110 -112 L150 -100 L150 -40 Z" fill={p.c(c)} />
<path d="M-150 -74 L150 -74 L150 -40 L-150 -40 Z" fill={p.lo(c, 0.3)} />
<path d="M-100 -112 L-60 -160 L-40 -160 L-80 -112 Z" fill={p.hi(c, 0.25)} />
<path d="M-50 -150 L-4 -150 L-4 -114 L-78 -114 Z" fill={p.c(glass)} /><path d="M8 -150 L64 -150 L96 -114 L8 -114 Z" fill={p.lo(glass, 0.25)} />
<path d="M-30 -146 L-16 -146 L-34 -118 L-48 -118 Z" fill="#ffffff" opacity={0.5} />
<rect x={140} y={-96} width={12} height={14} rx={3} fill={p.c("#ffe6a0")} /><rect x={-152} y={-92} width={10} height={12} rx={3} fill={p.c("#e84a3a")} />
<rect x={-156} y={-48} width={312} height={10} rx={4} fill={p.lo(c, 0.5)} />
{[-90, 95].map((x) => <g key={x}><circle cx={x} cy={-35} r={32} fill={p.c("#1e1f26")} /><circle cx={x} cy={-35} r={15} fill={p.c("#9ea2ac")} /><circle cx={x + 4} cy={-33} r={8} fill={p.lo("#9ea2ac", 0.4)} /></g>)}
</g>;
},
sign: (p, color) => {
const c = color ?? "#2f6d3a";
return <g>
<rect x={-12} y={-440} width={24} height={440} fill={p.c(p.pal.ink)} /><rect x={2} y={-440} width={10} height={440} fill={p.lo(p.pal.ink, 0.3)} />
<rect x={-180} y={-540} width={360} height={150} rx={14} fill={p.c("#ffffff")} />
<rect x={-170} y={-530} width={340} height={130} rx={10} fill={p.c(c)} />
<rect x={-170} y={-430} width={340} height={30} rx={10} fill={p.lo(c, 0.3)} />
<rect x={-130} y={-500} width={200} height={14} rx={7} fill="#ffffff" opacity={0.55} /><rect x={-130} y={-472} width={140} height={14} rx={7} fill="#ffffff" opacity={0.4} />
</g>;
},
crate: (p, color) => {
const w = color ?? "#b0804a";
const dark = p.lo(w, 0.45);
return <g>
<polygon points="-130,-260 -92,-300 168,-300 130,-260" fill={p.hi(w, 0.25)} />
<polygon points="130,-260 168,-300 168,-38 130,0" fill={p.lo(w, 0.4)} />
<rect x={-130} y={-260} width={260} height={260} fill={p.c(w)} />
{[-195, -130, -65].map((y) => <rect key={y} x={-130} y={y} width={260} height={5} fill={dark} opacity={0.6} />)}
<path d="M-112 -242 L112 -18" stroke={p.c(mix(w, "#5a3a1a", 0.35))} strokeWidth={26} />
<path d="M-104 -250 L120 -26" stroke={dark} strokeWidth={6} />
<rect x={-130} y={-260} width={260} height={260} fill="none" stroke={p.c(mix(w, "#5a3a1a", 0.35))} strokeWidth={22} />
<rect x={108} y={-260} width={22} height={260} fill={dark} opacity={0.6} />
</g>;
},
tent: (p, color) => {
const c = color ?? "#d9773a";
return <g>
<path d="M-340 0 L0 -440 L340 0 Z" fill={p.c(c)} />
<path d="M0 -440 L340 0 L60 0 Z" fill={p.lo(c, 0.36)} />
<path d="M0 -440 L-340 0 L-300 0 Z" fill={p.hi(c, 0.25)} />
<path d="M-90 0 L0 -250 L90 0 Z" fill={p.c(mix(c, p.pal.ink, 0.75))} />
<path d="M0 -250 L-130 0 L-90 0 Z" fill={p.hi(c, 0.15)} />
<path d="M0 -440 L0 -480 M-340 0 L-420 -20 M340 0 L420 -20" stroke={p.c(p.pal.ink)} strokeWidth={6} />
</g>;
},
fire: (p) => <g>
<ellipse cx={0} cy={-8} rx={260} ry={40} fill={p.pal.light} opacity={0.22} />
<path d="M-110 -10 L100 -50 M-100 -50 L110 -10" stroke={p.c(p.pal.trunk)} strokeWidth={30} strokeLinecap="round" />
<path d="M-104 -16 L96 -54" stroke={p.lo(p.pal.trunk, 0.4)} strokeWidth={10} strokeLinecap="round" />
<path d="M-80 -30 Q-100 -150 -24 -230 Q-14 -150 34 -132 Q54 -210 18 -290 Q130 -200 86 -30 Z" fill="#e8562a" />
<path d="M-56 -32 Q-66 -120 -10 -180 Q0 -110 40 -100 Q54 -150 40 -200 Q100 -130 66 -32 Z" fill="#ff9a2a" />
<path d="M-24 -32 Q-34 -96 8 -130 Q16 -84 40 -76 Q48 -54 34 -32 Z" fill="#ffe066" />
</g>,
ark: (p, color) => {
// Arca: casco de tábuas com betume escuro embaixo, casa de um andar em cima com janelinhas e uma porta.
const wood = color ?? "#8a5a32";
const cabin = mix(wood, "#ffffff", 0.12);
return <g>
<path d="M-390 -150 L390 -150 Q362 -26 290 0 L-290 0 Q-362 -26 -390 -150 Z" fill={p.c(wood)} />
<path d="M-390 -150 L-340 -150 Q-330 -40 -270 0 L-290 0 Q-362 -26 -390 -150 Z" fill={p.hi(wood, 0.2)} />
<path d="M180 -150 L390 -150 Q362 -26 290 0 L160 0 Q200 -60 180 -150 Z" fill={p.lo(wood, 0.3)} />
<path d="M-370 -60 Q-330 -6 -290 0 L290 0 Q330 -6 370 -60 Z" fill={p.c("#3a2a22")} opacity={0.8} />
{[-120, -92, -64, -36].map((y) => <path key={y} d={`M${-386 + (y + 150) * 0.2} ${y} L${386 - (y + 150) * 0.2} ${y}`} stroke={p.lo(wood, 0.5)} strokeWidth={5} opacity={0.7} />)}
<rect x={-400} y={-162} width={800} height={18} rx={6} fill={p.hi(mix(wood, "#6b4426", 0.5), 0.2)} />
<rect x={-230} y={-290} width={460} height={130} fill={p.c(cabin)} />
<rect x={150} y={-290} width={80} height={130} fill={p.lo(cabin, 0.32)} />
{[-180, -110, -40, 30, 100].map((x) => <rect key={x} x={x} y={-262} width={34} height={26} rx={3} fill={p.c(mix(p.pal.ink, wood, 0.3))} />)}
<rect x={160} y={-224} width={56} height={64} rx={4} fill={p.lo("#4a2f1c", 0.3)} />
<polygon points="-262,-288 0,-352 262,-288" fill={p.c("#6a4428")} />
<polygon points="0,-352 262,-288 120,-288" fill={p.lo("#6a4428", 0.35)} />
</g>;
},
ark_frame: (p, color) => {
// Arca em construção: quilha, costelas curvas de madeira clara e só as primeiras fileiras de tábuas.
const wood = color ?? "#c9955a";
return <g>
<rect x={-380} y={-26} width={760} height={26} rx={6} fill={p.c("#7a5232")} />
{Array.from({ length: 11 }, (_, i) => {
const x = -330 + i * 66;
const k = 1 - Math.abs(x) / 420;
const d = `M${x} -20 Q${x * 1.02} ${-110 - k * 40} ${x * 1.14} ${-170 - k * 30}`;
return <g key={i}><path d={d} stroke={p.c(wood)} strokeWidth={16} fill="none" strokeLinecap="round" />
<path d={d} transform="translate(5 0)" stroke={p.lo(wood, 0.35)} strokeWidth={6} fill="none" strokeLinecap="round" /></g>;
})}
<path d="M-360 -60 Q-320 -12 -280 -14 L280 -14 Q320 -12 360 -60 L340 -92 Q300 -54 270 -56 L-270 -56 Q-300 -54 -340 -92 Z" fill={p.c("#8a5a32")} />
<path d="M-300 -34 L300 -34" stroke={p.lo("#8a5a32", 0.5)} strokeWidth={5} />
<rect x={-390} y={-200} width={780} height={12} rx={5} fill={p.c(wood)} />
<rect x={-390} y={-192} width={780} height={4} rx={2} fill={p.lo(wood, 0.4)} />
</g>;
},
scaffold: (p, color) => {
const wood = color ?? "#a87a48";
return <g strokeLinecap="round">
<path d="M-110 0 L-110 -330 M110 0 L110 -330" strokeWidth={14} stroke={p.c(wood)} />
<path d="M-104 0 L-104 -330 M116 0 L116 -330" strokeWidth={5} stroke={p.lo(wood, 0.4)} />
<path d="M-130 -120 L130 -120 M-130 -240 L130 -240" strokeWidth={18} stroke={p.c("#7a5232")} />
<path d="M-130 -114 L130 -114 M-130 -234 L130 -234" strokeWidth={6} stroke={p.lo("#7a5232", 0.4)} />
<path d="M-110 -10 L110 -120 M110 -130 L-110 -240" strokeWidth={8} stroke={p.c(wood)} opacity={0.85} />
</g>;
},
planks: (p, color) => {
const w = color ?? "#c9955a";
return <g>{[0, 1, 2, 3].map((i) => <Box key={i} x={-170 + (i % 2) * 22} y={-26 - i * 22} w={340 - i * 14} h={20} fill={i % 2 ? w : mix(w, "#000000", 0.12)} p={p} side={0.1} top={5} rx={4} />)}</g>;
},
};
/**
* Parte da FRENTE das peças que podem ter gente dentro (casco e amurada da arca; lataria abaixo das janelas do
* carro). Com `occupied: true` no lugar, ela é desenhada de novo POR CIMA dos personagens: eles ficam "dentro".
*/
export const FRONT_PART: Record<string, Draw> = {
ark: (p, color) => {
const wood = color ?? "#8a5a32";
return <g>
<path d="M-390 -150 L390 -150 Q362 -26 290 0 L-290 0 Q-362 -26 -390 -150 Z" fill={p.c(wood)} />
<path d="M-390 -150 L-340 -150 Q-330 -40 -270 0 L-290 0 Q-362 -26 -390 -150 Z" fill={p.hi(wood, 0.2)} />
<path d="M180 -150 L390 -150 Q362 -26 290 0 L160 0 Q200 -60 180 -150 Z" fill={p.lo(wood, 0.3)} />
<path d="M-370 -60 Q-330 -6 -290 0 L290 0 Q330 -6 370 -60 Z" fill={p.c("#3a2a22")} opacity={0.8} />
{[-120, -92, -64, -36].map((y) => <path key={y} d={`M${-386 + (y + 150) * 0.2} ${y} L${386 - (y + 150) * 0.2} ${y}`} stroke={p.lo(wood, 0.5)} strokeWidth={5} opacity={0.7} />)}
<rect x={-400} y={-162} width={800} height={18} rx={6} fill={p.hi(mix(wood, "#6b4426", 0.5), 0.2)} />
</g>;
},
car: (p, color) => {
const c = color ?? "#c8443a";
return <g transform="scale(2.5)">
<path d="M-150 -40 L-150 -90 Q-140 -110 -100 -112 L150 -100 L150 -40 Z" fill={p.c(c)} />
<path d="M-150 -74 L150 -74 L150 -40 L-150 -40 Z" fill={p.lo(c, 0.3)} />
<rect x={140} y={-96} width={12} height={14} rx={3} fill={p.c("#ffe6a0")} /><rect x={-152} y={-92} width={10} height={12} rx={3} fill={p.c("#e84a3a")} />
<rect x={-156} y={-48} width={312} height={10} rx={4} fill={p.lo(c, 0.5)} />
{[-90, 95].map((x) => <g key={x}><circle cx={x} cy={-35} r={32} fill={p.c("#1e1f26")} /><circle cx={x} cy={-35} r={15} fill={p.c("#9ea2ac")} /><circle cx={x + 4} cy={-33} r={8} fill={p.lo("#9ea2ac", 0.4)} /></g>)}
</g>;
},
};
+343
View File
@@ -0,0 +1,343 @@
// Peças de interior: porta, janela, mesa, cama, estante, arquivo, armários de metal, quadro, luminárias, escrivaninha,
// varal. Base em (0,0) no chão; as de parede (janela, quadro, varal) já desenham na altura certa acima do chão; a
// luminária pendente tem a origem no TETO (y cresce para baixo). Luz da esquerda.
import React from "react";
import { mix, type Paint } from "./paint";
import { Box } from "./built";
import type { Draw } from "./nature";
const BOOKS = ["#c8483a", "#e0a63a", "#3f78b8", "#4f9a6a", "#e8e0cc", "#7a4a8a", "#2f4a6a", "#b86a3a"];
const CLOTHES = ["#4f9a5a", "#e2b33a", "#c8483a", "#3f6aa8", "#e8e2d6", "#7f9a5a", "#8a5ab0"];
/** Taça de troféu (dourada), base no chão da prateleira. */
function Trophy({ x, y, s, p }: { x: number; y: number; s: number; p: Paint }) {
const g = "#d6a536";
return <g transform={`translate(${x} ${y}) scale(${s})`}>
<rect x={-24} y={-14} width={48} height={14} rx={2} fill={p.c(mix(g, "#5a4020", 0.4))} />
<rect x={-6} y={-40} width={12} height={28} fill={p.c(g)} />
<path d="M-34 -100 L34 -100 Q32 -52 0 -40 Q-32 -52 -34 -100 Z" fill={p.c(g)} />
<path d="M6 -100 L34 -100 Q32 -52 0 -40 Q14 -60 6 -100 Z" fill={p.lo(g, 0.38)} />
<path d="M-34 -92 Q-56 -88 -48 -70 Q-42 -60 -26 -62 M34 -92 Q56 -88 48 -70 Q42 -60 26 -62" stroke={p.c(g)} strokeWidth={6} fill="none" />
<rect x={-26} y={-96} width={8} height={30} rx={4} fill={p.hi(g, 0.5)} />
</g>;
}
/** O que vai numa prateleira (sorteado pela semente): livros, troféu, potes/caixas ou planta. */
function ShelfItems({ x0, x1, y, h, p }: { x0: number; x1: number; y: number; h: number; p: Paint }) {
const kind = p.r();
if (kind < 0.18) return <Trophy x={(x0 + x1) / 2 + (p.r() - 0.5) * 80} y={y} s={h / 110} p={p} />;
if (kind < 0.3) {
return <g>{[0, 1, 2].map((i) => {
const c = BOOKS[Math.floor(p.r() * BOOKS.length)];
const w = 60 + p.r() * 30;
const hh = h * (0.4 + p.r() * 0.35);
const x = x0 + 14 + i * ((x1 - x0) / 3);
return <g key={i}><rect x={x} y={y - hh} width={w} height={hh} rx={6} fill={p.c(c)} /><rect x={x + w * 0.7} y={y - hh} width={w * 0.3} height={hh} rx={4} fill={p.lo(c, 0.35)} /></g>;
})}</g>;
}
if (kind < 0.38) {
const pot = "#c0704a";
const cx = (x0 + x1) / 2;
return <g>
<path d={`M${cx - 40} ${y - 60} L${cx + 40} ${y - 60} L${cx + 30} ${y} L${cx - 30} ${y} Z`} fill={p.c(pot)} />
<path d={`M${cx + 10} ${y - 60} L${cx + 40} ${y - 60} L${cx + 30} ${y} L${cx + 8} ${y} Z`} fill={p.lo(pot, 0.35)} />
{[-50, -15, 20, 50].map((dx, i) => <ellipse key={i} cx={cx + dx} cy={y - 70 - (i % 2) * 30} rx={22} ry={44} transform={`rotate(${dx / 2} ${cx + dx} ${y - 70})`} fill={i % 2 ? p.lo(p.pal.leaf, 0.3) : p.c(p.pal.leaf)} />)}
</g>;
}
// Livros em pé, de alturas e cores variadas (às vezes um deitado no fim da fileira).
const books: React.ReactNode[] = [];
let x = x0 + 6;
while (x < x1 - 30) {
const w = 18 + p.r() * 16;
const hh = h * (0.62 + p.r() * 0.32);
const c = BOOKS[Math.floor(p.r() * BOOKS.length)];
books.push(<g key={x}><rect x={x} y={y - hh} width={w} height={hh} rx={2} fill={p.c(c)} /><rect x={x + w * 0.62} y={y - hh} width={w * 0.38} height={hh} fill={p.lo(c, 0.35)} />
<rect x={x} y={y - hh * 0.8} width={w} height={4} fill={p.hi(c, 0.4)} /></g>);
x += w + 2;
if (p.r() < 0.12) x += 24;
}
return <g>{books}</g>;
}
export const INDOOR: Record<string, Draw> = {
door: (p, color) => {
const d = color ?? "#6e4a30";
const trim = mix(p.pal.wall, "#f4ece0", 0.55);
return <g>
<rect x={-172} y={-664} width={344} height={664} rx={6} fill={p.c(trim)} />
<rect x={140} y={-664} width={32} height={664} fill={p.lo(trim, 0.3)} />
<rect x={-150} y={-640} width={300} height={640} fill={p.c(d)} />
<rect x={110} y={-640} width={40} height={640} fill={p.lo(d, 0.35)} />
{[[-600, 250], [-320, 270]].map(([y, h]) => <g key={y}>
<rect x={-112} y={y} width={200} height={h} rx={4} fill={p.lo(d, 0.16)} />
<rect x={-112} y={y} width={12} height={h} fill={p.lo(d, 0.42)} /><rect x={-112} y={y} width={200} height={10} fill={p.lo(d, 0.42)} />
<rect x={76} y={y} width={12} height={h} fill={p.hi(d, 0.25)} /><rect x={-112} y={y + h - 10} width={200} height={10} fill={p.hi(d, 0.25)} />
</g>)}
<rect x={96} y={-350} width={22} height={70} rx={8} fill={p.c("#c9a560")} />
<circle cx={107} cy={-316} r={12} fill={p.hi("#e6c27a", 0.3)} />
</g>;
},
window: (p, color) => {
// Janela na parede: moldura, céu lá fora (claro de dia, escuro com lua à noite), copa de árvore, cortinas.
const trim = mix(p.pal.wall, "#f4ece0", 0.6);
const out = color ?? (p.night ? "#1c2a5a" : mix(p.pal.sky[2], "#ffffff", 0.25));
const outTop = p.night ? "#121c44" : mix(p.pal.sky[1], "#ffffff", 0.2);
const curtain = p.r() > 0.45 ? ["#b8483a", "#3f6aa8", "#c89a3a", "#6a8a4a"][Math.floor(p.r() * 4)] : null;
return <g>
<rect x={-210} y={-640} width={420} height={420} rx={6} fill={p.c(trim)} />
<rect x={180} y={-640} width={30} height={420} fill={p.lo(trim, 0.3)} />
<rect x={-186} y={-616} width={372} height={372} fill={p.c(out)} />
<rect x={-186} y={-616} width={372} height={170} fill={p.c(outTop)} />
{p.night && <circle cx={-90} cy={-540} r={30} fill={p.c("#f4ecc8")} />}
<g fill={p.night ? p.c("#1a3040") : p.c(mix(p.pal.leaf, out, 0.35))}>
<circle cx={-140} cy={-300} r={90} /><circle cx={-40} cy={-280} r={70} /><circle cx={120} cy={-290} r={80} /><circle cx={-170} cy={-380} r={60} />
</g>
<path d="M-120 -616 L-40 -616 L-186 -380 L-186 -510 Z" fill="#ffffff" opacity={0.14} />
<rect x={-8} y={-616} width={16} height={372} fill={p.c(trim)} /><rect x={-186} y={-438} width={372} height={16} fill={p.c(trim)} />
<rect x={2} y={-616} width={6} height={372} fill={p.lo(trim, 0.3)} />
<rect x={-232} y={-236} width={464} height={26} rx={5} fill={p.hi(trim, 0.2)} />
<rect x={-224} y={-210} width={448} height={14} fill={p.lo(p.pal.wall, 0.45)} opacity={0.7} />
{curtain && [-1, 1].map((s) => <g key={s}>
<path d={`M${s * 190} -666 L${s * 270} -666 L${s * 290} -200 L${s * 200} -200 Q${s * 214} -440 ${s * 190} -666 Z`} fill={p.c(curtain)} />
<path d={`M${s * 236} -666 L${s * 270} -666 L${s * 290} -200 L${s * 250} -200 Z`} fill={s > 0 ? p.lo(curtain, 0.35) : p.hi(curtain, 0.18)} />
<path d={`M${s * 214} -640 L${s * 224} -210`} stroke={p.lo(curtain, 0.3)} strokeWidth={6} />
</g>)}
{curtain && <rect x={-300} y={-680} width={600} height={16} rx={8} fill={p.c(mix(p.pal.trunk, "#8a6a4a", 0.3))} />}
</g>;
},
table: (p, color) => {
const w = color ?? "#9a643c";
return <g>
{[-236, 220].map((x) => <rect key={x} x={x} y={-300} width={18} height={270} fill={p.lo(w, 0.5)} />)}
<polygon points="-280,-270 280,-270 250,-304 -250,-304" fill={p.hi(w, 0.22)} />
<rect x={-280} y={-270} width={560} height={28} fill={p.c(w)} />
<rect x={-280} y={-248} width={560} height={6} fill={p.lo(w, 0.45)} />
<rect x={236} y={-270} width={44} height={28} fill={p.lo(w, 0.32)} />
{[-262, 236].map((x) => <g key={x}><rect x={x} y={-242} width={26} height={242} fill={p.c(w)} /><rect x={x + 14} y={-242} width={12} height={242} fill={p.lo(w, 0.38)} /></g>)}
</g>;
},
bed: (p, color) => {
const blanket = color ?? "#4f64a8";
const wood = mix(p.pal.trunk, "#9a6a40", 0.4);
const sheet = "#ecebe6";
return <g>
<path d="M-390 0 L-390 -330 Q-390 -380 -350 -380 Q-320 -380 -320 -330 L-320 0 Z" fill={p.c(wood)} />
<rect x={-340} y={-380} width={20} height={380} fill={p.lo(wood, 0.35)} />
<rect x={-330} y={-118} width={680} height={50} fill={p.c(wood)} /><rect x={-330} y={-80} width={680} height={12} fill={p.lo(wood, 0.4)} />
<rect x={-320} y={-210} width={660} height={96} rx={18} fill={p.c(sheet)} />
<rect x={-312} y={-262} width={160} height={64} rx={28} fill={p.hi(sheet, 0.2)} />
<path d="M-180 -262 Q-160 -230 -168 -200" stroke={p.lo(sheet, 0.3)} strokeWidth={6} fill="none" />
<path d="M-120 -222 Q100 -238 344 -214 L350 -96 Q120 -88 -120 -100 Z" fill={p.c(blanket)} />
<path d="M-120 -222 Q100 -238 344 -214 L344 -196 Q100 -214 -120 -204 Z" fill={p.hi(blanket, 0.25)} />
<path d="M0 -224 Q20 -160 -10 -100 M150 -228 Q180 -170 160 -94" stroke={p.lo(blanket, 0.35)} strokeWidth={10} fill="none" strokeLinecap="round" />
<rect x={300} y={-216} width={50} height={120} fill={p.lo(blanket, 0.3)} />
<rect x={340} y={-260} width={36} height={260} rx={6} fill={p.c(wood)} /><rect x={360} y={-260} width={16} height={260} fill={p.lo(wood, 0.4)} />
{[-310, 320].map((x) => <rect key={x} x={x} y={-70} width={22} height={70} fill={p.lo(wood, 0.3)} />)}
</g>;
},
shelf: (p, color) => {
const w = color ?? mix(p.pal.trunk, "#8a5a36", 0.4);
const back = p.lo(w, 0.55);
const ys = [-616, -466, -316, -166];
return <g>
<polygon points="200,0 200,-640 236,-664 236,-16" fill={p.lo(w, 0.42)} />
<rect x={-200} y={-640} width={400} height={640} fill={p.c(w)} />
<rect x={-176} y={-616} width={352} height={590} fill={back} />
{ys.map((y) => <g key={y}>
<rect x={-176} y={y + 122} width={352} height={14} fill={p.lo(w, 0.7)} opacity={0.5} />
<ShelfItems x0={-170} x1={170} y={y + 128} h={118} p={p} />
<rect x={-180} y={y + 128} width={360} height={22} fill={p.c(w)} />
<rect x={-180} y={y + 128} width={360} height={6} fill={p.hi(w, 0.3)} />
</g>)}
<rect x={-200} y={-640} width={24} height={640} fill={p.hi(w, 0.14)} />
<rect x={176} y={-640} width={24} height={640} fill={p.lo(w, 0.25)} />
<rect x={-214} y={-664} width={428} height={28} rx={4} fill={p.hi(w, 0.18)} />
<polygon points="214,-664 250,-686 250,-662 214,-636" fill={p.lo(w, 0.5)} />
</g>;
},
cabinet: (p, color) => {
// Arquivo/armário de gavetas.
const m = color ?? "#6f7f8a";
return <g>
<polygon points="150,0 150,-560 192,-584 192,-18" fill={p.lo(m, 0.42)} />
<polygon points="-150,-560 -108,-584 192,-584 150,-560" fill={p.hi(m, 0.3)} />
<rect x={-150} y={-560} width={300} height={560} fill={p.c(m)} />
{[0, 1, 2, 3].map((i) => {
const y = -540 + i * 132;
return <g key={i}>
<rect x={-130} y={y} width={260} height={118} rx={5} fill={p.c(mix(m, "#ffffff", 0.06))} />
<rect x={-130} y={y + 108} width={260} height={10} fill={p.lo(m, 0.4)} />
<rect x={-130} y={y} width={260} height={6} fill={p.hi(m, 0.25)} />
<rect x={-34} y={y + 26} width={68} height={26} rx={3} fill={p.c("#ece6d4")} />
<rect x={-46} y={y + 64} width={92} height={16} rx={8} fill={p.lo(m, 0.55)} />
<rect x={-46} y={y + 64} width={92} height={6} rx={3} fill={p.hi(m, 0.4)} />
</g>;
})}
<rect x={118} y={-560} width={32} height={560} fill={p.lo(m, 0.25)} />
</g>;
},
locker: (p, color) => {
// Fileira de 3 armários de metal (vestiário, escola, fábrica).
const m = color ?? "#3f5f8c";
return <g>
<polygon points="300,0 300,-760 340,-784 340,-20" fill={p.lo(m, 0.45)} />
<polygon points="-300,-760 -260,-784 340,-784 300,-760" fill={p.hi(m, 0.25)} />
<rect x={-300} y={-760} width={600} height={760} fill={p.lo(m, 0.3)} />
{[-1, 0, 1].map((k) => {
const x = k * 198 - 96;
return <g key={k}>
<rect x={x} y={-744} width={192} height={680} rx={4} fill={p.c(m)} />
<rect x={x + 160} y={-744} width={32} height={680} fill={p.lo(m, 0.28)} />
<rect x={x} y={-744} width={192} height={6} fill={p.hi(m, 0.3)} />
{[0, 1, 2, 3].map((i) => <rect key={i} x={x + 36} y={-700 + i * 26} width={110} height={12} rx={6} fill={p.lo(m, 0.55)} />)}
{[0, 1, 2].map((i) => <rect key={i} x={x + 36} y={-150 + i * 26} width={110} height={12} rx={6} fill={p.lo(m, 0.55)} />)}
<rect x={x + 150} y={-430} width={16} height={86} rx={8} fill={p.hi(m, 0.4)} />
<rect x={x + 60} y={-560} width={56} height={34} rx={4} fill={p.c("#ece6d4")} opacity={0.85} />
</g>;
})}
<rect x={-300} y={-64} width={600} height={64} fill={p.lo(m, 0.5)} />
</g>;
},
frame: (p, color) => {
// Quadro na parede (paisagem, foto de grupo, retrato ou abstrato).
const f = color ?? "#9a6a3a";
const kind = Math.floor(p.r() * 4);
const x = -170;
const y = -700;
const w = 340;
const h = 260;
const ix = x + 26;
const iy = y + 26;
const iw = w - 52;
const ih = h - 52;
const sepia = mix("#d8c8a0", p.pal.wall, 0.15);
const pic: React.ReactNode =
kind === 0 ? <g>
<rect x={ix} y={iy} width={iw} height={ih} fill={p.c(mix(p.pal.sky[1], "#ffffff", 0.3))} />
<circle cx={ix + iw * 0.25} cy={iy + ih * 0.3} r={22} fill={p.c("#ffe08a")} />
<path d={`M${ix} ${iy + ih} L${ix} ${iy + ih * 0.62} Q${ix + iw * 0.3} ${iy + ih * 0.4} ${ix + iw * 0.55} ${iy + ih * 0.62} Q${ix + iw * 0.8} ${iy + ih * 0.45} ${ix + iw} ${iy + ih * 0.6} L${ix + iw} ${iy + ih} Z`} fill={p.c("#6a9a5a")} />
<path d={`M${ix + iw * 0.55} ${iy + ih * 0.62} Q${ix + iw * 0.8} ${iy + ih * 0.45} ${ix + iw} ${iy + ih * 0.6} L${ix + iw} ${iy + ih} L${ix + iw * 0.5} ${iy + ih} Z`} fill={p.lo("#6a9a5a", 0.3)} />
</g>
: kind === 1 ? <g>
<rect x={ix} y={iy} width={iw} height={ih} fill={p.c(sepia)} />
{[0, 1, 2, 3, 4].map((i) => {
const cx = ix + 40 + i * ((iw - 80) / 4);
return <g key={i} fill={p.lo(sepia, 0.55)}><circle cx={cx} cy={iy + ih * 0.42} r={17} /><rect x={cx - 24} y={iy + ih * 0.42 + 18} width={48} height={ih * 0.4} rx={14} /></g>;
})}
<rect x={ix} y={iy + ih * 0.86} width={iw} height={ih * 0.14} fill={p.lo(sepia, 0.3)} />
</g>
: kind === 2 ? <g>
<rect x={ix} y={iy} width={iw} height={ih} fill={p.c("#c8b490")} />
<circle cx={ix + iw / 2} cy={iy + ih * 0.42} r={40} fill={p.lo("#c8b490", 0.5)} />
<path d={`M${ix + iw / 2 - 80} ${iy + ih} Q${ix + iw / 2} ${iy + ih * 0.55} ${ix + iw / 2 + 80} ${iy + ih} Z`} fill={p.lo("#c8b490", 0.5)} />
</g>
: <g>
<rect x={ix} y={iy} width={iw} height={ih} fill={p.c("#ece2cc")} />
<rect x={ix + 20} y={iy + 20} width={iw * 0.45} height={ih * 0.5} fill={p.c("#c8483a")} />
<rect x={ix + iw * 0.55} y={iy + ih * 0.35} width={iw * 0.35} height={ih * 0.5} fill={p.c("#3f6aa8")} />
<circle cx={ix + iw * 0.4} cy={iy + ih * 0.7} r={30} fill={p.c("#e2b33a")} />
</g>;
return <g>
<rect x={x + 14} y={y + 16} width={w} height={h} rx={4} fill={p.pal.ink} opacity={0.22} />
<rect x={x} y={y} width={w} height={h} rx={4} fill={p.c(f)} />
<rect x={x} y={y} width={w} height={10} fill={p.hi(f, 0.3)} /><rect x={x} y={y} width={10} height={h} fill={p.hi(f, 0.3)} />
<rect x={x + w - 12} y={y} width={12} height={h} fill={p.lo(f, 0.38)} /><rect x={x} y={y + h - 12} width={w} height={12} fill={p.lo(f, 0.38)} />
{pic}
<rect x={ix} y={iy} width={iw} height={8} fill={p.pal.ink} opacity={0.2} /><rect x={ix} y={iy} width={8} height={ih} fill={p.pal.ink} opacity={0.15} />
</g>;
},
pendant: (p, color) => {
// Luminária pendente: origem no teto, fio descendo, cúpula e a lâmpada acesa por baixo.
const s = color ?? "#2f3f6a";
return <g>
<rect x={-3} y={-20} width={6} height={290} fill={p.c(p.pal.ink)} />
<rect x={-18} y={250} width={36} height={24} rx={4} fill={p.c(mix(s, p.pal.ink, 0.3))} />
<circle cx={0} cy={372} r={150} fill={p.pal.light} opacity={0.14} />
<path d="M-130 370 Q-124 272 0 266 Q124 272 130 370 Z" fill={p.c(s)} />
<path d="M30 268 Q124 274 130 370 L60 370 Q66 300 30 268 Z" fill={p.lo(s, 0.38)} />
<path d="M-104 352 Q-104 296 -40 276 Q-84 300 -84 352 Z" fill={p.hi(s, 0.3)} />
<ellipse cx={0} cy={370} rx={130} ry={20} fill={p.pal.light} />
<ellipse cx={0} cy={376} rx={44} ry={24} fill="#fffbe8" />
</g>;
},
desklamp: (p, color) => {
// Luminária de mesa articulada, acesa (poça de luz na base). Fica em cima de mesa/escrivaninha próxima.
const m = color ?? "#5f7a4a";
return <g>
<path d="M40 -250 L240 0 L-40 0 L-10 -230 Z" fill={p.pal.light} opacity={0.16} />
<ellipse cx={100} cy={-4} rx={150} ry={22} fill={p.pal.light} opacity={0.3} />
<ellipse cx={-60} cy={-12} rx={70} ry={16} fill={p.c(m)} /><rect x={-130} y={-12} width={140} height={12} fill={p.lo(m, 0.35)} />
<path d="M-60 -16 L-100 -200 M-100 -200 L20 -300" stroke={p.c(m)} strokeWidth={18} strokeLinecap="round" fill="none" />
<path d="M-54 -18 L-94 -198" stroke={p.lo(m, 0.4)} strokeWidth={6} strokeLinecap="round" />
<circle cx={-100} cy={-200} r={16} fill={p.lo(m, 0.3)} />
<g transform="translate(20 -300) rotate(35)">
<path d="M-30 -30 L30 -30 L80 60 L-80 60 Z" fill={p.c(m)} />
<path d="M10 -30 L30 -30 L80 60 L40 60 Z" fill={p.lo(m, 0.4)} />
<ellipse cx={0} cy={60} rx={80} ry={14} fill={p.pal.light} />
<ellipse cx={0} cy={62} rx={30} ry={10} fill="#fffbe8" />
</g>
</g>;
},
desk: (p, color) => {
// Escrivaninha de 2 gaveteiros, com papéis, livros e caneca por cima.
const w = color ?? "#8a5a36";
const knob = "#d8b060";
return <g>
<rect x={-110} y={-276} width={220} height={236} fill={p.lo(w, 0.62)} />
{[-310, 110].map((x) => <g key={x}>
<rect x={x} y={-276} width={200} height={276} fill={p.c(w)} />
<rect x={x + 170} y={-276} width={30} height={276} fill={p.lo(w, 0.3)} />
{[0, 1, 2].map((i) => <g key={i}>
<rect x={x + 14} y={-262 + i * 86} width={172} height={74} rx={4} fill={p.c(mix(w, "#ffffff", 0.05))} />
<rect x={x + 14} y={-196 + i * 86} width={172} height={8} fill={p.lo(w, 0.45)} />
<circle cx={x + 100} cy={-226 + i * 86} r={11} fill={p.hi(knob, 0.2)} /><circle cx={x + 104} cy={-223 + i * 86} r={5} fill={p.lo(knob, 0.4)} />
</g>)}
</g>)}
<polygon points="-330,-300 330,-300 304,-330 -304,-330" fill={p.hi(w, 0.22)} />
<rect x={-330} y={-300} width={660} height={26} fill={p.c(w)} /><rect x={-330} y={-280} width={660} height={6} fill={p.lo(w, 0.5)} />
<rect x={290} y={-300} width={40} height={26} fill={p.lo(w, 0.32)} />
<g transform={`translate(${p.r() > 0.5 ? 90 : -230} -312)`}>
{[0, 1, 2].map((i) => <rect key={i} x={i * 4} y={-i * 7} width={130} height={8} rx={2} fill={p.c(i % 2 ? "#f2eee4" : "#e2dccc")} />)}
</g>
<g transform="translate(200 -312)">
<rect x={0} y={-30} width={100} height={30} rx={3} fill={p.c("#3f6aa8")} /><rect x={6} y={-54} width={90} height={24} rx={3} fill={p.c("#c8483a")} />
<rect x={70} y={-30} width={30} height={30} fill={p.lo("#3f6aa8", 0.35)} />
</g>
<g transform="translate(-90 -312)">
<rect x={-22} y={-48} width={44} height={48} rx={6} fill={p.c("#ece6d8")} /><rect x={6} y={-48} width={16} height={48} fill={p.lo("#ece6d8", 0.3)} />
<path d="M22 -38 Q42 -30 22 -14" stroke={p.c("#ece6d8")} strokeWidth={7} fill="none" />
</g>
</g>;
},
clothesline: (p, color) => {
// Varal: corda com roupas presas. Ao ar livre tem dois postes; dentro de casa fica preso na parede.
const rope = mix(p.pal.trunk, "#c8b08a", 0.5);
// Dentro de casa a corda vai de parede a parede (mais alta e mais comprida, sem postes).
const y0 = p.indoor ? -880 : -720;
const half = p.indoor ? 720 : 500;
const yAt = (t: number) => y0 + 120 * t * (1 - t);
const items = p.indoor ? [0.12, 0.25, 0.38, 0.51, 0.64, 0.77, 0.9] : [0.1, 0.26, 0.42, 0.58, 0.74, 0.9];
return <g>
{!p.indoor && [-500, 500].map((x) => <g key={x}><rect x={x - 14} y={-760} width={28} height={760} fill={p.c(p.pal.trunk)} /><rect x={x + 2} y={-760} width={12} height={760} fill={p.lo(p.pal.trunk, 0.4)} /></g>)}
<path d={`M${-half} ${y0} Q0 ${y0 + 120} ${half} ${y0}`} stroke={p.c(rope)} strokeWidth={6} fill="none" />
{items.map((t, i) => {
const x = -half + 2 * half * t;
const y = yAt(t);
const c = color && i % 2 === 0 ? color : CLOTHES[Math.floor(p.r() * CLOTHES.length)];
const towel = p.r() < 0.3;
const tilt = (t - 0.5) * 10;
return <g key={i} transform={`translate(${x} ${y - 4}) rotate(${tilt})`}>
{towel
? <g><rect x={-46} y={0} width={92} height={150} rx={4} fill={p.c(c)} /><rect x={18} y={0} width={28} height={150} fill={p.lo(c, 0.35)} />
<rect x={-46} y={120} width={92} height={10} fill={p.hi(c, 0.4)} /></g>
: <g>
<path d="M-40 0 L-86 26 L-68 64 L-46 54 L-46 168 L46 168 L46 54 L68 64 L86 26 L40 0 Q0 18 -40 0 Z" fill={p.c(c)} />
<path d="M14 8 L40 0 L86 26 L68 64 L46 54 L46 168 L14 168 Z" fill={p.lo(c, 0.35)} />
<path d="M-40 0 Q0 18 40 0 L28 -2 Q0 10 -28 -2 Z" fill={p.hi(c, 0.5)} />
</g>}
<rect x={-30} y={-12} width={10} height={22} rx={2} fill={p.c("#c8a070")} /><rect x={20} y={-12} width={10} height={22} rx={2} fill={p.c("#c8a070")} />
</g>;
})}
</g>;
},
};
+142
View File
@@ -0,0 +1,142 @@
// Peças da natureza: árvores, mato, pedras, montanha, nuvem, palmeira, ondas. Base em (0,0); luz da esquerda.
import React from "react";
import { mix, type Paint } from "./paint";
export type Draw = (p: Paint, color?: string) => React.ReactNode;
type Blob = [number, number, number];
/** Copa/moita/nuvem em 2 tons: tudo na cor da sombra, a parte de cima-esquerda na base e brilho nos topos. */
export function Foliage({ blobs, color, p, shadeK = 0.5, hiK = 0.14, lift = 0.16 }: { blobs: Blob[]; color: string; p: Paint; shadeK?: number; hiK?: number; lift?: number }) {
const cx = blobs.reduce((s, b) => s + b[0], 0) / blobs.length;
const cy = blobs.reduce((s, b) => s + b[1], 0) / blobs.length;
const top = Math.min(...blobs.map((b) => b[1] - b[2]));
return (
<g>
<g fill={p.lo(color, shadeK)}>{blobs.map(([x, y, r], i) => <circle key={i} cx={x} cy={y} r={r} />)}</g>
<g fill={p.c(color)}>{blobs.map(([x, y, r], i) => <circle key={i} cx={x - r * lift * 0.8} cy={y - r * lift} r={r * 0.8} />)}</g>
{hiK > 0 && <g fill={p.hi(color, hiK)}>
{blobs.filter(([x, y, r]) => x <= cx + 40 && y - r <= top + (cy - top) * 0.5).map(([x, y, r], i) => <circle key={i} cx={x - r * 0.24} cy={y - r * 0.3} r={r * 0.6} />)}
</g>}
</g>
);
}
const jitter = (p: Paint, blobs: Blob[], k = 1): Blob[] => blobs.map(([x, y, s]) => [x + (p.r() - 0.5) * 36 * k, y + (p.r() - 0.5) * 28 * k, s * (0.9 + p.r() * 0.2)]);
export const NATURE: Record<string, Draw> = {
tree: (p, color) => {
const leaf = color ?? p.pal.leaf;
const bark = p.pal.trunk;
const blobs = jitter(p, [[-210, -560, 150], [205, -575, 150], [0, -520, 170], [-100, -700, 175], [120, -710, 170], [5, -840, 150],
[-285, -660, 110], [285, -670, 105], [0, -660, 200]]);
return <g>
<path d="M-56 0 Q-30 -10 -30 -200 L-28 -400 L28 -400 Q30 -200 32 -10 Q50 0 62 0 Z" fill={p.c(bark)} />
<path d="M6 -2 Q20 -150 16 -400 L28 -400 Q30 -200 32 -10 Q50 0 62 0 Z" fill={p.lo(bark, 0.4)} />
<path d="M-12 -330 Q-90 -420 -170 -520 M8 -360 Q70 -460 150 -560 M0 -380 L-6 -560" stroke={p.c(bark)} strokeWidth={30} strokeLinecap="round" fill="none" />
<path d="M14 -364 Q76 -456 156 -552" stroke={p.lo(bark, 0.4)} strokeWidth={12} strokeLinecap="round" fill="none" />
<path d="M-20 -60 Q-14 -120 -18 -180 M-4 -240 Q2 -280 -2 -320" stroke={p.lo(bark, 0.3)} strokeWidth={5} strokeLinecap="round" fill="none" />
<Foliage blobs={blobs} color={leaf} p={p} />
</g>;
},
pine: (p, color) => {
const leaf = color ?? mix(p.pal.leaf, "#1f5a46", 0.35);
const tiers: [number, number, number][] = [[-200, -90, -440], [-165, -300, -640], [-125, -500, -840]];
return <g>
<rect x={-22} y={-110} width={44} height={110} fill={p.c(p.pal.trunk)} />
<rect x={4} y={-110} width={18} height={110} fill={p.lo(p.pal.trunk, 0.4)} />
{tiers.map(([w, b, t], i) => <g key={i}>
<polygon points={`0,${t} ${w},${b} ${-w},${b}`} fill={p.c(leaf)} />
<polygon points={`0,${t} ${-w},${b} ${-w * 0.1},${b}`} fill={p.lo(leaf, 0.42)} />
<polygon points={`0,${t} ${w * 0.55},${b - (b - t) * 0.42} ${w * 0.25},${b - (b - t) * 0.4}`} fill={p.hi(leaf, 0.2)} />
<path d={`M${w} ${b} L${-w} ${b} L${-w * 0.92} ${b - 18} L${w * 0.92} ${b - 18} Z`} fill={p.lo(leaf, 0.55)} />
</g>)}
</g>;
},
deadtree: (p, color) => {
const bark = color ?? p.pal.trunk;
return <g strokeLinecap="round" fill="none">
<g stroke={p.c(bark)}>
<path d="M0 0 L0 -440" strokeWidth={52} />
<path d="M0 -240 L-140 -400 M-80 -320 L-160 -300 M0 -340 L120 -500 M60 -420 L160 -430 M0 -440 L-40 -560" strokeWidth={24} />
</g>
<g stroke={p.lo(bark, 0.45)}>
<path d="M14 0 L14 -430" strokeWidth={18} />
<path d="M8 -346 L124 -496" strokeWidth={9} />
</g>
<path d="M-30 0 Q-60 4 -80 0 M30 0 Q60 4 84 0" stroke={p.c(bark)} strokeWidth={20} />
</g>;
},
bush: (p, color) => <Foliage blobs={jitter(p, [[-90, -70, 85], [15, -105, 105], [115, -66, 80], [-165, -42, 56], [180, -38, 52], [40, -50, 70]], 0.6)} color={color ?? p.pal.leaf} p={p} />,
rock: (p, color) => {
const s = color ?? p.pal.stone;
return <g>
<path d="M-120 0 Q-138 -84 -52 -118 Q34 -150 104 -84 Q146 -34 120 0 Z" fill={p.c(s)} />
<path d="M30 -134 Q96 -116 114 -66 Q140 -30 120 0 L6 0 Q44 -64 30 -134 Z" fill={p.lo(s, 0.38)} />
<path d="M-106 -40 Q-110 -98 -44 -116 Q-16 -124 6 -122 Q-44 -100 -66 -40 Z" fill={p.hi(s, 0.25)} />
</g>;
},
mountain: (p, color) => {
const m = color ?? p.pal.far;
return <g>
<polygon points="-520,0 -60,-470 0,-520 70,-460 520,0" fill={p.c(m)} />
<polygon points="0,-520 70,-460 520,0 80,0 150,-140 40,-260 60,-380" fill={p.lo(m, 0.3)} />
<polygon points="-60,-470 0,-520 -40,-400 -140,-250 -260,-150 -150,-300" fill={p.hi(m, 0.12)} />
<polygon points="-110,-410 -60,-470 0,-520 70,-460 110,-410 50,-432 10,-396 -40,-436" fill={p.c("#ffffff")} opacity={0.85} />
<polygon points="0,-520 70,-460 110,-410 50,-432 22,-410" fill={p.lo("#e8ecf4", 0.3)} opacity={0.85} />
</g>;
},
cloud: (p, color) => {
const base = color ?? mix("#ffffff", p.pal.light, 0.12);
return <g opacity={0.95}>
<Foliage blobs={[[-80, -50, 52], [0, -78, 66], [78, -52, 50], [-140, -34, 34], [140, -32, 32]]} color={base} p={p} shadeK={0.2} hiK={0} lift={0.22} />
<rect x={-174} y={-34} width={348} height={34} rx={17} fill={p.lo(base, 0.22)} />
</g>;
},
palm: (p, color) => {
const leaf = color ?? p.pal.leaf;
const bark = mix(p.pal.trunk, "#b08a5a", 0.35);
const fronds: [number, number][] = [[-250, -470], [-210, -600], [-40, -700], [150, -650], [270, -500], [60, -560]];
return <g>
<path d="M-22 0 Q-40 -260 20 -560 L52 -556 Q2 -260 26 0 Z" fill={p.c(bark)} />
<path d="M8 0 Q-6 -260 40 -558 L52 -556 Q2 -260 26 0 Z" fill={p.lo(bark, 0.4)} />
{Array.from({ length: 9 }, (_, i) => {
const y = -40 - i * 58;
const x = -14 + (i / 9) * 40 - Math.sin((i / 9) * 2) * 10;
return <path key={i} d={`M${x - 20} ${y} Q${x + 4} ${y + 10} ${x + 30} ${y}`} stroke={p.lo(bark, 0.5)} strokeWidth={6} fill="none" strokeLinecap="round" />;
})}
{fronds.map(([x, y], i) => {
const ox = 36;
const oy = -560;
const mx = (ox + x) / 2;
const my = Math.min(oy, y) - 70;
return <g key={i}>
<path d={`M${ox} ${oy} Q${mx} ${my - 34} ${x} ${y} Q${mx} ${my + 44} ${ox} ${oy} Z`} fill={p.c(leaf)} />
<path d={`M${ox} ${oy} Q${mx} ${my + 6} ${x} ${y} Q${mx} ${my + 44} ${ox} ${oy} Z`} fill={p.lo(leaf, 0.42)} />
</g>;
})}
<circle cx={24} cy={-540} r={20} fill={p.c("#6a4a2a")} /><circle cx={52} cy={-532} r={18} fill={p.lo("#6a4a2a", 0.3)} />
</g>;
},
outcrop: (p, color) => {
const s = color ?? mix(p.pal.stone, p.pal.ground.dirt, 0.5);
return <g>
<path d="M-330 0 Q-300 -70 -160 -96 Q0 -116 170 -94 Q310 -70 330 0 Z" fill={p.c(s)} />
<path d="M60 -110 Q200 -96 290 -60 Q320 -36 330 0 L40 0 Q110 -50 60 -110 Z" fill={p.lo(s, 0.32)} />
{[-30, -56, -78].map((y, i) => <path key={y} d={`M${-300 + i * 40} ${y} Q0 ${y - 22} ${300 - i * 40} ${y}`} stroke={p.lo(s, 0.5)} strokeWidth={5} fill="none" />)}
<path d="M-330 0 Q-300 -70 -160 -96 L-150 -80 Q-280 -50 -300 0 Z" fill={p.hi(s, 0.3)} />
</g>;
},
rainbow: () => {
const bands = ["#e8463d", "#f28c28", "#f2c230", "#5cc48a", "#4fb0e8", "#7a5ce0"];
return <g fill="none" opacity={0.78}>{bands.map((c, i) => <path key={c} d={`M${-600 + i * 26} 0 A${600 - i * 26} ${600 - i * 26} 0 0 1 ${600 - i * 26} 0`} stroke={c} strokeWidth={27} />)}</g>;
},
waves: (p, color) => {
const water = color ?? p.pal.ground.water;
const d = Array.from({ length: 7 }, (_, i) => `Q${-300 + i * 100 + 50} -70 ${-300 + (i + 1) * 100} 0`).join(" ");
return <g>
<path d={`M-300 0 ${d} L400 40 L-300 40 Z`} fill={p.lo(water, 0.3)} />
<path d={`M-300 6 ${d} L400 12 L-300 12 Z`} fill={p.c(water)} opacity={0.7} />
<path d={`M-300 0 ${d}`} stroke={p.hi("#ffffff", 0)} strokeWidth={9} fill="none" opacity={0.75} strokeLinecap="round" />
</g>;
},
};
+88
View File
@@ -0,0 +1,88 @@
// Tinta do cenário: paletas, mistura de cor e o "pincel" de cada peça. Toda peça pinta em 2 tons (cel): a cor
// base e o lado da sombra, num tom mais escuro e frio da própria cor (nunca contorno preto). A luz vem da
// ESQUERDA em todas as peças. A distância (z) puxa a cor para a do céu/parede (perspectiva atmosférica) e a
// frente fica um pouco mais escura e contrastada — tudo por mistura de cor, sem filtro (render barato).
export const PALETTES = ["night", "sepia", "day", "dusk", "gray"] as const;
export type PaletteId = (typeof PALETTES)[number];
export type Pal = {
/** Céu: topo, meio e perto do horizonte. */
sky: [string, string, string];
wall: string;
ground: Record<string, string>;
far: string; near: string; ink: string; leaf: string; trunk: string; stone: string;
/** Cor da luz (lado iluminado, lâmpada, sol). */
light: string;
/** Cor fria para onde as sombras puxam. */
shade: string;
/** Sol/lua: cor do disco e do halo. */
sun: string; halo: string;
/** Contraluz: quanto toda peça escurece para o frio (entardecer = sol baixo atrás das coisas). */
dim?: number;
};
const P: Record<PaletteId, Pal> = {
night: { sky: ["#070a1c", "#141a3e", "#2a3264"], wall: "#25304f", far: "#2c3463", near: "#3d4a7c", ink: "#0c0d1a", leaf: "#2a4a5a", trunk: "#3a2e40",
stone: "#5a6088", light: "#ffc965", shade: "#05081c", sun: "#f4ecc8", halo: "#8a9ad8",
ground: { grass: "#22384a", street: "#232842", dirt: "#33304a", floor: "#2a2e48", sand: "#4a4868", water: "#16305a" } },
sepia: { sky: ["#b8956a", "#dcc196", "#f0dfb8"], wall: "#6e6248", far: "#b49a74", near: "#7a5e46", ink: "#2a2018", leaf: "#7f8048", trunk: "#5a4330",
stone: "#a39a8a", light: "#ffdc8e", shade: "#2c2a3a", sun: "#fff0c0", halo: "#ffd890",
ground: { grass: "#8f8c54", street: "#76685a", dirt: "#8a6a48", floor: "#7a5e44", sand: "#d8bd8a", water: "#6f8a8a" } },
day: { sky: ["#3f8fd8", "#7fbdec", "#d4ecf8"], wall: "#e6d6b6", far: "#a6c8de", near: "#e09a68", ink: "#22252e", leaf: "#5aa84a", trunk: "#7a5232",
stone: "#a9adb5", light: "#fff2be", shade: "#2a3a78", sun: "#fff8d8", halo: "#fff2b0",
ground: { grass: "#7cc25e", street: "#8a8f99", dirt: "#c49060", floor: "#c69c6c", sand: "#f0d79a", water: "#3f9ad8" } },
dusk: { sky: ["#5c5a9a", "#e49a72", "#f8d08a"], wall: "#5a4658", far: "#b48a98", near: "#c98a6a", ink: "#20141c", leaf: "#6a8540", trunk: "#5e3a2a",
stone: "#9a8a92", light: "#ffcf86", shade: "#3a2a62", sun: "#ffe7a8", halo: "#ffc070", dim: 0.12,
ground: { grass: "#6e8448", street: "#6a5a64", dirt: "#c27a4c", floor: "#6e5048", sand: "#dba878", water: "#5a6aa0" } },
gray: { sky: ["#5f6670", "#8d949c", "#c0c4c8"], wall: "#565b63", far: "#8f969e", near: "#646a72", ink: "#1b1d21", leaf: "#5a6b55", trunk: "#4a4038",
stone: "#9aa0a8", light: "#f2e6c8", shade: "#1e2430", sun: "#e8e8e0", halo: "#c8ccd0",
ground: { grass: "#5f6e55", street: "#4a4f57", dirt: "#5e5246", floor: "#4a4d54", sand: "#a8a08a", water: "#5a6f80" } },
};
export const palette = (id: PaletteId | undefined): Pal => P[id ?? "night"] ?? P.night;
/** Mistura duas cores hex (#rrggbb) em k (0 = a, 1 = b). */
export function mix(a: string, b: string, k: number): string {
const pa = parseInt(a.slice(1, 7), 16);
const pb = parseInt(b.slice(1, 7), 16);
const q = Math.max(0, Math.min(1, k));
const ch = (s: number) => Math.round(((pa >> s) & 255) * (1 - q) + ((pb >> s) & 255) * q);
return `#${[16, 8, 0].map((s) => ch(s).toString(16).padStart(2, "0")).join("")}`;
}
/** Pincel de uma peça: já sabe a profundidade, a paleta e o sorteio da semente. */
export type Paint = {
pal: Pal;
r: () => number;
indoor: boolean;
night: boolean;
/** Cor base (com a névoa da distância). */
c: (hex: string) => string;
/** Lado da sombra: mais escuro e frio (k = quanto). */
lo: (hex: string, k?: number) => string;
/** Lado da luz: mais claro e quente. */
hi: (hex: string, k?: number) => string;
};
/**
* `haze` = quanto a peça puxa para a cor do fundo (0–1); `front` = quanto escurece por estar na frente (0–0,2).
* Os resultados ficam em cache por peça: o mesmo hex sai sempre igual.
*/
export function makePaint(pal: Pal, r: () => number, opts: { haze: number; hazeColor: string; front: number; indoor: boolean; night: boolean }): Paint {
const cache = new Map<string, string>();
const base = (hex: string) => {
const hit = cache.get(hex);
if (hit) return hit;
let v = pal.dim ? mix(hex, pal.shade, pal.dim) : hex;
if (opts.front > 0) v = mix(v, pal.ink, opts.front);
if (opts.haze > 0) v = mix(v, opts.hazeColor, opts.haze);
cache.set(hex, v);
return v;
};
return {
pal, r, indoor: opts.indoor, night: opts.night,
c: base,
lo: (hex, k = 0.3) => base(mix(hex, pal.shade, k)),
hi: (hex, k = 0.2) => base(mix(hex, pal.light, k)),
};
}
+303
View File
@@ -0,0 +1,303 @@
// Biblioteca de MÃOS desenhadas (não montadas com cápsulas): cada forma é um desenho num quadro fixo de 120×120,
// com a silhueta inteira num path só (Bézier contínuas: dedos afinando em 3 falanges, nós em arco, polegar nascendo
// do montinho da base da palma), as linhas internas no tom escuro da pele, unhas, e uma sombra cel DESENHADA
// (recortada pela silhueta). O rig só ESCOLHE a forma, posiciona no pulso, gira e espelha.
//
// Regras de construção seguidas (ensino de desenho de mão): palma ≈ quadrada com laterais curvas; dedo médio ≈ altura
// da palma, médio o maior, indicador ≈ anelar, mínimo o menor; nós da base e pontas em ARCO (o médio mais à frente);
// dedo afina para a ponta; polegar com 2 segmentos e unha, girando em outro eixo; pulso mais estreito que a palma;
// volume com sombra no lado oposto à luz e embaixo dos dedos; linhas internas sempre curvas.
//
// Quadro canônico: braço da DIREITA da tela (s = 1), luz vinda da esquerda (sombra desenhada à direita/embaixo).
// - formas "alinhadas" (relaxed, open, point, fist, on_face): o antebraço chega por cima (pulso em (60, 4)) e os dedos
// apontam para +y; o polegar fica do lado −x. O rig gira pelo ângulo do antebraço.
// - formas "em pé" (thumbs_up, grip, pinch_edge): desenhadas na orientação da tela, com o pulso num canto e o ângulo
// do antebraço para o qual foram feitas (`wristDeg`); o rig só inclina um pouco para acompanhar o braço.
import React from "react";
import type { IconId } from "./spec";
export const HAND_SHAPES = ["relaxed", "open", "point", "thumbs_up", "grip", "pinch_edge", "pinch_low", "fist", "on_face"] as const;
export type HandShape = (typeof HAND_SHAPES)[number];
type ShapeDef = {
/** Silhueta inteira (um path). */
body: string;
/** Sombra cel desenhada (recortada pela silhueta do corpo). */
shadow: string;
/** Linhas internas do corpo: separação dos dedos, nós, dobras. */
lines: string;
/** Peça por cima (polegar dobrado por cima dos dedos ou do objeto), com sombra e linhas próprias. */
over?: { body: string; shadow?: string; lines?: string };
/** Unhas: [cx, cy, rx, ry, giro]. A primeira do corpo, as de `overNails` por cima. */
nails?: [number, number, number, number, number][];
overNails?: [number, number, number, number, number][];
/** Pulso no quadro (onde encosta o fim do antebraço). */
wrist: [number, number];
/** Ângulo do antebraço para o qual a forma foi desenhada (0 = descendo; formas alinhadas = 0). */
wristDeg: number;
upright: boolean;
/** Com objeto: o corpo fica ATRÁS do objeto (só a peça `over` na frente) — pinch_edge. */
bodyBehind?: boolean;
/** Onde fica o objeto: cabo (grip) ou borda (pinch_edge). */
hold?: [number, number];
};
// Pulso: cilindro com ≈ 60 % da largura da palma (27 unidades), centrado no ponto `wrist`, com uma sobra de 10
// unidades que entra por baixo da manga (fica escondida pelo punho da manga). Sombra do lado oposto à luz (direita):
// no pulso ela tem a mesma largura da sombra do antebraço (≈ 1/3) e vai afinando na borda da mão; sob os dedos dobrados
// e sob o polegar.
const WRIST_TOP = "M46.5 -10 L46.5 3";
const WRIST_RIGHT_END = "C74.4 6.5 73.6 3 73.5 0 L73.5 -10 Z";
const SHAPES: Record<HandShape, ShapeDef> = {
// Caída ao lado do corpo, vista pelo dorso: dedos juntos levemente curvos (nós e pontas em arco), polegar na frente.
relaxed: {
body: `${WRIST_TOP} C45.5 12 41 18 38.5 25 C35.5 33 34 42 35 50 C35.8 57 38.5 61 42 60.5 C45 60 46 57 45.6 53 C45.3 49 45 46 44.8 44`
+ " C43.6 52 42.8 62 43 72 C43.2 79 45.2 82.5 48.3 82.5 C51.3 82.5 52.6 80 52.6 76.5 L52.8 74 C53 80 53.4 86 55.2 89"
+ " C56.6 91.6 60 92 61.8 89.8 C63 88 63.2 85 63.2 81 L63.4 78 C63.8 82 64.6 85.5 66.4 87.2 C68.4 89 71.4 88.2 72.2 85.4"
+ " C72.8 83 72.8 80 72.6 77 L72.8 74 C73.8 76.5 75.4 78 77.4 77.6 C79.6 77 80.6 74.6 80.7 71.5 C81 64 81.8 54 82 46"
+ ` C82.2 34 79.5 20 75.5 10 ${WRIST_RIGHT_END}`,
shadow: "M64.6 -12 L65 1 C69 6 75 12 78 22 C79.6 32 80 42 79.6 52 C79.2 62 78.6 70 78.8 76 L96 80 L96 -12 Z"
+ " M40 77 C48 84.5 62 90.5 80 76 L80 100 L40 100 Z M45.2 45 C46.6 52 47 59 46.6 65 L49.6 66 C49.8 58 49.2 50 47.6 44 Z",
lines: "M52.8 74 C52.7 68 52.8 62 53.2 56 M63.4 78 C63.4 71 63.2 64 63 57 M72.8 74 C73 68 73.4 62 73.8 55 M44.8 44 C44.5 38 43 32 41 27",
nails: [[40.6, 54.2, 2.8, 3.8, 6]],
wrist: [60, 0], wristDeg: 0, upright: false,
},
// Aberta, palma para a câmera (acenando): dedos levemente abertos, polegar saindo da eminência tenar.
open: {
body: `${WRIST_TOP} C44 12 39 18 35 22 C29 26 24 31 21 37 C18.5 42 19.5 47 23.5 47.5 C26.5 48 28.5 45.5 30 42.5 C32.5 38 35.5 35 38.5 34.5`
+ " C39 38 39.2 41 39.5 44 C38.6 54 38 64 38.4 72 C38.6 78 41 80.6 44 80.4 C47 80.2 48.4 78 48.4 74.6 C48.6 64 48.8 55 49.4 47.5"
+ " C50.4 58 50.8 70 51.2 80 C51.4 86 54.2 88.6 57.2 88.4 C60.2 88.2 61.6 85.6 61.4 82 C61 70 60.8 58 61.2 48"
+ " C62.6 58 63.6 68 64.4 76 C64.8 81.4 67.6 83.6 70.4 83 C73 82.4 74 79.8 73.6 76.6 C72.6 66 72 56 72 47.4"
+ " C73.8 54 75.6 61 77.6 66.6 C79 70.6 82 71.6 84.2 70 C86 68.6 86 66 85.2 63 C83 54 82.6 42 81.6 30 C80.6 18 76 8 73.5 2 L73.5 -10 Z",
shadow: "M64.6 -12 L65 1 C70 6 77 14 80.6 32 C81.6 44 82 54 83.4 64 L96 64 L96 -12 Z M50 30 C56 36 66 38.4 75 34 C70 42 60 44.4 51 40 Z"
+ " M45.6 50 C46.2 60 46.4 70 46 80.4 L49 80 L49.2 50 Z M58.4 50 C58.8 62 59.2 74 59 88.4 L62 88 L61.6 50 Z M70.4 50 C71.2 60 71.8 70 72 82 L74.6 81 L73.6 50 Z",
lines: "M48 46 C58 42.4 70 42.4 80 46 M42 40 C46 32 50 22 52 12",
wrist: [60, 0], wristDeg: 0, upright: false,
},
// Apontando, vista pelo lado da palma: indicador esticado (3 falanges, afinando, unha na ponta, leve curva); médio,
// anelar e mínimo dobrados como gomos empilhados em arco (médio mais à frente), com a ponta virada para a palma e a
// UNHA de cada um aparecendo; o polegar fecha por cima do médio, com a unha dele.
point: {
body: `${WRIST_TOP} C45 12 40 18 37.5 26 C36 34 36.2 42 38.2 48 C37.8 60 37.9 72 38.5 82 C39 90 39.6 96 40.6 101.4`
+ " C41.4 106.6 46 108.4 49.2 106 C51.6 104.2 52.2 100.4 52.2 96.6 C52.2 88 52.6 76 53.4 64"
+ " C54 68.6 56.8 71 60.6 70.6 C64 70.2 65.6 67.6 65.8 64.8 C68 68 71.6 68.4 74 66.6 C76 65 76.4 62 76 59.8"
+ ` C78.4 60.6 81 59.4 81.8 56.4 C82.6 53 82.4 49 82 46 C82 34 79.5 20 75.5 10 ${WRIST_RIGHT_END}`,
shadow: "M64.6 -12 L65 1 C70 6 78 14 80.8 30 C81.6 40 81 48 79.6 52 C76 50 70 49 64 50 L96 50 L96 -12 Z"
+ " M50 66 C56 72.6 68 72 74 68 C78 66 81 62 83 56 L86 80 L48 80 Z M49.6 66 C50.2 78 50.6 92 50.2 108 L58 108 L58 66 Z"
+ " M44 58 C48 62 52 64.4 56.4 63.6 L58 67 L44 64 Z",
lines: "M65.8 64.8 C65.4 60.6 64.4 57.6 62.8 55.4 M76 59.8 C75.4 56 74.2 53.4 72.6 51.6 M53 57.4 C60 53.6 70 51.4 81 47"
+ " M38.8 81 Q45.4 82.6 52.4 81 M40.2 93 Q46 94.4 52.2 93",
nails: [[59.6, 66.6, 3.2, 2.4, 6], [70.8, 63.4, 2.9, 2.2, -8], [79.2, 54.6, 2.3, 1.9, -30], [45.8, 102, 3, 3.6, -4]],
over: {
body: "M38.4 30 C42 38 47 46 52.8 52 C56.2 55.4 57 60 54 61.6 C51 63.2 47.4 60.4 44.4 56.6 C40.8 52 38 46 37.6 40 Z",
shadow: "M39.6 46 C42 51 46 56 50 59 L46 62 L38 52 Z",
},
overNails: [[53.2, 57.2, 3, 2.6, 40]],
wrist: [60, 0], wristDeg: 0, upright: false,
},
// Joinha: punho de lado, os 4 dedos dobrados na horizontal (um em cima do outro, nós e pontas na frente),
// polegar grosso saindo do topo, com unha, levemente inclinado para trás. Antebraço chegando de baixo, na diagonal.
thumbs_up: {
body: "M56 42 C46 39.5 34 40 29 44.5 C24.6 48.6 25.2 54.4 29.6 56 C25.2 58.6 24.8 65.4 29.4 67.8 C25.8 70.6 26.4 77.6 31 79.4"
+ " C28.6 82.6 30.6 88.4 36 89.4 C46 91.2 60 92.6 72 93.6 C78 94.4 83 97.2 86.5 101.5 L93.6 108.6 L112.6 89.6 L105.5 82.5"
+ " C101 77.6 96 70.4 92 61 C89.4 54.4 85 48 78 45 C77.6 40 76.8 30 75.4 20 C74.4 13 71.6 7 66 6.4"
+ " C60.6 5.8 57.4 9.6 56.8 15.6 C56.2 24 55.8 33 56 42 Z",
shadow: "M84 46 C90 52 95 62 98 72 L104 82 L120 96 L120 40 Z M28 54.6 C38 57.8 50 58 60 56.6 L60 59.6 C48 61 38 60.6 28 58 Z"
+ " M28 66.4 C38 69.6 50 70 60 68.6 L60 71.6 C48 73 38 72.6 28 70 Z M30 78 C40 81 50 81.6 58 80.6 L58 83.6 C48 84.6 40 84 30 81.4 Z"
+ " M30 88 C46 92 62 94 74 95 L86 104 L40 104 Z M71 8 C74 14 76 24 77 40 L84 44 L84 4 Z",
lines: "M29.6 56 C38 58 48 58.4 58 57 M29.4 67.8 C38 70 48 70.4 58 69 M31 79.4 C39 81.4 48 81.8 56 81"
+ " M58 57 C62 55.6 64.6 52.6 65.4 49 M58 69 C62.6 67.6 65.6 64.6 66.4 60.6 M56 81 C60.4 80 63.4 77.4 64.4 73.6 M57 34.5 C62 37 70 37.4 77 33.6",
nails: [[65.4, 13.8, 5, 6, 4]],
wrist: [96, 92], wristDeg: 135, upright: true,
},
// Punho em volta de um cabo (martelo, régua, ramo, celular): o cabo passa por dentro, o polegar fecha por cima.
grip: {
body: "M44 42 C34 41.6 26.6 43.6 26.2 49 C25.8 53.4 26.8 55.6 29.6 56 C25.2 58.6 24.8 65.4 29.4 67.8 C25.8 70.6 26.4 77.6 31 79.4"
+ " C28.6 82.6 30.6 88.4 36 89.4 C48 91.4 64 92 76 89.6 C86 87.4 92.6 80 94.4 70 C96 62 100 55 105.5 49.5 L112.6 42.4 L93.6 23.4 L86.5 30.5"
+ " C80 36 72 39.6 62 41 C56 41.8 50 42 44 42 Z",
shadow: "M86 34 C92 44 95 58 94 70 C92 82 84 90 74 92 L120 120 L120 30 Z M28 54.6 C38 57.8 50 58 60 56.6 L60 59.6 C48 61 38 60.6 28 58 Z"
+ " M28 66.4 C38 69.6 50 70 60 68.6 L60 71.6 C48 73 38 72.6 28 70 Z M30 78 C40 81 50 81.6 58 80.6 L58 83.6 C48 84.6 40 84 30 81.4 Z"
+ " M30 88 C46 92 62 93 78 90 L78 100 L30 100 Z",
lines: "M29.6 56 C38 58 48 58.4 58 57 M29.4 67.8 C38 70 48 70.4 58 69 M31 79.4 C39 81.4 48 81.8 56 81"
+ " M58 57 C62 55.6 64.6 52.6 65.4 49 M58 69 C62.6 67.6 65.6 64.6 66.4 60.6 M56 81 C60.4 80 63.4 77.4 64.4 73.6",
over: {
body: "M80 36 C72 30.6 58 29.6 46 32.6 C37 34.8 33.4 40.6 36.6 44.2 C40.6 47.6 52 46.6 62 45.6 C70 44.8 76 43 79 40.6 Z",
shadow: "M36 43 C44 46.6 58 46.4 72 44 L72 48 L36 48 Z",
},
overNails: [[40.6, 39.4, 4.2, 3.6, -12]],
wrist: [96, 40], wristDeg: 45, upright: true, hold: [44, 66],
},
// Segurando a borda de um objeto largo (em par): dedos atrás do objeto, polegar grosso por cima da frente dele.
// Antebraço chegando de cima, por fora (pose hold_both).
pinch_edge: {
body: "M56 32 C62 27 72 26.6 80 30.6 C83.6 32.6 85.6 37 87 42 L94.4 35.3 L112.4 55.3 L105 62 C102 70.4 97 78 90 83.4"
+ " C82.6 89 72.6 92 64 90.6 C58.6 89.6 55.6 86 55 80 C54 64 54 46 56 32 Z",
shadow: "M82 30 C90 38 94 50 94 62 C92 74 86 82 76 88 L120 120 L120 20 Z M55 78 C60 86 70 90 84 88 L84 96 L54 96 Z",
lines: "M56 46 C62 46 68.6 47.6 74 50.6 M55.6 60 C61.4 60.4 67.6 62 73 64.8 M55.6 73.6 C60.6 74 65.4 75.6 69.6 78",
over: {
body: "M70 46 C62 40 52 34.6 45 31.6 C38.4 28.8 33 32.4 35 38.4 C37.4 45 46.4 51 55.6 57 C62 61 70.4 57.6 70 46 Z",
shadow: "M36.4 40.6 C43 47 52 53 60 58 L68 58 L68 64 L34 46 Z",
},
overNails: [[39.8, 35.2, 4.2, 3.6, 30]],
wrist: [96, 52], wristDeg: 48, upright: true, bodyBehind: true, hold: [56, 52],
},
// A mesma pegada de borda com o antebraço chegando de baixo (close de mãos segurando um livro aberto).
pinch_low: {
body: "M56 30 C64 25 78 26 85 34 C90 41 93 52 95 62 C96.6 70 100 78 105.5 86.5 L112.6 93.6 L93.6 112.6 L86.5 105.5"
+ " C80 98 72 94.6 66 92.4 C59 90 56 85.6 55 79 C53.6 64 53.6 44 56 30 Z",
shadow: "M80 28 C90 40 94 56 96 68 C98 78 102 84 110 92 L120 120 L120 20 Z M55 78 C60 86 68 91 80 96 L80 104 L54 100 Z",
lines: "M56 46 C62 46 68.6 47.6 74 50.6 M55.6 60 C61.4 60.4 67.6 62 73 64.8 M55.6 73.6 C60.6 74 65.4 75.6 69.6 78",
over: {
body: "M70 46 C62 40 52 34.6 45 31.6 C38.4 28.8 33 32.4 35 38.4 C37.4 45 46.4 51 55.6 57 C62 61 70.4 57.6 70 46 Z",
shadow: "M36.4 40.6 C43 47 52 53 60 58 L68 58 L68 64 L34 46 Z",
},
overNails: [[39.8, 35.2, 4.2, 3.6, 30]],
wrist: [96, 96], wristDeg: 135, upright: true, bodyBehind: true, hold: [56, 52],
},
// Fechada, vista pelo lado da palma: os 4 dedos dobrados como gomos em arco (médio mais à frente, mínimo menor),
// com a ponta virada para a palma e a UNHA de cada um; o polegar fecha por cima do indicador e do médio.
fist: {
body: `${WRIST_TOP} C45 12 40 18 37.5 26 C36 34 36.2 42 38 50 C39.4 57 42.4 62 46.6 63.6 C50 65 53.2 64 54.4 61.4`
+ " C56 66.4 60 69 64 68.4 C67.4 67.8 69 65.2 69.2 62.4 C71.4 65.8 75 66.2 77.4 64.2 C79.4 62.4 79.8 59.4 79.4 57"
+ ` C81.6 57 82.6 53 82.4 48 C82.2 34 79.5 20 75.5 10 ${WRIST_RIGHT_END}`,
shadow: "M64.6 -12 L65 1 C70 6 78 14 80.8 30 C81.6 40 81 46 80 50 L96 50 L96 -12 Z M40 58 C48 68 66 72 82 54 L84 80 L38 80 Z",
lines: "M54.4 61.4 C53.8 57 52.4 54 50.6 52 M69.2 62.4 C68.8 58.4 67.6 55.6 66 53.6 M79.4 57 C78.6 53.6 77.4 51.2 75.8 49.6 M44 51 C54 47.6 68 45.6 81 43.6",
nails: [[46, 59.6, 3, 2.3, 10], [62.6, 64.4, 3.2, 2.4, 0], [74.2, 61.2, 2.8, 2.1, -10], [80, 53, 2.2, 1.8, -30]],
over: {
body: "M38 30 C42 39 48 47 55 52 C59 54.6 60.4 59 57 60.6 C53 62.4 47.6 59 43.6 54.6 C39.8 50.4 37.4 42 38 30 Z",
shadow: "M39.4 46 C42.6 52 47 57 52 60 L48 63 L38 52 Z",
},
overNails: [[56.6, 56.8, 3.1, 2.7, 35]],
wrist: [60, 0], wristDeg: 0, upright: false,
},
// Apoiada no rosto (queixo, boca, lateral da cabeça): dorso, dedos juntos e mais retos, polegar recolhido.
on_face: {
body: `${WRIST_TOP} C45.5 12 41.5 18 39.5 25 C37.5 32 37.5 40 39 46 C39.5 58 39.6 70 40.4 82 C40.8 88 43.4 91.4 46.4 91.2`
+ " C49.4 91 50.6 88.4 50.8 85 L51 83 C51.4 90 53.6 94.4 57 94.4 C60.4 94.4 62 91.4 62.2 87.6 L62.3 85.6 C63 91 65.4 93.4 68.4 93"
+ " C71.4 92.6 72.4 89.8 72.4 86.4 L72.5 83.6 C73.6 87 75.6 88.2 77.6 87.6 C79.8 86.8 80.6 84 80.8 80.6 C81.6 70 82.2 56 82 44"
+ ` C81.8 32 79.2 20 75.5 10 ${WRIST_RIGHT_END}`,
shadow: "M64.6 -12 L65 1 C70 6 78 14 80.4 36 C81 50 80.6 66 79.6 84 L96 84 L96 -12 Z M40 84 C48 92 66 97 82 84 L82 104 L40 104 Z",
lines: "M51 83 C51 74 51.2 66 51.6 58 M62.3 85.6 C62.3 76 62.2 67 62 58 M72.5 83.6 C72.8 75 73 66 73.2 57",
over: {
body: "M39.5 25 C35 31 33.6 40 35.4 46 C36.8 50.4 41 50 41.6 46 C42.2 41 42 34 41.8 28 Z",
},
overNails: [[37.4, 44.6, 2.4, 3.2, 6]],
wrist: [60, 0], wristDeg: 0, upright: false,
},
};
/** Objetos seguros com as DUAS mãos (pelas bordas, na frente do peito). O resto vai numa mão só (`grip`). */
export const TWO_HANDED: IconId[] = ["book", "tablet"];
/**
* Como cada objeto entra no punho (`grip`): ponto do cabo no quadro 100×100 do ícone e o giro que deixa o cabo em pé
* (cabeça do martelo, ponta do ramo e da régua para cima). Sem entrada: pelo meio, sem girar.
*/
export const GRIP: Partial<Record<IconId, { x: number; y: number; rot: number }>> = {
hammer: { x: 50, y: 80, rot: 20 },
olive: { x: 26, y: 80, rot: -43 },
ruler: { x: 14, y: 58, rot: -78 },
phone: { x: 50, y: 74, rot: 0 },
fuel: { x: 50, y: 30, rot: 0 },
bulb: { x: 50, y: 82, rot: 0 },
};
/**
* Posição da forma: espelho (`mirror`), giro em graus e escala, a partir do pulso na tela, do ângulo do antebraço e do
* lado do braço. Formas alinhadas giram com o antebraço; as "em pé" só inclinam até ±30° para acompanhá-lo.
*/
export function handPlacement(shape: HandShape, x: number, y: number, foreDeg: number, s: number, k: number) {
const def = SHAPES[shape];
let mirror: number;
let rot: number;
if (def.upright) {
// Desenhada para o braço da direita; o pulso acompanha o eixo do antebraço (gira em torno do centro do pulso).
mirror = s >= 0 ? 1 : -1;
rot = foreDeg - def.wristDeg * mirror;
} else {
// Polegar do lado do corpo; com o braço erguido o eixo local vira e o espelho inverte junto.
const up = Math.cos((foreDeg * Math.PI) / 180) >= 0;
mirror = up ? s : -s;
rot = foreDeg;
}
const [wx, wy] = def.wrist;
const transform = `translate(${x} ${y}) rotate(${rot}) scale(${k * mirror} ${k}) translate(${-wx} ${-wy})`;
const r = (rot * Math.PI) / 180;
/** Ponto do quadro 120×120 → tela. */
const map = (px: number, py: number) => {
const lx = (px - wx) * k * mirror;
const ly = (py - wy) * k;
return { x: x + lx * Math.cos(r) - ly * Math.sin(r), y: y + lx * Math.sin(r) + ly * Math.cos(r) };
};
return { def, mirror, rot, transform, map, hold: def.hold ? map(def.hold[0], def.hold[1]) : null };
}
/** Pulso que põe o ponto `hold` da forma em (hx, hy) — para pôr as mãos nas bordas do objeto. */
export function wristForHold(shape: HandShape, hx: number, hy: number, foreDeg: number, s: number, k: number) {
const p = handPlacement(shape, 0, 0, foreDeg, s, k);
return { x: hx - (p.hold?.x ?? 0), y: hy - (p.hold?.y ?? 0) };
}
function shadeHex(hex: string, k: number): string {
const n = parseInt(hex.slice(1), 16);
const c = (v: number) => Math.max(0, Math.min(255, Math.round(v * k))).toString(16).padStart(2, "0");
return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`;
}
/** Mistura duas cores hex (0 = a, 1 = b). */
function mixHex(a: string, b: string, t: number): string {
const pa = parseInt(a.slice(1), 16), pb = parseInt(b.slice(1), 16);
const ch = (sh: number) => Math.round(((pa >> sh) & 255) * (1 - t) + ((pb >> sh) & 255) * t).toString(16).padStart(2, "0");
return `#${ch(16)}${ch(8)}${ch(0)}`;
}
function coolHex(hex: string, k: number): string {
const n = parseInt(hex.slice(1), 16);
const r = ((n >> 16) & 255) * k * 0.94, g = ((n >> 8) & 255) * k * 0.97, b = (n & 255) * k + 10;
const c = (v: number) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0");
return `#${c(r)}${c(g)}${c(b)}`;
}
/**
* Desenha a forma de mão no lugar. `layer`: "back" = o que fica atrás do objeto, "front" = o que fica na frente,
* "all" = tudo. `light` = lado da sombra na tela (1 = direita). Sem contorno: a borda é o tom escuro da pele.
*/
export function HandArt({ shape, x, y, foreDeg, s, k, skin, light = 1, layer = "all", uid }: {
shape: HandShape; x: number; y: number; foreDeg: number; s: number; k: number; skin: string; light?: number;
layer?: "all" | "back" | "front"; uid: string;
}) {
const p = handPlacement(shape, x, y, foreDeg, s, k);
const def = p.def;
// A sombra foi desenhada à direita; se, depois de espelhar e girar, a direita do desenho não cai do lado da sombra
// pedido, a sombra vira para o outro lado (sempre recortada pela silhueta).
const rightOnScreen = p.mirror * Math.cos((p.rot * Math.PI) / 180);
const flipShadow = Math.sign(rightOnScreen || 1) !== Math.sign(light || 1);
const shadowT = flipShadow ? "translate(120 0) scale(-1 1)" : undefined;
const dark = shadeHex(skin, 0.62);
const shadow = coolHex(skin, 0.8);
const lineProps = { stroke: dark, strokeWidth: 1.7, strokeLinecap: "round" as const, strokeLinejoin: "round" as const, fill: "none", opacity: 0.55 };
const nail = ([cx, cy, rx, ry, a]: [number, number, number, number, number], i: number) => (
<ellipse key={i} cx={cx} cy={cy} rx={rx} ry={ry} transform={`rotate(${a} ${cx} ${cy})`} fill={mixHex(skin, "#f7cfc6", 0.55)} stroke={shadeHex(skin, 0.68)} strokeWidth={0.9} />
);
const bodyLayer = def.bodyBehind ? "back" : def.hold ? "front" : "all";
const showBody = layer === "all" || layer === bodyLayer || (bodyLayer === "all" && layer === "front");
const showOver = layer !== "back";
return (
<g transform={p.transform}>
<defs>
<clipPath id={`hb${uid}${layer}`}><path d={def.body} /></clipPath>
{def.over && <clipPath id={`ho${uid}${layer}`}><path d={def.over.body} /></clipPath>}
</defs>
{showBody && <>
<path d={def.body} fill={skin} />
<g clipPath={`url(#hb${uid}${layer})`}><path d={def.shadow} fill={shadow} transform={shadowT} /></g>
<path d={def.lines} {...lineProps} />
{(def.nails ?? []).map(nail)}
</>}
{showOver && def.over && <>
<path d={def.over.body} fill={shadeHex(skin, 1.03)} />
{def.over.shadow && <g clipPath={`url(#ho${uid}${layer})`}><path d={def.over.shadow} fill={shadow} /></g>}
{def.over.lines && <path d={def.over.lines} {...lineProps} />}
{(def.overNails ?? []).map(nail)}
</>}
</g>
);
}
+28
View File
@@ -70,6 +70,34 @@ const DRAW: Record<IconId, React.ReactNode> = {
<circle cx={50} cy={50} r={40} fill="#f4f6ff" /><circle cx={50} cy={50} r={34} fill="#232850" />
<rect x={48} y={24} width={4} height={28} rx={2} fill="#fff" /><rect x={48} y={48} width={22} height={4} rx={2} fill={COLORS.key} />
</>),
// Itens de mão e objetos de história antiga (também servem como objeto solto na cena).
olive: (<>
<path d="M20 86 Q46 60 86 16" stroke="#6b4a2a" strokeWidth={5} fill="none" strokeLinecap="round" />
{[[34, 66, -40], [44, 56, 30], [54, 46, -40], [64, 36, 30], [74, 26, -40], [28, 76, 30]].map(([x, y, r], i) => (
<ellipse key={i} cx={x} cy={y} rx={13} ry={5.5} fill={i % 2 ? "#7fa24a" : "#5f8a3a"} transform={`rotate(${r} ${x} ${y})`} />
))}
<circle cx={50} cy={58} r={4} fill="#3d3a5a" /><circle cx={70} cy={38} r={4} fill="#3d3a5a" />
</>),
hammer: (<>
<rect x={44} y={34} width={12} height={60} rx={5} fill="#8a5a32" transform="rotate(-20 50 64)" />
<rect x={22} y={14} width={50} height={22} rx={4} fill="#8c929e" transform="rotate(-20 47 25)" />
<rect x={22} y={14} width={12} height={22} rx={3} fill="#6c717c" transform="rotate(-20 47 25)" />
</>),
tablet: (<>
<path d="M18 10 Q50 4 82 10 L86 88 Q50 96 14 88 Z" fill="#b8916a" />
{Array.from({ length: 7 }, (_, i) => <path key={i} d={`M24 ${22 + i * 10} L76 ${22 + i * 10}`} stroke="#8a6646" strokeWidth={2.5} strokeDasharray="5 3 2 3" />)}
<path d="M70 70 L86 60 L86 88 L64 92 Z" fill="#000" opacity={0.18} />
</>),
book: (<>
<path d="M8 24 Q30 16 50 26 Q70 16 92 24 L92 82 Q70 74 50 84 Q30 74 8 82 Z" fill="#f2e8d0" />
<path d="M50 26 L50 84" stroke="#b9a882" strokeWidth={3} />
{[0, 1, 2, 3].map((i) => <g key={i}><path d={`M16 ${36 + i * 11} L42 ${38 + i * 11}`} stroke="#9a8a6a" strokeWidth={2.5} /><path d={`M58 ${38 + i * 11} L84 ${36 + i * 11}`} stroke="#9a8a6a" strokeWidth={2.5} /></g>)}
<path d="M8 82 Q30 74 50 84 Q70 74 92 82 L92 88 Q70 80 50 90 Q30 80 8 88 Z" fill="#7a3a2a" />
</>),
ruler: (<>
<rect x={6} y={38} width={88} height={24} rx={3} fill="#e6c27a" transform="rotate(-12 50 50)" />
{Array.from({ length: 10 }, (_, i) => <rect key={i} x={12 + i * 8.4} y={38} width={2.4} height={i % 2 ? 7 : 12} fill="#6b4a2a" transform="rotate(-12 50 50)" />)}
</>),
};
export function Icon({ id }: { id: IconId }) {
+63
View File
@@ -0,0 +1,63 @@
// Profundidade dos braços do personagem de frente para a câmera (função pura do estado do rig, sem React).
//
// O desenho (CharacterFigure.tsx) empilha as camadas assim:
// tronco → braços "side" → acessórios do peito (toalha, cachecol, crachá, apito) → braços "front" →
// parte da toalha apoiada no ombro → cabeça → braços "face".
// Regra: com o personagem de frente, braço e mão NUNCA somem atrás do tronco, da roupa, de acessório ou da barba.
// - "face": a mão sobe até a altura do pescoço/rosto, dentro da largura da cabeça (pensar, tapar a boca, mão na
// testa) — desenhado por cima da cabeça e da barba;
// - "front": a mão ou o antebraço entram na frente do peito (segurar objeto diante do corpo, cruzar os braços,
// apontar para o outro lado, mão na cintura) — por cima do tronco e dos acessórios do peito;
// - "side": o braço fica ao lado do corpo (caído, acenando para fora, apontando para o lado) — por cima do tronco,
// mas por baixo do pano apoiado no ombro/peito (o braço sai por baixo da toalha).
// Não há caso "atrás do tronco": nenhuma pose do rig leva a mão às costas.
import type { BodyParams } from "./rig";
export type ArmLayer = "side" | "front" | "face";
export type Point = { x: number; y: number };
/** Ponta de um segmento: ângulo de tela em graus (0 = para baixo). Igual ao `tip` do desenho. */
export const tipOf = (x: number, y: number, deg: number, len: number): Point => {
const r = (deg * Math.PI) / 180;
return { x: x - Math.sin(r) * len, y: y + Math.cos(r) * len };
};
/** Medidas do desenho (viewBox 200×440) que a regra usa — as mesmas de CharacterFigure.tsx. */
export const ARM = { shoulderX: 54, upper: 56, wrist: 43, hand: 28, torsoHalf: 56 } as const;
/** Ombro, cotovelo, pulso e centro da mão do braço `s` (1 = direita da tela, -1 = esquerda). `w` = largura do corpo. */
export function armGeometry(b: BodyParams, s: 1 | -1, w = 1) {
const hipY = 306 + b.crouch * 56;
const shY = hipY - 100;
const torsoTop = hipY - 114;
const l = s > 0 ? b.armR : b.armL;
const shoulder = { x: 100 + s * ARM.shoulderX * w, y: shY };
const upperDeg = -s * l.raise;
const elbow = tipOf(shoulder.x, shoulder.y, upperDeg, ARM.upper);
const foreDeg = upperDeg + s * l.bend;
const wrist = tipOf(elbow.x, elbow.y, foreDeg, ARM.wrist);
const hand = tipOf(elbow.x, elbow.y, foreDeg, ARM.wrist + ARM.hand);
return { shoulder, elbow, wrist, hand, upperDeg, foreDeg, torsoTop, hipY };
}
/**
* Camada do braço `s` no quadro. `holds` = segura objeto (sempre na frente do corpo, salvo na altura do rosto).
* O "peito" é o tronco sem as faixas laterais onde o braço caído naturalmente encosta.
*/
export function armLayer(b: BodyParams, s: 1 | -1, opts: { holds?: boolean; w?: number } = {}): ArmLayer {
const w = opts.w ?? 1;
const g = armGeometry(b, s, w);
const half = ARM.torsoHalf * w;
// Altura do pescoço/rosto: acima do topo do tronco (+ folga da gola), dentro da largura da cabeça.
const atFace = (p: Point) => p.y < g.torsoTop + 12 && Math.abs(p.x - 100) < 66;
if (atFace(g.hand)) return "face";
if (opts.holds) return "front";
const chest = { x0: 100 - half + 16, x1: 100 + half - 16, y0: g.torsoTop + 6, y1: g.hipY + 10 };
const inChest = (p: Point) => p.x > chest.x0 && p.x < chest.x1 && p.y > chest.y0 && p.y < chest.y1;
// Amostra o antebraço (cotovelo → mão): basta um trecho na frente do peito.
for (let i = 0; i <= 8; i++) {
const k = i / 8;
if (inChest({ x: g.elbow.x + (g.hand.x - g.elbow.x) * k, y: g.elbow.y + (g.hand.y - g.elbow.y) * k })) return "front";
}
return "side";
}
+8 -2
View File
@@ -7,7 +7,7 @@ import { emphasisAt, speak, visemeAt, type SpokenWord } from "./lipsync";
import { blendBody, blendFace, bodyOf, faceOf, withBody, withFace, type BodyParams, type BodyPatch, type FaceParams, type FacePatch } from "./rig";
export const ACTIONS = ["express", "pose", "walk", "run", "enter", "exit", "jump", "nod", "shake_head", "tremble", "bounce", "fall",
"sit", "stand_up", "turn", "talk", "look", "emote", "wave"] as const;
"sit", "stand_up", "turn", "talk", "look", "emote", "wave", "hammer"] as const;
export type ActionKind = (typeof ACTIONS)[number];
export type Action = {
@@ -42,7 +42,7 @@ export type ActorState = {
const DEFAULT_DUR: Record<ActionKind, number> = {
express: 0.25, pose: 0.35, walk: 1.6, run: 0.9, enter: 1.2, exit: 1.2, jump: 0.8, nod: 0.7, shake_head: 0.8, tremble: 1, bounce: 0.8,
fall: 0.6, sit: 0.5, stand_up: 0.5, turn: 0.3, talk: 1.5, look: 0.3, emote: 1.2, wave: 1.2,
fall: 0.6, sit: 0.5, stand_up: 0.5, turn: 0.3, talk: 1.5, look: 0.3, emote: 1.2, wave: 1.2, hammer: 2.4,
};
const clamp01 = (v: number) => Math.max(0, Math.min(1, v));
@@ -189,6 +189,12 @@ export function evaluate(actor: ActorInput, t: number, durationS: number, seed =
break;
}
case "emote": if (active) st.emote = { text: a.text ?? "!", k: env }; break;
// Martelar: braço direito sobe e desce batendo (`times` golpes), cabeça acompanha cada batida.
case "hammer": if (active) {
const beat = Math.abs(Math.sin(p * Math.PI * (a.times ?? 5)));
st.body = withBody(st.body, { armR: { raise: 40 + beat * 95 * Math.min(1, env * 1.5), bend: 60 + beat * 40 }, headNod: st.body.headNod + (1 - beat) * 0.15 * env });
break;
}
case "wave": if (active) st.body = withBody(st.body, { armR: { raise: 140 * Math.min(1, env * 1.5), bend: -25 + Math.sin(p * Math.PI * 2 * (a.times ?? 3)) * 30 } }); break;
}
}
+330 -33
View File
@@ -1,9 +1,13 @@
// Camadas por cima da cena: etiqueta, onomatopeia, contador, ondas de som, X vermelho, painel do topo (HUD) e a
// legenda palavra por palavra (cada palavra entra pequena e cresce; palavra-chave em amarelo, perigo em vermelho).
// Camadas por cima da cena: etiqueta, onomatopeia, ondas de som, X vermelho, painel do topo (HUD), cartão de nome,
// cartelas de dado (número grande, lista com caixas, tabela, barra de progresso, grade de quadradinhos) e a legenda
// palavra por palavra (cada palavra entra pequena e cresce; palavra-chave maior e em amarelo, perigo em vermelho).
//
// Tudo é função pura do quadro (mola da Remotion + tempo do spec): o mesmo quadro sai sempre igual.
// Tamanhos em `u(n)` = n% da largura de um quadro vertical 9:16 (num quadro mais largo, limita pela altura).
import React from "react";
import { spring } from "remotion";
import { COLORS, FONT_CAPTION, FONT_LABEL, TONE_BG, TONE_FG } from "./theme";
import type { ShotSpec, TextItem, Tone, Word } from "./spec";
import { COLORS, FONT_CAPTION, FONT_LABEL, FONT_TEXT, TONE_BG, TONE_FG } from "./theme";
import { numberOf, type Hud as HudSpec, type TextItem, type TextRow, type Tone, type Word } from "./spec";
/** 0 → 1 com mola, a partir de `startS` (antes disso, 0). */
export function pop(frame: number, fps: number, startS = 0, stiffness = 220): number {
@@ -16,6 +20,32 @@ export function shake(frame: number, amp = 3): { x: number; y: number } {
return { x: Math.sin(frame * 12.9898) * amp, y: Math.cos(frame * 78.233) * amp * 0.7 };
}
/** 0 → 1 sem mola (desacelera no fim), de `startS` a `startS + durS`: barra enchendo, número contando. */
export function ease(frame: number, fps: number, startS: number, durS: number): number {
const p = Math.max(0, Math.min(1, (frame / fps - startS) / Math.max(0.01, durS)));
return 1 - (1 - p) ** 3;
}
/** Medida proporcional ao quadro: n% da largura de um vertical 9:16. */
export const u = (n: number) => `calc(${n.toFixed(3)} * min(1cqw, 0.5625cqh))`;
/** Cores do grafismo (cartelas, HUD, cartão de nome). */
export const UI = {
ink: "#151a31",
box: "rgba(15,18,30,0.94)",
boxEdge: "rgba(150,160,210,0.16)",
cell: "#252c48",
cream: "#f3efe6",
yellow: "#fcc430",
red: "#ea4752",
redSoft: "#f4646d",
green: "#2f9a55",
muted: "#c3c8dd",
dim: "#7f87a8",
track: "#2a3050",
};
const TONE_TEXT: Record<Tone, string> = { danger: UI.red, info: UI.yellow, ok: "#45c97a" };
const at = (x: number, y: number): React.CSSProperties => ({ position: "absolute", left: `${x * 100}%`, top: `${y * 100}%` });
export function TagLabel({ text, tone = "info", size = 3.6 }: { text: string; tone?: Tone; size?: number }) {
@@ -28,24 +58,244 @@ export function TagLabel({ text, tone = "info", size = 3.6 }: { text: string; to
);
}
/**
* Cartão de nome do personagem: cartão creme arredondado, nome grande em letra condensada escura e 1–2 linhas
* menores (função, dado). Sem posição nem animação: quem usa posiciona e faz a entrada.
*/
export function NameCard({ name, lines = [], size = 1 }: { name: string; lines?: string[]; size?: number }) {
const s = size;
return (
<div style={{ display: "inline-block", background: UI.cream, borderRadius: u(2.4 * s), padding: `${u(2.2 * s)} ${u(3.4 * s)} ${u(2.5 * s)}`,
boxShadow: `0 ${u(0.9 * s)} 0 rgba(8,10,22,0.34)`, textAlign: "left", whiteSpace: "nowrap" }}>
<div style={{ fontFamily: FONT_CAPTION, fontSize: u(6 * s), color: UI.ink, lineHeight: 1.12, letterSpacing: "0.005em" }}>{name.toUpperCase()}</div>
{lines.filter((l) => l.trim()).slice(0, 3).map((l, i) => (
<div key={i} style={{ fontFamily: FONT_TEXT, fontSize: u(3.3 * s), color: "#1c2138", lineHeight: 1.55, letterSpacing: "0.035em",
marginTop: i === 0 ? u(0.3 * s) : 0 }}>
{l.toUpperCase()}
</div>
))}
</div>
);
}
/** Conta o número do texto de 0 até o valor ("R$ 134.273", "-R$ 47.312.904", "297"), mantendo prefixo e sufixo. */
export function countUp(value: string, p: number): string {
const m = /^(\D*?)(\d{1,3}(?:\.\d{3})+|\d+)(,\d+)?(\D*)$/.exec(value.trim());
if (!m || p >= 1) return value;
const target = Number(m[2].replace(/\./g, ""));
if (target < 10) return value;
const n = String(Math.round(target * Math.max(0, p)));
const digits = m[2].includes(".") ? n.replace(/\B(?=(\d{3})+(?!\d))/g, ".") : n;
return `${m[1]}${digits}${m[3] ?? ""}${m[4]}`;
}
/** Caixa escura arredondada das cartelas flutuantes. */
function Box({ s, children, style }: { s: number; children: React.ReactNode; style?: React.CSSProperties }) {
return (
<div style={{ background: UI.box, borderRadius: u(3 * s), border: `${u(0.22 * s)} solid ${UI.boxEdge}`,
boxShadow: `0 ${u(0.8 * s)} 0 rgba(0,0,0,0.3)`, ...style }}>
{children}
</div>
);
}
/** Fundo escuro de tela inteira (cartela "panel"), com leve luz no centro como a referência. */
function PanelBackdrop({ k }: { k: number }) {
return (
<div style={{ position: "absolute", inset: "-4%", opacity: Math.min(1, k * 2.2),
background: "radial-gradient(ellipse 62% 42% at 50% 46%, #1d2342 0%, #151a31 55%, #0e1222 100%)" }} />
);
}
const label = (size: number, color = UI.muted, spacing = 0.16): React.CSSProperties => ({
fontFamily: FONT_TEXT, fontSize: u(size), color, letterSpacing: `${spacing}em`, lineHeight: 1.1, whiteSpace: "nowrap",
});
function StatCard({ t, s, frame, fps }: { t: TextItem; s: number; frame: number; fps: number }) {
const atS = t.atS ?? 0;
const value = countUp(String(t.value ?? ""), ease(frame, fps, atS + 0.1, 0.9));
const inner = (
<div style={{ textAlign: "center" }}>
{t.text.trim() && <div style={{ ...label(4.4 * s), marginBottom: u(1.2 * s), paddingLeft: "0.16em" }}>{t.text.toUpperCase()}</div>}
<div style={{ fontFamily: FONT_CAPTION, fontSize: u(15.5 * s), lineHeight: 1.08, whiteSpace: "nowrap",
color: t.tone ? TONE_TEXT[t.tone] : "#ffffff", textShadow: `0 ${u(0.6 * s)} 0 rgba(0,0,0,0.3)` }}>{value.toUpperCase()}</div>
</div>
);
return t.panel ? inner : <Box s={s} style={{ padding: `${u(2.6 * s)} ${u(5 * s)} ${u(2 * s)}` }}>{inner}</Box>;
}
function CounterCard({ t, s, frame, fps }: { t: TextItem; s: number; frame: number; fps: number }) {
const value = countUp(String(t.value ?? ""), ease(frame, fps, (t.atS ?? 0) + 0.1, 0.8));
return (
<Box s={s} style={{ padding: `${u(2.2 * s)} ${u(4.6 * s)} ${u(1.4 * s)}`, textAlign: "center", borderRadius: u(2.8 * s) }}>
<div style={{ ...label(3.5 * s, UI.muted, 0.12), paddingLeft: "0.12em" }}>{t.text.toUpperCase()}</div>
<div style={{ fontFamily: FONT_CAPTION, fontSize: u(11 * s), color: t.tone ? TONE_TEXT[t.tone] : "#ffffff", lineHeight: 1.12 }}>{value}</div>
</Box>
);
}
/** Caixa de seleção: vazia (contorno), marcada (verde enche da esquerda e o ✓ se desenha) ou riscada (vermelha com X). */
function CheckBox({ state, m, s }: { state: TextRow["state"]; m: number; s: number }) {
const side = u(8.2 * s);
const fill = state === "crossed" ? UI.red : UI.green;
const marked = state === "checked" || state === "crossed";
const draw = Math.max(0, Math.min(1, (m - 0.45) / 0.55));
return (
<div style={{ position: "relative", width: side, height: side, flex: "none", borderRadius: u(1.6 * s), overflow: "hidden",
boxSizing: "border-box", border: `${u(0.7 * s)} solid ${marked && m > 0 ? fill : state === "empty" ? "#4d5476" : "#6d7598"}` }}>
{marked && m > 0 && <div style={{ position: "absolute", left: 0, top: 0, bottom: 0, width: `${Math.min(1, m * 1.8) * 100}%`, background: fill }} />}
{marked && draw > 0 && (
<svg viewBox="0 0 100 100" style={{ position: "absolute", inset: "-12%", width: "124%", height: "124%" }}>
{state === "checked"
? <path d="M27 52 L44 68 L74 34" fill="none" stroke="#fff" strokeWidth={12} strokeLinecap="round" strokeLinejoin="round"
strokeDasharray={80} strokeDashoffset={80 * (1 - draw)} />
: <g stroke="#fff" strokeWidth={12} strokeLinecap="round">
<line x1={34} y1={34} x2={34 + 32 * Math.min(1, draw * 2)} y2={34 + 32 * Math.min(1, draw * 2)} />
{draw > 0.5 && <line x1={66} y1={34} x2={66 - 32 * (draw - 0.5) * 2} y2={34 + 32 * (draw - 0.5) * 2} />}
</g>}
</svg>
)}
</div>
);
}
function ChecklistCard({ t, s, frame, fps }: { t: TextItem; s: number; frame: number; fps: number }) {
const atS = t.atS ?? 0;
const step = t.stepS ?? 0.5;
const items = t.items ?? [];
let order = 0;
return (
<Box s={s} style={{ padding: `${u(5 * s)} ${u(7 * s)} ${u(5 * s)} ${u(6.4 * s)}`, minWidth: u((t.panel ? 84 : 30) * s), boxSizing: "border-box",
...(t.panel ? { background: "rgba(9,11,22,0.6)", boxShadow: "none" } : {}) }}>
{t.text.trim() && <div style={{ ...label(3.8 * s), marginBottom: u(3 * s) }}>{t.text.toUpperCase()}</div>}
{items.map((it, i) => {
const kIn = pop(frame, fps, atS + i * 0.07, 260);
const marked = it.state === "checked" || it.state === "crossed";
// Marcadas e riscadas em sequência, na ordem da lista.
const m = marked ? ease(frame, fps, atS + 0.45 + step * order++, 0.38) : 0;
const color = it.state === "crossed" && m > 0.5 ? UI.redSoft : marked && m > 0.5 ? "#ffffff" : it.state === "empty" ? UI.dim : UI.muted;
return (
<div key={i} style={{ display: "flex", alignItems: "center", gap: u(4 * s), marginTop: i ? u(3.3 * s) : 0,
opacity: Math.min(1, kIn * 1.6), transform: `translateX(${(1 - kIn) * -6}%)` }}>
<CheckBox state={it.state ?? "empty"} m={m} s={s} />
<span style={{ ...label(6.1 * s, color, 0.05) }}>{it.text.toUpperCase()}</span>
</div>
);
})}
</Box>
);
}
function TableCard({ t, s, frame, fps }: { t: TextItem; s: number; frame: number; fps: number }) {
const atS = t.atS ?? 0;
const items = t.items ?? [];
const hl = t.highlight;
const hlK = hl === undefined ? 0 : pop(frame, fps, atS + 0.35 + items.length * 0.1, 200);
const hlColor = t.tone === "ok" ? UI.green : t.tone === "info" ? UI.yellow : UI.red;
return (
<Box s={s} style={{ padding: `${u(3.8 * s)} ${u(3.6 * s)}`, width: u(80 * s), boxSizing: "border-box" }}>
{t.text.trim() && <div style={{ ...label(3.8 * s), marginBottom: u(2.2 * s), paddingLeft: u(1.6 * s) }}>{t.text.toUpperCase()}</div>}
{items.map((it, i) => {
const kIn = pop(frame, fps, atS + 0.1 + i * 0.1, 260);
const on = i === hl;
const fg = on && hlK > 0.5 ? (t.tone === "info" ? UI.ink : "#ffffff") : "#ffffff";
return (
<div key={i} style={{ position: "relative", display: "flex", alignItems: "center", gap: u(2.6 * s), padding: `${u(1.5 * s)} ${u(2.2 * s)}`,
borderTop: i ? `${u(0.2 * s)} solid rgba(255,255,255,0.07)` : "none", opacity: Math.min(1, kIn * 1.6),
transform: `translateY(${(1 - kIn) * 25}%) scale(${on ? 1 + 0.04 * hlK : 1})` }}>
{on && <div style={{ position: "absolute", inset: `${u(-0.3 * s)} ${u(-1 * s)}`, borderRadius: u(1.4 * s), background: hlColor, opacity: hlK,
boxShadow: `0 ${u(0.5 * s)} 0 rgba(0,0,0,0.3)` }} />}
<span style={{ position: "relative", fontFamily: FONT_CAPTION, fontSize: u(4.6 * s), color: on && hlK > 0.5 ? fg : UI.dim, width: u(4.4 * s), lineHeight: 1.15 }}>{i + 1}</span>
<span style={{ position: "relative", ...label(5 * s, fg, 0.04), flex: 1, overflow: "hidden", textOverflow: "ellipsis" }}>{it.text.toUpperCase()}</span>
{it.value !== undefined && <span style={{ position: "relative", fontFamily: FONT_CAPTION, fontSize: u(5.2 * s), color: fg, lineHeight: 1.15 }}>{it.value.toUpperCase()}</span>}
</div>
);
})}
</Box>
);
}
function ProgressCard({ t, s, frame, fps }: { t: TextItem; s: number; frame: number; fps: number }) {
const target = Math.max(0, Math.min(100, numberOf(t.value)));
const f = ease(frame, fps, (t.atS ?? 0) + 0.25, 1.1);
const pct = Math.round(target * f);
const color = t.tone ? TONE_TEXT[t.tone] : UI.yellow;
return (
<Box s={s} style={{ padding: `${u(2.6 * s)} ${u(3.6 * s)} ${u(3 * s)}`, width: u(82 * s), boxSizing: "border-box" }}>
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
<span style={{ ...label(4 * s, "#ffffff", 0.12) }}>{t.text.toUpperCase()}</span>
<span style={{ fontFamily: FONT_CAPTION, fontSize: u(5.6 * s), color, lineHeight: 1.1 }}>{pct}%</span>
</div>
<div style={{ marginTop: u(1.6 * s), height: u(2.6 * s), borderRadius: u(1.3 * s), background: UI.track, overflow: "hidden" }}>
<div style={{ height: "100%", width: `${target * f}%`, borderRadius: u(1.3 * s), background: color,
boxShadow: `inset 0 ${u(0.6 * s)} 0 rgba(255,255,255,0.28)` }} />
</div>
</Box>
);
}
function GridCard({ t, s, frame, fps }: { t: TextItem; s: number; frame: number; fps: number }) {
const atS = t.atS ?? 0;
const total = Math.max(1, Math.min(40, Math.round(t.total ?? 1)));
const filled = Math.max(0, Math.min(total, Math.round(numberOf(t.value) || 0)));
const cols = total <= 6 ? total : total <= 24 ? 6 : 8;
const side = 7.4 * s;
return (
<Box s={s} style={{ padding: `${u(3.4 * s)} ${u(4 * s)} ${u(3.2 * s)}` }}>
<div style={{ fontFamily: FONT_CAPTION, fontSize: u(6.4 * s), color: "#ffffff", lineHeight: 1.15, marginBottom: u(2.2 * s), whiteSpace: "nowrap" }}>{t.text.toUpperCase()}</div>
<div style={{ display: "grid", gridTemplateColumns: `repeat(${cols}, ${u(side)})`, gap: u(1.3 * s) }}>
{Array.from({ length: total }, (_, i) => {
const k = i < filled ? pop(frame, fps, atS + 0.35 + i * 0.14, 260) : 0;
return (
<div key={i} style={{ position: "relative", width: u(side), height: u(side), boxSizing: "border-box", borderRadius: u(1 * s),
border: `${u(0.45 * s)} solid #3a4166` }}>
{k > 0.001 && (
<div style={{ position: "absolute", inset: u(-0.45 * s), borderRadius: u(1 * s), background: UI.cream, transform: `scale(${0.4 + 0.6 * k})`,
opacity: Math.min(1, k * 1.8), display: "flex", alignItems: "center", justifyContent: "center",
fontFamily: FONT_CAPTION, fontSize: u(4.4 * s), color: UI.ink, lineHeight: 1 }}>{i + 1}</div>
)}
</div>
);
})}
</div>
<div style={{ ...label(3.6 * s, UI.yellow, 0.12), marginTop: u(2.4 * s) }}>{filled} DE {total}</div>
</Box>
);
}
const CARDS = { stat: StatCard, counter: CounterCard, checklist: ChecklistCard, table: TableCard, progress: ProgressCard, grid: GridCard } as const;
export function TextLayer({ t, frame, fps }: { t: TextItem; frame: number; fps: number }) {
const k = pop(frame, fps, t.atS ?? 0);
if (k <= 0.001) return null;
const base = { ...at(t.x, t.y), transform: `translate(-50%, -50%) rotate(${t.rotate ?? 0}deg) scale(${0.4 + 0.6 * k})`, opacity: Math.min(1, k * 1.4) };
if (t.kind === "tag") return <div style={base}><TagLabel text={t.text} tone={t.tone} /></div>;
if (t.kind === "counter") {
const s = t.size ?? 1;
if (t.kind === "namecard") {
// Entra deslizando do lado de fora do quadro, com mola.
const dir = t.x < 0.5 ? -1 : 1;
return (
<div style={{ ...base, textAlign: "center", border: "0.35cqw solid #fff", borderRadius: "1.4cqw", padding: "0.8cqw 2.6cqw",
background: "rgba(10,12,28,0.85)" }}>
<div style={{ fontFamily: FONT_LABEL, fontSize: "2.6cqw", color: "#c9cbe0", letterSpacing: "0.08em" }}>{t.text.toUpperCase()}</div>
<div style={{ fontFamily: FONT_CAPTION, fontSize: "8cqw", color: "#fff", lineHeight: 1 }}>{t.value ?? ""}</div>
<div style={{ ...at(t.x, t.y), transform: `translate(-50%, -50%) translateX(${dir * (1 - k) * 18}%) scale(${0.82 + 0.18 * k})`,
opacity: Math.min(1, k * 1.6) }}>
<NameCard name={t.text} lines={t.lines} size={s} />
</div>
);
}
const s = t.kind === "onomatopoeia" ? shake(frame, 4) : { x: 0, y: 0 };
if (t.kind in CARDS) {
const Card = CARDS[t.kind as keyof typeof CARDS];
return (
<>
{t.panel && <PanelBackdrop k={k} />}
<div style={{ ...at(t.x, t.y), transform: `translate(-50%, -50%) translateY(${(1 - k) * 6}%) scale(${0.8 + 0.2 * k})`, opacity: Math.min(1, k * 1.6) }}>
<Card t={t} s={s} frame={frame} fps={fps} />
</div>
</>
);
}
const base = { ...at(t.x, t.y), transform: `translate(-50%, -50%) rotate(${t.rotate ?? 0}deg) scale(${0.4 + 0.6 * k})`, opacity: Math.min(1, k * 1.4) };
if (t.kind === "tag") return <div style={base}><TagLabel text={t.text} tone={t.tone} /></div>;
const sh = t.kind === "onomatopoeia" ? shake(frame, 4) : { x: 0, y: 0 };
const color = t.tone === "danger" ? COLORS.danger : t.kind === "big" ? "#ffffff" : COLORS.key;
return (
<div style={{ ...base, transform: `${base.transform} translate(${s.x}px, ${s.y}px)`, fontFamily: FONT_CAPTION, color,
<div style={{ ...base, transform: `${base.transform} translate(${sh.x}px, ${sh.y}px)`, fontFamily: FONT_CAPTION, color,
fontSize: t.kind === "big" ? "12cqw" : "9cqw", whiteSpace: "nowrap", WebkitTextStroke: "0.35cqw #121326",
paintOrder: "stroke fill", textShadow: "0 0.6cqw 0 rgba(0,0,0,0.35)" }}>
{t.text.toUpperCase()}
@@ -77,21 +327,61 @@ export function CrossOut({ k }: { k: number }) {
);
}
export function Hud({ hud, frame, fps }: { hud: NonNullable<ShotSpec["hud"]>; frame: number; fps: number }) {
let clock = hud.clock;
if (clock && /^\d{1,2}:\d{2}$/.test(clock) && hud.clockMinutesPerSecond) {
const [h, m] = clock.split(":").map(Number);
const total = (h * 60 + m + Math.floor((frame / fps) * hud.clockMinutesPerSecond)) % (24 * 60);
clock = `${String(Math.floor(total / 60)).padStart(2, "0")}:${String(total % 60).padStart(2, "0")}`;
}
/** Hora do HUD andando: "10:06" + minutos por segundo de trecho. */
export function hudClock(clock: string | undefined, t: number, minutesPerSecond?: number): string | undefined {
if (!clock || !/^\d{1,2}:\d{2}$/.test(clock) || !minutesPerSecond) return clock;
const [h, m] = clock.split(":").map(Number);
const total = (h * 60 + m + Math.floor(t * minutesPerSecond)) % (24 * 60);
return `${String(Math.floor(total / 60)).padStart(2, "0")}:${String(total % 60).padStart(2, "0")}`;
}
/** Valor do HUD zerado ou negativo ("R$ 0,00", "-12") pede vermelho. */
export function hudValueTone(value: string, tone?: Tone): Tone | undefined {
if (tone) return tone;
const v = value.trim();
if (/^[^\d]*-/.test(v)) return "danger";
const digits = v.replace(/[^\d]/g, "");
return digits && Number(digits) === 0 ? "danger" : undefined;
}
/**
* Painel do topo (fixo, sem animação de entrada: continua igual de um trecho para o outro). Esquerda: bloco amarelo
* (`badge`) + hora com ponto vermelho sobre fundo escuro e, embaixo, faixa clara com o lugar. Direita, opcional:
* rótulo pequeno + valor grande e faixa amarela com a nota.
*/
export function Hud({ hud, frame, fps }: { hud: HudSpec; frame: number; fps: number }) {
const clock = hudClock(hud.clock, frame / fps, hud.clockMinutesPerSecond);
const place = hud.place ?? hud.label;
const row = u(8);
const big: React.CSSProperties = { fontFamily: FONT_CAPTION, fontSize: u(5.8), lineHeight: 1, whiteSpace: "nowrap", paddingTop: u(0.3) };
const strip: React.CSSProperties = { ...label(2.5, UI.ink, 0.07), height: u(4.2), display: "flex", alignItems: "center", padding: `0 ${u(2.2)}` };
const shadow = `0 ${u(0.55)} 0 rgba(6,8,18,0.6)`;
const tone = hud.value ? hudValueTone(hud.value, hud.valueTone) : undefined;
return (
<div style={{ position: "absolute", top: "5.5%", left: 0, right: 0, display: "flex", justifyContent: "center", alignItems: "center",
gap: "1.4cqw", fontFamily: FONT_LABEL }}>
<span style={{ background: COLORS.danger, color: "#fff", fontSize: "3.4cqw", padding: "0.2em 0.5em 0.1em", borderRadius: "0.25em" }}>⚡ {hud.badge.toUpperCase()}</span>
<span style={{ color: "#fff", fontSize: "4.2cqw" }}>{hud.label.toUpperCase()}</span>
{clock && <span style={{ background: "#0d0f1f", color: COLORS.key, fontSize: "3.4cqw", padding: "0.2em 0.45em 0.1em", borderRadius: "0.25em",
border: "0.25cqw solid #3a3f6b" }}>{clock}</span>}
</div>
<>
<div style={{ position: "absolute", left: u(4), top: u(4.5), display: "inline-flex", flexDirection: "column", alignItems: "stretch", boxShadow: shadow }}>
<div style={{ display: "flex", height: row, background: clock ? "#11141f" : undefined }}>
<div style={{ ...big, background: UI.yellow, color: UI.ink, display: "flex", alignItems: "center", padding: `0 ${u(2.2)}` }}>{hud.badge.toUpperCase()}</div>
{clock && (
<div style={{ ...big, color: "#ffffff", display: "flex", alignItems: "center", gap: u(1.5), padding: `0 ${u(2.4)} 0 ${u(2.2)}` }}>
<span style={{ width: u(1.6), height: u(1.6), borderRadius: "50%", background: UI.red, marginTop: u(-0.3) }} />
{clock}
</div>
)}
</div>
{place && <div style={{ ...strip, background: UI.cream }}>{place.toUpperCase()}</div>}
</div>
{hud.value && (
<div style={{ position: "absolute", right: u(4), top: u(4.5), display: "inline-flex", flexDirection: "column", alignItems: "flex-end" }}>
<div style={{ display: "flex", height: row, boxShadow: hud.note ? "none" : shadow }}>
{hud.valueLabel && <div style={{ ...label(2.5, UI.muted, 0.1), background: UI.cell, display: "flex", alignItems: "center", padding: `0 ${u(1.5)}` }}>{hud.valueLabel.toUpperCase()}</div>}
<div style={{ ...big, background: "#11141f", color: tone === "danger" ? UI.redSoft : tone ? TONE_TEXT[tone] : "#ffffff", display: "flex", alignItems: "center",
padding: `0 ${u(2.2)}` }}>{hud.value.toUpperCase()}</div>
</div>
{hud.note && <div style={{ ...strip, background: UI.yellow, boxShadow: shadow }}>{hud.note.toUpperCase()}</div>}
</div>
)}
</>
);
}
@@ -107,22 +397,29 @@ export function captionChunks(words: Word[]): Word[][] {
return chunks;
}
export function Captions({ words, frame, fps, y = 0.665 }: { words: Word[]; frame: number; fps: number; y?: number }) {
/**
* Legenda: 2–3 palavras grandes em letra condensada branca, contorno e sombra escuros (deslocada para baixo e à
* esquerda, como a referência); palavra-chave maior e amarela, perigo vermelho.
*/
export function Captions({ words, frame, fps, y = 0.8 }: { words: Word[]; frame: number; fps: number; y?: number }) {
const t = frame / fps;
const chunks = captionChunks(words);
const chunk = chunks.find((c, i) => t >= c[0].startS && (i === chunks.length - 1 || t < chunks[i + 1][0].startS));
if (!chunk) return null;
const last = chunk[chunk.length - 1];
if (t > last.endS + 0.6) return null;
const ink = "#0f1226";
return (
<div style={{ position: "absolute", left: "6%", right: "6%", top: `${y * 100}%`, transform: "translateY(-50%)", display: "flex",
flexWrap: "wrap", justifyContent: "center", alignItems: "baseline", columnGap: "2.2cqw", fontFamily: FONT_CAPTION, lineHeight: 1.05 }}>
<div style={{ position: "absolute", left: "5%", right: "5%", top: `${y * 100}%`, transform: "translateY(-50%)", display: "flex",
flexWrap: "wrap", justifyContent: "center", alignItems: "baseline", columnGap: u(2.4), fontFamily: FONT_CAPTION, lineHeight: 1.08 }}>
{chunk.filter((w) => t >= w.startS).map((w, i) => {
const k = pop(frame, fps, w.startS, 320);
const color = w.tone === "danger" ? COLORS.danger : w.tone === "key" ? COLORS.key : "#ffffff";
const strong = w.tone === "key" || w.tone === "danger";
const color = w.tone === "danger" ? COLORS.danger : w.tone === "key" ? UI.yellow : "#ffffff";
return (
<span key={i} style={{ fontSize: "8.4cqw", color, transform: `scale(${0.55 + 0.45 * k})`, display: "inline-block",
textShadow: "0 0.5cqw 0 rgba(0,0,0,0.55), 0 0 1.4cqw rgba(0,0,0,0.5)" }}>
<span key={i} style={{ fontSize: u(strong ? 12.2 : 9.6), color, transform: `scale(${0.55 + 0.45 * k})`, transformOrigin: "50% 80%", display: "inline-block",
WebkitTextStroke: `${u(strong ? 1.1 : 0.9)} ${ink}`, paintOrder: "stroke fill",
textShadow: `${u(-0.7)} ${u(0.9)} 0 ${ink}, ${u(-0.35)} ${u(0.45)} 0 ${ink}, 0 0 ${u(2)} rgba(0,0,0,0.35)` }}>
{w.text.toUpperCase().replace(/[.,;:]$/, "")}
</span>
);
+513 -93
View File
@@ -1,142 +1,562 @@
// Lugares montados por PEÇAS (não há cenário pronto): paleta + céu/hora + chão + peças posicionadas por
// profundidade (z: 0 = frente, 1 = fundo). Parque de dia, cemitério na névoa, quarto à noite, bunker com foco
// de luz… tudo sai da mesma gramática. Espaço de desenho 1080×1920; chão começa em `horizon` (fração da altura).
//
// Regras de acabamento (valem para toda peça, ver elements/paint.ts): sombreado em 2 tons com a luz vindo da
// esquerda; 3 planos com perspectiva atmosférica (o fundo puxa para a cor do céu/parede, a frente escurece);
// sombra de contato no chão sob cada objeto. Tudo por mistura de cor — nada de blur por quadro.
import React from "react";
import { rng } from "./random";
import type { ShotSpec } from "./spec";
import { makePaint, mix, palette, type Pal, type PaletteId } from "./elements/paint";
import { NATURE, type Draw } from "./elements/nature";
import { BUILT, FRONT_PART } from "./elements/built";
import { INDOOR } from "./elements/indoor";
export const PALETTES = ["night", "sepia", "day", "dusk", "gray"] as const;
export type PaletteId = (typeof PALETTES)[number];
export { PALETTES, palette, type PaletteId } from "./elements/paint";
export const GROUNDS = ["grass", "street", "dirt", "floor", "sand", "water", "none"] as const;
export const ELEMENTS = ["tree", "deadtree", "pine", "bush", "rock", "mountain", "cloud", "bench", "lamp", "gravestone", "cross", "fence",
"house", "building", "car", "sign", "door", "window", "table", "bed", "shelf", "crate", "tent", "fire"] as const;
"house", "building", "car", "sign", "door", "window", "table", "bed", "shelf", "crate", "tent", "fire",
"ark", "ark_frame", "scaffold", "planks", "rainbow", "waves", "palm", "outcrop",
"cabinet", "locker", "frame", "pendant", "desklamp", "desk", "clothesline", "wall", "facade", "shopfront"] as const;
/** Tempo por cima da cena (chuva caindo; tempestade = chuva forte + relâmpago + céu mais escuro). */
export const WEATHERS = ["none", "rain", "storm"] as const;
export type ElementKind = (typeof ELEMENTS)[number];
/** Fonte de luz posicionada (`spec.lightSource`): luminária, janela ou sol. */
export const LIGHT_SOURCES = ["lamp", "window", "sun"] as const;
export type Place = {
ground: (typeof GROUNDS)[number];
/** Interno: parede no lugar do céu (quarto, bunker, loja). */
indoor?: boolean;
/** Linha do horizonte (fração da altura; padrão 0,56). */
/** Linha do horizonte / pé da parede (fração da altura; padrão 0,56 fora e 0,62 dentro). */
horizon?: number;
fog?: boolean;
elements: { kind: ElementKind; x: number; z?: number; scale?: number; flip?: boolean; color?: string }[];
weather?: (typeof WEATHERS)[number];
/** Água cobrindo o lugar: altura da superfície (fração da altura do quadro, 0 = topo) do início ao fim do trecho.
* Ex.: { from: 0.8, to: 0.5 } = a água sobe. O que não boia fica embaixo dela. */
flood?: { from: number; to: number };
elements: {
kind: ElementKind; x: number; z?: number; scale?: number; flip?: boolean; color?: string;
/** Sobe a peça (fração da altura do quadro): arca em cima do monte. */
lift?: number;
/** Boia na água (com `flood`, acompanha a superfície e balança). */
float?: boolean;
/** Tem gente DENTRO (arca, carro): a parte da frente da peça é desenhada por cima dos personagens. */
occupied?: boolean;
}[];
};
type Pal = { sky: [string, string]; wall: string; ground: Record<string, string>; far: string; near: string; ink: string; leaf: string; trunk: string; stone: string; light: string };
const P: Record<PaletteId, Pal> = {
night: { sky: ["#0b0e22", "#1c2147"], wall: "#2a2f4a", far: "#2a2d57", near: "#3b3f74", ink: "#0c0d1a", leaf: "#24445a", trunk: "#2b2338", stone: "#5a5f86", light: "#ffc94a",
ground: { grass: "#1d2e3a", street: "#1a1d38", dirt: "#2a2433", floor: "#22243a", sand: "#4a4560", water: "#152a4a" } },
sepia: { sky: ["#c9ad83", "#e8d6ae"], wall: "#7d6a55", far: "#a88f6e", near: "#6e5843", ink: "#2a2018", leaf: "#7b7a45", trunk: "#5a4330", stone: "#9b9387", light: "#ffd98a",
ground: { grass: "#8b8a52", street: "#6a5a4a", dirt: "#7a5a3c", floor: "#5e4c3c", sand: "#d2b886", water: "#6f8a8a" } },
day: { sky: ["#5aa9e6", "#cfeaf8"], wall: "#e9dcc5", far: "#9cc3d9", near: "#d98a5c", ink: "#22252e", leaf: "#4caf50", trunk: "#7a5232", stone: "#a9adb5", light: "#fff3b0",
ground: { grass: "#78c25a", street: "#8a8f99", dirt: "#b88a5a", floor: "#c9a77c", sand: "#f0d79a", water: "#3f9ad8" } },
dusk: { sky: ["#2a2c5c", "#e8946a"], wall: "#4a3a52", far: "#4c3f6e", near: "#6a4a62", ink: "#140f1c", leaf: "#2f4a3f", trunk: "#3a2a2a", stone: "#7a7090", light: "#ffcf7a",
ground: { grass: "#3a4a3a", street: "#3a3348", dirt: "#4a3530", floor: "#3c3040", sand: "#a87d6a", water: "#4a5a8a" } },
gray: { sky: ["#6f7680", "#b4b9bf"], wall: "#565b63", far: "#8a9098", near: "#5c6168", ink: "#1b1d21", leaf: "#5a6b55", trunk: "#4a4038", stone: "#9aa0a8", light: "#f2e6c8",
ground: { grass: "#5f6e55", street: "#4a4f57", dirt: "#5e5246", floor: "#45484f", sand: "#a8a08a", water: "#5a6f80" } },
};
export const palette = (id: PaletteId | undefined): Pal => P[id ?? "night"] ?? P.night;
const W = 1080;
const H = 1920;
const DRAW: Record<string, Draw> = { ...NATURE, ...BUILT, ...INDOOR };
function mix(a: string, b: string, k: number): string {
const pa = parseInt(a.slice(1), 16);
const pb = parseInt(b.slice(1), 16);
const ch = (s: number) => Math.round(((pa >> s) & 255) * (1 - k) + ((pb >> s) & 255) * k);
return `#${[16, 8, 0].map((s) => ch(s).toString(16).padStart(2, "0")).join("")}`;
/** Peças presas na parede do fundo quando o lugar é interno (o z delas é ignorado). */
const WALL_MOUNTED = new Set<ElementKind>(["window", "frame", "door"]);
/** Peças penduradas no teto: a origem é o topo do quadro. */
const CEILING = new Set<ElementKind>(["pendant"]);
/** Objetos de mesa: sobem sozinhos para cima da mesa/escrivaninha mais próxima (se não tiver `lift`). */
const ON_TOP = new Set<ElementKind>(["desklamp"]);
/** Altura do tampo (unidades da peça) das superfícies que recebem objetos de mesa. */
const SURFACE_TOP: Partial<Record<ElementKind, number>> = { desk: 330, table: 304 };
/** Só as peças assimétricas espelham; nas simétricas o `flip` trocaria só o lado da sombra (a luz é sempre da esquerda). */
const FLIPPABLE = new Set<ElementKind>(["deadtree", "palm", "car", "bed", "desklamp", "waves", "clothesline", "outcrop"]);
/** Meia largura da base de cada peça (unidades da peça) para a sombra de contato; 0 = sem sombra. */
const FOOT: Partial<Record<ElementKind, number>> = {
tree: 130, deadtree: 90, pine: 190, bush: 220, rock: 130, bench: 270, lamp: 60, gravestone: 125, cross: 60, fence: 470,
house: 420, building: 280, car: 390, sign: 40, table: 290, bed: 400, shelf: 230, crate: 170, tent: 350, fire: 130,
ark: 380, ark_frame: 380, scaffold: 140, planks: 185, palm: 80, outcrop: 340, cabinet: 185, locker: 330, desk: 340,
wall: 730, facade: 560, shopfront: 460, desklamp: 90, clothesline: 0,
};
const isNight = (id: PaletteId | undefined) => (id ?? "night") === "night";
/** Zoom do fundo pelo enquadramento: em meio corpo/de perto a câmera está mais perto, o fundo cresce junto. */
function backgroundZoom(spec: ShotSpec): number {
const framings = (spec.actors ?? []).flatMap((a) => (a.kind === "person" && a.framing ? [a.framing] : []));
if (framings.includes("close")) return 1.32;
if (framings.includes("medium")) return 1.16;
return 1;
}
/** Uma peça desenhada com a base em (0,0), altura de referência ~300 px. */
function Element({ kind, pal, color, seed }: { kind: ElementKind; pal: Pal; color?: string; seed: number }) {
const r = rng(seed);
switch (kind) {
case "tree": return <g><rect x={-14} y={-150} width={28} height={150} fill={pal.trunk} /><circle cx={0} cy={-210} r={95} fill={color ?? pal.leaf} /><circle cx={-60} cy={-170} r={60} fill={color ?? pal.leaf} /><circle cx={62} cy={-175} r={62} fill={color ?? pal.leaf} /></g>;
case "pine": return <g><rect x={-12} y={-60} width={24} height={60} fill={pal.trunk} /><polygon points="0,-330 -90,-60 90,-60" fill={color ?? pal.leaf} /></g>;
case "deadtree": return <g stroke={color ?? pal.trunk} strokeLinecap="round" fill="none"><path d="M0 0 L0 -220" strokeWidth={26} /><path d="M0 -120 L-70 -200 M-40 -160 L-80 -150 M0 -170 L60 -250 M30 -210 L80 -215 M0 -220 L-20 -280" strokeWidth={12} /></g>;
case "bush": return <g fill={color ?? pal.leaf}><circle cx={-40} cy={-35} r={42} /><circle cx={10} cy={-50} r={52} /><circle cx={55} cy={-30} r={38} /></g>;
case "rock": return <path d="M-70 0 Q-80 -50 -30 -70 Q20 -90 60 -50 Q85 -20 70 0 Z" fill={color ?? pal.stone} />;
case "mountain": return <g><polygon points="-520,0 0,-520 520,0" fill={color ?? pal.far} /><polygon points="-110,-410 0,-520 110,-410 50,-430 0,-400 -50,-430" fill="#ffffff" opacity={0.6} /></g>;
case "cloud": return <g fill={color ?? "#ffffff"} opacity={0.85}><ellipse cx={0} cy={-40} rx={110} ry={40} /><circle cx={-40} cy={-70} r={45} /><circle cx={30} cy={-80} r={55} /></g>;
case "bench": return <g fill={color ?? "#8a5a3a"}><rect x={-110} y={-70} width={220} height={16} rx={4} /><rect x={-110} y={-120} width={220} height={14} rx={4} /><rect x={-95} y={-70} width={12} height={70} fill={pal.ink} /><rect x={83} y={-70} width={12} height={70} fill={pal.ink} /></g>;
case "lamp": return <g><rect x={-7} y={-420} width={14} height={420} fill={pal.ink} /><rect x={-36} y={-440} width={72} height={26} rx={8} fill={pal.ink} /><ellipse cx={0} cy={-408} rx={26} ry={8} fill={pal.light} /><path d="M-24 -408 L-140 0 L140 0 L24 -408 Z" fill={pal.light} opacity={0.08} /></g>;
case "gravestone": return <g><path d="M-55 0 L-55 -130 Q-55 -185 0 -185 Q55 -185 55 -130 L55 0 Z" fill={color ?? pal.stone} /><rect x={-28} y={-120} width={56} height={6} rx={3} fill={pal.ink} opacity={0.35} /><rect x={-22} y={-100} width={44} height={6} rx={3} fill={pal.ink} opacity={0.35} /></g>;
case "cross": return <g fill={color ?? pal.stone}><rect x={-12} y={-200} width={24} height={200} /><rect x={-60} y={-160} width={120} height={22} /></g>;
case "fence": return <g fill={color ?? pal.ink}>{Array.from({ length: 9 }, (_, i) => <rect key={i} x={-200 + i * 50} y={-130} width={14} height={130} />)}<rect x={-210} y={-110} width={430} height={10} /><rect x={-210} y={-50} width={430} height={10} /></g>;
case "house": return <g><polygon points="-150,-180 0,-290 150,-180" fill={pal.ink} opacity={0.6} /><rect x={-140} y={-180} width={280} height={180} fill={color ?? pal.near} /><rect x={-110} y={-140} width={50} height={50} rx={4} fill={pal.light} opacity={r() > 0.5 ? 1 : 0.15} /><rect x={60} y={-140} width={50} height={50} rx={4} fill={pal.light} opacity={r() > 0.5 ? 1 : 0.15} /><rect x={-25} y={-100} width={50} height={100} fill={pal.ink} opacity={0.7} /></g>;
case "building": {
const floors = 4 + Math.floor(r() * 4);
return <g><rect x={-120} y={-floors * 80} width={240} height={floors * 80} fill={color ?? pal.far} />{Array.from({ length: floors * 3 }, (_, i) => <rect key={i} x={-95 + (i % 3) * 70} y={-floors * 80 + 20 + Math.floor(i / 3) * 80} width={44} height={40} fill={pal.light} opacity={r() > 0.7 ? 0.9 : 0.12} />)}</g>;
}
case "car": return <g><path d="M-150 -40 L-150 -90 Q-140 -110 -100 -112 L-60 -160 L70 -160 L110 -112 L150 -100 L150 -40 Z" fill={color ?? "#c8443a"} /><rect x={-50} y={-150} width={50} height={36} fill="#cfe3f3" opacity={0.85} /><rect x={8} y={-150} width={52} height={36} fill="#cfe3f3" opacity={0.85} /><circle cx={-90} cy={-35} r={32} fill={pal.ink} /><circle cx={95} cy={-35} r={32} fill={pal.ink} /></g>;
case "sign": return <g><rect x={-6} y={-220} width={12} height={220} fill={pal.ink} /><rect x={-90} y={-260} width={180} height={70} rx={8} fill={color ?? "#2f6d3a"} stroke="#ffffff" strokeWidth={5} /></g>;
case "door": return <g><rect x={-80} y={-330} width={160} height={330} rx={4} fill={color ?? "#4a2f22"} /><rect x={-60} y={-305} width={120} height={130} rx={3} fill="#000000" opacity={0.15} /><rect x={-60} y={-155} width={120} height={130} rx={3} fill="#000000" opacity={0.15} /><circle cx={52} cy={-165} r={9} fill="#e6c27a" /></g>;
case "window": return <g><rect x={-120} y={-260} width={240} height={200} rx={6} fill={pal.ink} /><rect x={-108} y={-248} width={216} height={176} fill={color ?? mix(pal.sky[0], pal.sky[1], 0.5)} /><rect x={-4} y={-248} width={8} height={176} fill={pal.ink} /><rect x={-108} y={-164} width={216} height={8} fill={pal.ink} /></g>;
case "table": return <g fill={color ?? "#7a5232"}><rect x={-140} y={-130} width={280} height={20} rx={4} /><rect x={-120} y={-110} width={18} height={110} /><rect x={102} y={-110} width={18} height={110} /></g>;
case "bed": return <g><rect x={-170} y={-90} width={340} height={60} rx={10} fill={color ?? "#5a6aa8"} /><rect x={-170} y={-150} width={24} height={150} fill={pal.trunk} /><rect x={-140} y={-120} width={90} height={34} rx={12} fill="#eeeeee" /><rect x={146} y={-110} width={24} height={110} fill={pal.trunk} /></g>;
case "shelf": return <g><rect x={-120} y={-360} width={240} height={360} fill={color ?? pal.trunk} />{[0, 1, 2, 3].map((i) => <g key={i}><rect x={-108} y={-340 + i * 88} width={216} height={70} fill="#000000" opacity={0.25} />{[0, 1, 2, 3, 4].map((j) => <rect key={j} x={-100 + j * 42} y={-330 + i * 88 + (r() * 14)} width={30} height={56 - (r() * 14)} rx={3} fill={["#e8463d", "#f2c230", "#4fb0e8", "#5cc48a", "#e8e8ee"][(i + j) % 5]} />)}</g>)}</g>;
case "crate": return <g><rect x={-70} y={-140} width={140} height={140} fill={color ?? "#a0743f"} /><path d="M-70 -140 L70 0 M70 -140 L-70 0" stroke="#6e4e28" strokeWidth={10} /><rect x={-70} y={-140} width={140} height={140} fill="none" stroke="#6e4e28" strokeWidth={10} /></g>;
case "tent": return <g><polygon points="-170,0 0,-220 170,0" fill={color ?? "#d9773a"} /><polygon points="-40,0 0,-120 40,0" fill={pal.ink} opacity={0.6} /></g>;
case "fire": return <g><rect x={-60} y={-18} width={120} height={18} rx={6} fill={pal.trunk} /><path d="M-40 -18 Q-50 -80 -10 -120 Q-5 -80 20 -70 Q30 -110 10 -150 Q70 -100 45 -18 Z" fill="#ff8a2a" /><path d="M-15 -18 Q-20 -60 5 -80 Q10 -50 25 -45 Q30 -30 20 -18 Z" fill="#ffd34a" /></g>;
type El = Place["elements"][number] & { i: number; z: number };
type Placed = { e: El; x: number; y: number; s: number; zEff: number; flip: boolean };
type Layout = { horizon: number; indoor: boolean; zoom: number; items: Placed[] };
/** Onde cada peça fica (base, escala, profundidade efetiva). A camada de luz usa a mesma conta. */
export function layoutPlace(spec: ShotSpec): Layout {
const place = spec.place!;
const indoor = !!place.indoor;
const horizon = (place.horizon ?? (indoor ? 0.62 : 0.56)) * H;
const near = indoor ? H * 0.8 : H * 0.72;
const items: Placed[] = place.elements.map((raw, i) => {
const e: El = { ...raw, i, z: raw.z ?? 0.3 };
const wall = indoor && WALL_MOUNTED.has(e.kind);
const zEff = wall ? 1 : e.z;
const depth = 1 - zEff * (indoor ? 0.35 : 0.62);
const s = (e.scale ?? 1) * depth * 1.15;
let y: number;
if (CEILING.has(e.kind)) y = 0;
else if (e.kind === "cloud") y = horizon * (0.15 + 0.5 * e.z);
else y = horizon + (1 - zEff) * (near - horizon);
y -= (e.lift ?? 0) * H;
return { e, x: e.x * W, y, s, zEff, flip: !!e.flip && FLIPPABLE.has(e.kind) };
});
// Objeto de mesa perto de uma mesa (mesma profundidade, dentro do tampo) vai para cima dela.
for (const it of items) {
if (!ON_TOP.has(it.e.kind) || it.e.lift !== undefined) continue;
const surface = items.find((o) => SURFACE_TOP[o.e.kind] && Math.abs(o.e.z - it.e.z) <= 0.25 && Math.abs(o.x - it.x) < (FOOT[o.e.kind] ?? 0) * o.s);
if (!surface) continue;
it.y = surface.y - SURFACE_TOP[surface.e.kind]! * surface.s;
it.s = surface.s * (it.e.scale ?? 1) * 0.9;
it.zEff = surface.zEff - 0.001;
}
items.sort((a, b) => b.zEff - a.zEff || a.e.i - b.e.i);
return { horizon, indoor, zoom: backgroundZoom(spec), items };
}
/** Sol/lua no céu (sempre do lado esquerdo: é de lá que vem a luz das peças). */
export function sunOf(id: PaletteId | undefined, horizon: number): { x: number; y: number; r: number } | null {
switch (id ?? "night") {
case "day": return { x: W * 0.2, y: H * 0.2, r: 66 };
case "sepia": return { x: W * 0.2, y: H * 0.19, r: 70 };
case "dusk": return { x: W * 0.2, y: horizon - H * 0.13, r: 96 };
case "night": return { x: W * 0.22, y: H * 0.15, r: 44 };
default: return null;
}
}
export function PlaceBackground({ spec, frame }: { spec: ShotSpec; frame: number }) {
/** Altura da superfície da água no instante (fração da altura; null = sem enchente). */
export function floodLevel(place: Place | undefined, progress: number): number | null {
if (!place?.flood) return null;
const p = Math.max(0, Math.min(1, progress));
const k = p < 0.5 ? 2 * p * p : 1 - (-2 * p + 2) ** 2 / 2;
return place.flood.from + (place.flood.to - place.flood.from) * k;
}
/** Uma peça no lugar: sombra de contato + desenho com a tinta da profundidade dela. */
function PlacedElement({ it, pal, spec, hazeColor, y, rot = 0, part }: { it: Placed; pal: Pal; spec: ShotSpec; hazeColor: string; y?: number; rot?: number; part?: "front" }) {
const { e } = it;
const place = spec.place!;
const indoor = !!place.indoor;
const z = it.zEff;
const sky = e.kind === "cloud" || e.kind === "rainbow";
const haze = sky ? 0.12 : indoor ? z * 0.22 : Math.min(0.85, Math.pow(z, 1.8) * 0.66 + (place.fog ? 0.04 + z * 0.16 : 0));
const front = !sky && z < 0.25 ? (0.25 - z) * 0.5 : 0;
const p = makePaint(pal, rng(spec.seed + e.i * 17), { haze, hazeColor, front, indoor, night: isNight(spec.palette) });
const draw = part === "front" ? FRONT_PART[e.kind] : DRAW[e.kind];
if (!draw) return null;
const foot = (CEILING.has(e.kind) || (indoor && WALL_MOUNTED.has(e.kind)) || e.float || (e.lift ?? 0) > 0.02) ? 0 : FOOT[e.kind] ?? 0;
const s = it.s;
return (
<g transform={`translate(${it.x} ${y ?? it.y}) rotate(${rot}) scale(${it.flip ? -s : s} ${s})`}>
{foot > 0 && part !== "front" && <ellipse cx={foot * 0.1} cy={4} rx={foot * 1.12} ry={Math.min(46, Math.max(16, foot * 0.11))} fill="url(#cShadow)" opacity={1 - z * 0.5} />}
{draw(p, e.color)}
</g>
);
}
/** Céu com degradê rico, sol/lua com halo (ou parede do interior). Não muda com o quadro. */
function SkyLayer({ spec, horizon }: { spec: ShotSpec; horizon: number }) {
const pal = palette(spec.palette);
const place = spec.place!;
if (place.indoor) {
const wallTop = mix(pal.wall, pal.ink, 0.42);
return <g>
<defs>
<linearGradient id="placeWall" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stopColor={wallTop} /><stop offset="0.45" stopColor={mix(pal.wall, pal.ink, 0.12)} /><stop offset="1" stopColor={pal.wall} />
</linearGradient>
<linearGradient id="placeCorner" x1="0" y1="0" x2="1" y2="0">
<stop offset="0" stopColor={pal.shade} stopOpacity={0.4} /><stop offset="0.16" stopColor={pal.shade} stopOpacity={0} />
<stop offset="0.84" stopColor={pal.shade} stopOpacity={0} /><stop offset="1" stopColor={pal.shade} stopOpacity={0.45} />
</linearGradient>
</defs>
<rect width={W} height={H} fill="url(#placeWall)" />
</g>;
}
const sun = sunOf(spec.palette, horizon);
const night = isNight(spec.palette);
return <g>
<defs>
<linearGradient id="placeSky" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2={horizon}>
<stop offset="0" stopColor={pal.sky[0]} /><stop offset="0.55" stopColor={pal.sky[1]} /><stop offset="1" stopColor={pal.sky[2]} />
</linearGradient>
{sun && <radialGradient id="placeHalo" gradientUnits="userSpaceOnUse" cx={sun.x} cy={sun.y} r={sun.r * 4.2}>
<stop offset="0" stopColor={pal.halo} stopOpacity={night ? 0.35 : 0.75} /><stop offset="0.35" stopColor={pal.halo} stopOpacity={night ? 0.12 : 0.3} />
<stop offset="1" stopColor={pal.halo} stopOpacity={0} />
</radialGradient>}
</defs>
<rect width={W} height={H} fill="url(#placeSky)" />
{sun && <>
<circle cx={sun.x} cy={sun.y} r={sun.r * 4.2} fill="url(#placeHalo)" />
<circle cx={sun.x} cy={sun.y} r={sun.r} fill={pal.sun} />
{night
? <><circle cx={sun.x + 12} cy={sun.y - 8} r={9} fill={mix(pal.sun, "#b0a890", 0.4)} /><circle cx={sun.x - 14} cy={sun.y + 12} r={6} fill={mix(pal.sun, "#b0a890", 0.4)} /></>
: <circle cx={sun.x - sun.r * 0.25} cy={sun.y - sun.r * 0.25} r={sun.r * 0.55} fill="#ffffff" opacity={0.35} />}
</>}
</g>;
}
/** Chão (degradê + textura) e, ao fundo, a silhueta distante (morros ou cidade). */
function GroundLayer({ spec, horizon, hazeColor }: { spec: ShotSpec; horizon: number; hazeColor: string }) {
const place = spec.place!;
const pal = palette(spec.palette);
const horizon = (place.horizon ?? 0.56) * H;
const rand = rng(spec.seed + 29);
const out: React.ReactNode[] = [];
const g = place.ground === "none" ? null : pal.ground[place.ground];
const span = H - horizon;
if (place.indoor) {
// Parede: lambri (meia-parede) ou listras, conforme a semente; rodapé no pé da parede.
const wall = pal.wall;
if (spec.seed % 2 === 0) {
const top = horizon - H * 0.17;
out.push(<rect key="dado" x={0} y={top} width={W} height={horizon - top} fill={mix(wall, pal.ink, 0.16)} />);
out.push(<path key="dadoP" d={Array.from({ length: 8 }, (_, i) => `M${i * 150 + 40} ${top + 30} L${i * 150 + 40} ${horizon - 40} L${i * 150 + 150} ${horizon - 40}`).join(" ")}
stroke={mix(wall, pal.ink, 0.3)} strokeWidth={6} fill="none" />);
out.push(<rect key="rail" x={0} y={top - 16} width={W} height={18} fill={mix(wall, pal.light, 0.22)} />);
out.push(<rect key="railS" x={0} y={top + 2} width={W} height={6} fill={mix(wall, pal.ink, 0.35)} />);
} else {
out.push(<path key="stripes" d={Array.from({ length: 12 }, (_, i) => `M${i * 96 + 30} 0 L${i * 96 + 30} ${horizon}`).join(" ")} stroke={mix(wall, pal.ink, 0.1)} strokeWidth={26} />);
}
out.push(<rect key="corner" x={0} y={0} width={W} height={horizon} fill="url(#placeCorner)" />);
} else if (place.ground === "grass" || place.ground === "dirt" || place.ground === "sand") {
// Morros distantes em 2 camadas, bem apagados (plano de fundo).
const ridge = (h: number, amp: number, seed: number) => {
const r = rng(seed);
let d = `M0 ${horizon + 2} L0 ${horizon - h}`;
for (let x = 0; x <= W + 180; x += 180) d += ` Q${x + 90} ${horizon - h - amp * (0.4 + r())} ${x + 180} ${horizon - h + (r() - 0.5) * amp * 0.5}`;
return d + ` L${W} ${horizon + 2} Z`;
};
out.push(<path key="r1" d={ridge(H * 0.075, H * 0.05, spec.seed + 3)} fill={mix(pal.far, hazeColor, 0.55)} />);
out.push(<path key="r2" d={ridge(H * 0.03, H * 0.03, spec.seed + 7)} fill={mix(g ?? pal.far, hazeColor, 0.45)} />);
} else if (place.ground === "street") {
// Cidade ao longe: blocos apagados com algumas janelas.
let x = -20;
const blocks: React.ReactNode[] = [];
while (x < W) {
const w = 90 + rand() * 120;
const h = H * (0.05 + rand() * 0.09);
blocks.push(<rect key={x} x={x} y={horizon - h} width={w} height={h + 2} fill={mix(pal.far, hazeColor, 0.5 + rand() * 0.15)} />);
x += w - 6;
}
out.push(<g key="city">{blocks}</g>);
}
if (g) {
out.push(<rect key="ground" x={0} y={horizon} width={W} height={span} fill="url(#placeGround)" />);
if (place.ground === "floor") {
// Tábuas em perspectiva: linhas que fogem para o ponto de fuga, juntas desencontradas, tom alternado.
const vpY = horizon - H * 0.3;
const k = (H - vpY) / (horizon - vpY);
const at = (xh: number, y: number) => W / 2 + (xh - W / 2) * ((y - vpY) / (horizon - vpY));
const n = 16;
const step = W / 9;
let seams = "";
for (let i = -n; i <= n; i++) {
const xh = W / 2 + i * step * 0.5;
if (Math.abs(i) % 2 === 1) {
const x2 = W / 2 + (i + 1) * step * 0.5;
out.push(<polygon key={`pl${i}`} points={`${xh},${horizon} ${x2},${horizon} ${W / 2 + (x2 - W / 2) * k},${H} ${W / 2 + (xh - W / 2) * k},${H}`} fill={mix(g, pal.ink, 0.06)} />);
}
seams += `M${xh} ${horizon} L${W / 2 + (xh - W / 2) * k} ${H} `;
for (let j = 0; j < 3; j++) {
const y = horizon + span * Math.pow(rand(), 1.4);
const xa = at(xh, y);
const xb = at(xh + step * 0.5, y);
seams += `M${xa} ${y} L${xb} ${y} `;
}
}
out.push(<path key="seams" d={seams} stroke={mix(g, pal.ink, 0.32)} strokeWidth={4} fill="none" />);
out.push(<rect key="base" x={0} y={horizon - 34} width={W} height={36} fill={mix(pal.wall, pal.ink, 0.38)} />);
out.push(<rect key="baseT" x={0} y={horizon - 34} width={W} height={7} fill={mix(pal.wall, pal.light, 0.15)} />);
out.push(<rect key="ao" x={0} y={horizon} width={W} height={26} fill={pal.ink} opacity={0.18} />);
} else if (place.ground === "street") {
const walk = horizon + span * 0.16;
const walkC = mix(mix("#d2c8b4", g, 0.3), hazeColor, 0.15);
out.push(<rect key="walk" x={0} y={horizon} width={W} height={walk - horizon} fill={walkC} />);
out.push(<path key="tiles" d={Array.from({ length: 14 }, (_, i) => { const x = -120 + i * 110; return `M${x} ${horizon} L${W / 2 + (x - W / 2) * 1.25} ${walk}`; }).join(" ") + ` M0 ${(horizon + walk) / 2} L${W} ${(horizon + walk) / 2}`}
stroke={mix(walkC, pal.ink, 0.18)} strokeWidth={3} fill="none" />);
out.push(<rect key="curb" x={0} y={walk} width={W} height={18} fill={mix(walkC, pal.light, 0.25)} />);
out.push(<rect key="curbS" x={0} y={walk + 18} width={W} height={20} fill={mix(g, pal.ink, 0.35)} />);
const lane = walk + (H - walk) * 0.42;
out.push(<path key="lane" d={Array.from({ length: 7 }, (_, i) => `M${i * 190 - 60} ${lane} l120 0`).join(" ")} stroke="#f2ecd8" strokeWidth={12} opacity={0.55} />);
} else if (place.ground === "grass" || place.ground === "dirt" || place.ground === "sand") {
// Faixas na perspectiva + tufos/pedrinhas/ondulações, maiores perto da câmera.
for (let b = 1; b < 6; b++) {
const y0 = horizon + span * Math.pow(b / 6, 1.7);
const y1 = horizon + span * Math.pow((b + 0.45) / 6, 1.7);
out.push(<rect key={`band${b}`} x={0} y={y0} width={W} height={y1 - y0} fill={b % 2 ? mix(g, pal.light, 0.06) : mix(g, pal.ink, 0.05)} opacity={0.45} />);
}
let marks = "";
for (let i = 0; i < 46; i++) {
const t = Math.pow(rand(), 0.8);
const y = horizon + span * t;
const x = rand() * W;
const s = 6 + t * 26;
if (place.ground === "grass") marks += `M${x - s} ${y} L${x - s * 0.3} ${y - s * 1.4} L${x} ${y} L${x + s * 0.4} ${y - s * 1.6} L${x + s} ${y} `;
else if (place.ground === "sand") marks += `M${x - s * 3} ${y} Q${x} ${y - s * 0.6} ${x + s * 3} ${y} `;
else marks += `M${x - s * 0.6} ${y} a${s * 0.6} ${s * 0.28} 0 1 0 ${s * 1.2} 0 a${s * 0.6} ${s * 0.28} 0 1 0 ${-s * 1.2} 0 `;
}
out.push(<path key="marks" d={marks} fill={place.ground === "dirt" ? mix(g, pal.ink, 0.14) : "none"}
stroke={place.ground === "grass" ? mix(g, pal.ink, 0.25) : place.ground === "sand" ? mix(g, pal.light, 0.35) : "none"} strokeWidth={place.ground === "sand" ? 5 : 4} strokeLinejoin="round" />);
}
}
return <g>{out}</g>;
}
export function PlaceBackground({ spec, frame, progress = 0 }: { spec: ShotSpec; frame: number; progress?: number }) {
const place = spec.place!;
const pal = palette(spec.palette);
const layout = React.useMemo(() => layoutPlace(spec), [spec]);
const { horizon, zoom } = layout;
const hazeColor = place.indoor ? pal.wall : mix(mix(pal.sky[2], pal.sky[1], 0.25), "#c8ccd6", place.fog ? 0.45 : 0);
const level = floodLevel(place, progress);
const waterY = level === null ? null : level * H;
const storm = place.weather === "storm";
const ground = place.ground === "none" ? null : pal.ground[place.ground];
const elements = [...place.elements].map((e, i) => ({ ...e, i, z: e.z ?? 0.3 })).sort((a, b) => b.z - a.z);
// Tudo que não muda com o quadro é desenhado uma vez só (céu, chão, peças paradas).
const sky = React.useMemo(() => <SkyLayer spec={spec} horizon={horizon} />, [spec, horizon]);
const floating = (it: Placed) => !!it.e.float && waterY !== null;
const staticBack = React.useMemo(() => (
<g>
<GroundLayer spec={spec} horizon={horizon} hazeColor={hazeColor} />
{layout.items.filter((it) => !(it.e.float && place.flood)).map((it) => <PlacedElement key={it.e.i} it={it} pal={pal} spec={spec} hazeColor={hazeColor} />)}
</g>
), [spec, layout]); // eslint-disable-line react-hooks/exhaustive-deps
const rand = rng(spec.seed + 13);
const stars = !place.indoor && (spec.palette ?? "night") === "night"
const stars = !place.indoor && isNight(spec.palette)
? Array.from({ length: 60 }, () => ({ x: rand() * W, y: rand() * horizon * 0.8, r: 1 + rand() * 2, p: rand() * 6 })) : [];
const zoomT = zoom === 1 ? undefined : `translate(${W / 2} ${horizon}) scale(${zoom}) translate(${-W / 2} ${-horizon})`;
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice">
<defs>
<linearGradient id="placeSky" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor={pal.sky[0]} /><stop offset="1" stopColor={pal.sky[1]} /></linearGradient>
<linearGradient id="placeFog" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor="#ffffff" stopOpacity={0} /><stop offset="1" stopColor="#d8dce6" stopOpacity={0.35} /></linearGradient>
<linearGradient id="placeFog" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor="#ffffff" stopOpacity={0} />
<stop offset="0.3" stopColor="#d8dce6" stopOpacity={0.3} /><stop offset="1" stopColor="#d8dce6" stopOpacity={0.06} /></linearGradient>
<radialGradient id="cShadow"><stop offset="0" stopColor={pal.ink} stopOpacity={0.5} /><stop offset="0.6" stopColor={pal.ink} stopOpacity={0.28} /><stop offset="1" stopColor={pal.ink} stopOpacity={0} /></radialGradient>
{ground && <linearGradient id="placeGround" x1="0" y1="0" x2="0" y2="1">
{place.indoor
? <><stop offset="0" stopColor={mix(ground, pal.ink, 0.3)} /><stop offset="0.18" stopColor={ground} /><stop offset="1" stopColor={mix(ground, pal.ink, 0.32)} /></>
: <><stop offset="0" stopColor={mix(ground, hazeColor, 0.35)} /><stop offset="0.3" stopColor={ground} /><stop offset="1" stopColor={mix(ground, pal.ink, 0.22)} /></>}
</linearGradient>}
<linearGradient id="placeWater" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor={mix(pal.ground.water, "#ffffff", 0.12)} /><stop offset="1" stopColor={mix(pal.ground.water, pal.ink, 0.35)} /></linearGradient>
</defs>
<rect width={W} height={H} fill={place.indoor ? pal.wall : "url(#placeSky)"} />
{sky}
{stars.map((s, i) => <circle key={i} cx={s.x} cy={s.y} r={s.r} fill="#fff" opacity={0.3 + 0.3 * Math.sin(frame / 12 + s.p)} />)}
{!place.indoor && (spec.palette ?? "night") === "night" && <circle cx={W * 0.78} cy={H * 0.12} r={40} fill="#f4ecc8" />}
{!place.indoor && (spec.palette === "day" || spec.palette === "sepia") && <circle cx={W * 0.8} cy={H * 0.1} r={60} fill={pal.light} opacity={0.9} />}
{place.indoor && <rect x={0} y={horizon - 18} width={W} height={18} fill={pal.ink} opacity={0.25} />}
{ground && <rect x={0} y={horizon} width={W} height={H - horizon} fill={ground} />}
{place.ground === "street" && Array.from({ length: 8 }, (_, i) => <rect key={i} x={i * 150 - 40} y={horizon + (H - horizon) * 0.32} width={90} height={9} rx={4} fill="#ffffff" opacity={0.25} />)}
{elements.map((e) => {
// Profundidade: mais ao fundo = mais perto do horizonte, menor e mais apagado (névoa/atmosfera).
const baseY = e.kind === "cloud" ? horizon * (0.15 + 0.5 * e.z) : horizon + (1 - e.z) * (H * 0.72 - horizon);
const scale = (e.scale ?? 1) * (1 - e.z * 0.62) * 1.15;
const fade = e.kind === "cloud" ? 0 : e.z * (place.fog ? 0.7 : 0.35);
return (
<g key={e.i} transform={`translate(${e.x * W} ${baseY}) scale(${e.flip ? -scale : scale} ${scale})`} opacity={1 - fade * 0.3}>
<Element kind={e.kind} pal={pal} color={e.color ?? (fade > 0.05 && e.kind !== "fire" ? undefined : undefined)} seed={spec.seed + e.i * 17} />
<g transform={zoomT}>
{staticBack}
{waterY !== null && (
<g>
<rect x={0} y={waterY} width={W} height={H - waterY} fill="url(#placeWater)" />
<path d={`M0 ${waterY} ${Array.from({ length: 10 }, (_, i) => `Q${i * 108 + 54} ${waterY - 22 + Math.sin(frame / 9 + i) * 8} ${(i + 1) * 108} ${waterY}`).join(" ")}`}
stroke="#ffffff" strokeWidth={7} fill="none" opacity={0.55} />
</g>
);
})}
{place.fog && <rect x={0} y={horizon - H * 0.15} width={W} height={H * 0.5} fill="url(#placeFog)" />}
)}
{place.ground === "water" && waterY === null && Array.from({ length: 6 }, (_, i) => (
<path key={`w${i}`} d={`M${((i * 197 + frame * 2) % (W + 200)) - 100} ${horizon + 60 + i * ((H - horizon) / 6)} q30 -16 60 0 q30 16 60 0`} stroke="#ffffff" strokeWidth={5} fill="none" opacity={0.35} />
))}
{layout.items.filter(floating).map((it) => (
// Boia: a quilha fica um pouco abaixo da superfície e a peça balança com a água.
<PlacedElement key={it.e.i} it={it} pal={pal} spec={spec} hazeColor={hazeColor}
y={waterY! + H * 0.035 + Math.sin(frame / 14 + it.e.i) * 9} rot={Math.sin(frame / 22 + it.e.i) * (storm ? 3.5 : 1.6)} />
))}
{waterY !== null && <rect x={0} y={waterY + H * 0.03} width={W} height={H} fill={pal.ground.water} opacity={0.35} />}
</g>
{place.fog && <rect x={0} y={horizon - H * 0.18} width={W} height={H - horizon + H * 0.18} fill="url(#placeFog)" />}
</svg>
);
}
/** Foco de luz vindo do teto (bunker, interrogatório) ou vinheta de anoitecer, por cima de tudo. */
export function LightLayer({ light, palette: id }: { light: ShotSpec["light"]; palette?: PaletteId }) {
if (!light || light === "none") return null;
const pal = palette(id);
if (light === "vignette") {
return <div style={{ position: "absolute", inset: 0, background: "radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 45%, rgba(0,0,0,0.55) 100%)" }} />;
type LightSpot = { kind: "lamp" | "window" | "sun" | "glow"; x: number; y: number; w?: number; h?: number; spread?: number; fixture?: boolean };
/** Fonte de luz do trecho: a escolhida no spec, ou deduzida das peças (luminária > janela > sol). */
export function resolveLight(spec: ShotSpec | undefined, light: ShotSpec["light"]): LightSpot | null {
if (light === "none") return null;
const src = spec?.lightSource;
if (src) {
const dy = src.kind === "lamp" ? 0.2 : src.kind === "window" ? 0.32 : 0.2;
return { kind: src.kind, x: src.x * W, y: (src.y ?? dy) * H, w: W * 0.3, h: H * 0.18 };
}
const place = spec?.scene.kind === "place" ? spec.place : undefined;
const layout = place ? layoutPlace(spec!) : null;
const toScreen = (x: number, y: number) => layout && layout.zoom !== 1
? { x: W / 2 + (x - W / 2) * layout.zoom, y: layout.horizon + (y - layout.horizon) * layout.zoom } : { x, y };
const pendant = layout?.items.find((it) => it.e.kind === "pendant");
if (pendant && (light === "spot" || light === undefined)) {
const z = layout!.zoom;
const b = toScreen(pendant.x, pendant.y + 376 * pendant.s);
return { kind: "lamp", x: b.x, y: b.y, spread: 130 * pendant.s * z };
}
// Luminária de mesa acesa: brilho quente em volta da cúpula, o resto do lugar no escuro.
const desk = layout?.items.find((it) => it.e.kind === "desklamp");
if (desk && light === undefined) {
const k = desk.flip ? -1 : 1;
const a = toScreen(desk.x + k * 40 * desk.s, desk.y - 130 * desk.s);
return { kind: "glow", x: a.x, y: a.y, spread: 420 * desk.s * layout!.zoom };
}
if (light === "spot") return { kind: "lamp", x: W / 2, y: H * 0.045, spread: W * 0.07, fixture: true };
if (light !== undefined || !place || !layout) return null;
if (place.indoor) {
const win = layout.items.find((it) => it.e.kind === "window");
if (!win) return null;
const a = toScreen(win.x - 186 * win.s, win.y - 616 * win.s);
const b = toScreen(win.x + 186 * win.s, win.y - 244 * win.s);
return { kind: "window", x: (a.x + b.x) / 2, y: (a.y + b.y) / 2, w: b.x - a.x, h: b.y - a.y };
}
const sun = sunOf(spec!.palette, layout.horizon);
if (!sun || isNight(spec!.palette)) return null;
return { kind: "sun", x: sun.x, y: sun.y };
}
/**
* Luz por cima de tudo (inclusive dos personagens). Fonte POSICIONADA: luminária (cone + poça no chão), janela
* (raios em diagonal + manchas no piso) ou sol (brilho quente). Contraste quente (luz) × frio (sombra).
* `light: "vignette"` escurece as bordas; `"none"` desliga; sem `light`, a fonte sai das peças do lugar.
*/
export function LightLayer({ light, palette: id, spec }: { light: ShotSpec["light"]; palette?: PaletteId; spec?: ShotSpec }) {
const pal = palette(id ?? spec?.palette);
const src = resolveLight(spec, light);
const vignette = light === "vignette";
if (!src && !vignette) return null;
const indoor = !!spec?.place?.indoor;
const horizon = spec?.place ? (spec.place.horizon ?? (indoor ? 0.62 : 0.56)) * H : H * 0.6;
const night = isNight(id ?? spec?.palette);
const warm = night && src?.kind === "window" ? "#a8c0ff" : pal.light;
const layers: React.ReactNode[] = [];
const defs: React.ReactNode[] = [];
if (src?.kind === "lamp") {
const floorY = indoor || !spec?.place ? Math.max(src.y + H * 0.3, horizon + (H - horizon) * 0.55) : H * 0.84;
const sw = src.spread ?? W * 0.08;
const spread = (floorY - src.y) * 0.42 + sw;
defs.push(<linearGradient key="c" id="lgCone" gradientUnits="userSpaceOnUse" x1="0" y1={src.y} x2="0" y2={floorY}>
<stop offset="0" stopColor={warm} stopOpacity={0.42} /><stop offset="1" stopColor={warm} stopOpacity={0.06} /></linearGradient>);
defs.push(<radialGradient key="p" id="lgPool"><stop offset="0" stopColor={warm} stopOpacity={0.4} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
defs.push(<radialGradient key="d" id="lgDark" gradientUnits="userSpaceOnUse" cx={src.x} cy={(src.y + floorY) / 2} r={H * 0.62}>
<stop offset="0.3" stopColor={pal.shade} stopOpacity={0} /><stop offset="1" stopColor={pal.shade} stopOpacity={0.62} /></radialGradient>);
layers.push(<rect key="dark" width={W} height={H} fill="url(#lgDark)" />);
layers.push(<polygon key="cone" points={`${src.x - sw * 0.92},${src.y} ${src.x + sw * 0.92},${src.y} ${src.x + spread},${floorY} ${src.x - spread},${floorY}`} fill="url(#lgCone)" />);
layers.push(<ellipse key="pool" cx={src.x} cy={floorY} rx={spread * 1.15} ry={spread * 0.2} fill="url(#lgPool)" />);
if (src.fixture) {
layers.push(<path key="fx" d={`M${src.x - sw} ${src.y} Q${src.x - sw * 0.9} ${src.y - 60} ${src.x} ${src.y - 64} Q${src.x + sw * 0.9} ${src.y - 60} ${src.x + sw} ${src.y} Z`} fill={mix(pal.ink, "#4a5270", 0.5)} />);
layers.push(<ellipse key="fxl" cx={src.x} cy={src.y} rx={sw} ry={12} fill={warm} />);
}
} else if (src?.kind === "window") {
const ww = src.w ?? W * 0.3;
const wh = src.h ?? H * 0.18;
const x0 = src.x - ww / 2;
const y0 = src.y - wh / 2;
const dir = src.x < W / 2 ? 1 : -1;
const vx = dir * W * 0.78;
const vy = H * 0.55;
const pane = (a: number, b: number) => {
// Retângulo da vidraça arrastado na direção dos raios (contorno convexo).
const xa = x0 + ww * a;
const xb = x0 + ww * b;
const [l, r] = dir > 0 ? [xa, xb] : [xb, xa];
return `${l},${y0} ${r},${y0} ${r + vx},${y0 + vy} ${r + vx},${y0 + wh + vy} ${l + vx},${y0 + wh + vy} ${l},${y0 + wh}`;
};
defs.push(<linearGradient key="b" id="lgBeam" gradientUnits="userSpaceOnUse" x1={src.x} y1={src.y} x2={src.x + vx} y2={src.y + vy}>
<stop offset="0" stopColor={warm} stopOpacity={night ? 0.16 : 0.34} /><stop offset="1" stopColor={warm} stopOpacity={0} /></linearGradient>);
defs.push(<radialGradient key="g" id="lgGlow" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={W * 0.75}>
<stop offset="0" stopColor={warm} stopOpacity={night ? 0.12 : 0.24} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
defs.push(<linearGradient key="k" id="lgCool" x1={dir > 0 ? 1 : 0} y1="0" x2={dir > 0 ? 0 : 1} y2="0">
<stop offset="0" stopColor={pal.shade} stopOpacity={0.4} /><stop offset="0.6" stopColor={pal.shade} stopOpacity={0} /></linearGradient>);
layers.push(<rect key="cool" width={W} height={H} fill="url(#lgCool)" />);
layers.push(<rect key="glow" width={W} height={H} fill="url(#lgGlow)" />);
layers.push(<polygon key="b1" points={pane(0, 0.47)} fill="url(#lgBeam)" />);
layers.push(<polygon key="b2" points={pane(0.53, 1)} fill="url(#lgBeam)" />);
// Manchas da janela no piso, inclinadas no sentido dos raios.
const fy = horizon + (H - horizon) * 0.3;
const fh = (H - horizon) * 0.2;
const cx = src.x + dir * W * 0.38;
const sk = dir * fh * 0.9;
for (const [a, b] of [[-0.62, -0.03], [0.03, 0.62]]) {
const xa = cx + ww * a;
const xb = cx + ww * b;
layers.push(<polygon key={`f${a}`} points={`${xa},${fy} ${xb},${fy} ${xb + sk},${fy + fh} ${xa + sk},${fy + fh}`} fill={warm} opacity={night ? 0.08 : 0.2} />);
}
} else if (src?.kind === "glow") {
const r = Math.max(W * 0.35, src.spread ?? W * 0.4);
defs.push(<radialGradient key="g" id="lgGlow" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={r}>
<stop offset="0" stopColor={warm} stopOpacity={0.38} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
defs.push(<radialGradient key="d" id="lgDark" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={H * 0.7}>
<stop offset="0.25" stopColor={pal.shade} stopOpacity={0} /><stop offset="1" stopColor={pal.shade} stopOpacity={0.6} /></radialGradient>);
layers.push(<rect key="dark" width={W} height={H} fill="url(#lgDark)" />);
layers.push(<rect key="glow" width={W} height={H} fill="url(#lgGlow)" />);
} else if (src?.kind === "sun") {
defs.push(<radialGradient key="s" id="lgSun" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={W * 1.05}>
<stop offset="0" stopColor={warm} stopOpacity={0.26} /><stop offset="0.5" stopColor={warm} stopOpacity={0.06} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
defs.push(<linearGradient key="k" id="lgCool" x1="1" y1="1" x2="0.3" y2="0.4">
<stop offset="0" stopColor={pal.shade} stopOpacity={0.3} /><stop offset="1" stopColor={pal.shade} stopOpacity={0} /></linearGradient>);
layers.push(<rect key="cool" width={W} height={H} fill="url(#lgCool)" />);
layers.push(<rect key="sun" width={W} height={H} fill="url(#lgSun)" />);
}
if (vignette) {
defs.push(<radialGradient key="v" id="lgVig" cx="0.5" cy="0.45" r="0.75"><stop offset="0.55" stopColor="#000" stopOpacity={0} /><stop offset="1" stopColor="#000" stopOpacity={0.55} /></radialGradient>);
layers.push(<rect key="vig" width={W} height={H} fill="url(#lgVig)" />);
}
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0 }}>
<defs>
<linearGradient id="spot" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor={pal.light} stopOpacity={0.32} /><stop offset="1" stopColor={pal.light} stopOpacity={0.05} /></linearGradient>
<radialGradient id="spotDark" cx="0.5" cy="0.55" r="0.65"><stop offset="0.35" stopColor="#000" stopOpacity={0} /><stop offset="1" stopColor="#000" stopOpacity={0.6} /></radialGradient>
</defs>
<rect width={W} height={H} fill="url(#spotDark)" />
<polygon points={`${W * 0.44},${H * 0.03} ${W * 0.56},${H * 0.03} ${W * 0.86},${H * 0.75} ${W * 0.14},${H * 0.75}`} fill="url(#spot)" />
<rect x={W * 0.42} y={H * 0.025} width={W * 0.16} height={14} rx={6} fill="#d9d9d9" />
<ellipse cx={W / 2} cy={H * 0.75} rx={W * 0.36} ry={34} fill={pal.light} opacity={0.12} />
<defs>{defs}</defs>
{layers}
</svg>
);
}
/** Chuva por cima de tudo (inclusive dos personagens); tempestade escurece, chove mais e relampeja. */
export function WeatherLayer({ spec, frame }: { spec: ShotSpec; frame: number }) {
const weather = spec.place?.weather ?? "none";
if (weather === "none") return null;
const storm = weather === "storm";
const rand = rng(spec.seed + 101);
const drops = Array.from({ length: storm ? 230 : 130 }, () => ({ x: rand() * (W + 300), y: rand() * H, v: 38 + rand() * 26, l: 40 + rand() * 50 }));
// Relâmpago: um clarão curto a cada 2,5 s, com fase que depende da semente.
const cycle = 75;
const ph = (frame + (spec.seed % cycle)) % cycle;
const flash = storm && ph < 5 ? (ph < 2 ? 0.55 : 0.25) : 0;
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0 }}>
{storm && <rect width={W} height={H} fill="#0a1020" opacity={0.22} />}
<g stroke="#d6e4f5" strokeWidth={storm ? 3.4 : 2.6} strokeLinecap="round" opacity={storm ? 0.6 : 0.5}>
{drops.map((d, i) => {
const y = ((d.y + frame * d.v) % (H + 120)) - 60;
const x = ((((d.x - frame * d.v * 0.22) % (W + 300)) + W + 300) % (W + 300)) - 150;
return <line key={i} x1={x} y1={y} x2={x - d.l * 0.22} y2={y + d.l} />;
})}
</g>
{flash > 0 && <>
<rect width={W} height={H} fill="#eaf2ff" opacity={flash} />
<path d={`M${W * 0.7} 0 L${W * 0.64} ${H * 0.14} L${W * 0.69} ${H * 0.14} L${W * 0.6} ${H * 0.3}`} stroke="#ffffff" strokeWidth={9} fill="none" strokeLinejoin="round" />
</>}
</svg>
);
}
/**
* Por cima dos personagens: a parte da frente das peças ocupadas (casco da arca, lataria do carro), na mesma
* posição da peça no fundo — quem está "dentro" aparece da cintura para cima.
*/
export function PlaceForeground({ spec, frame, progress = 0 }: { spec: ShotSpec; frame: number; progress?: number }) {
const place = spec.place;
const layout = React.useMemo(() => (place ? layoutPlace(spec) : null), [spec, place]);
if (!place || !layout || !place.elements.some((e) => e.occupied && FRONT_PART[e.kind])) return null;
const pal = palette(spec.palette);
const hazeColor = place.indoor ? pal.wall : mix(mix(pal.sky[2], pal.sky[1], 0.25), "#c8ccd6", place.fog ? 0.45 : 0);
const level = floodLevel(place, progress);
const waterY = level === null ? null : level * H;
const storm = place.weather === "storm";
const { horizon, zoom } = layout;
const zoomT = zoom === 1 ? undefined : `translate(${W / 2} ${horizon}) scale(${zoom}) translate(${-W / 2} ${-horizon})`;
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0 }}>
<g transform={zoomT}>
{layout.items.filter((it) => it.e.occupied && FRONT_PART[it.e.kind]).map((it) => {
const floating = !!it.e.float && waterY !== null;
return <PlacedElement key={it.e.i} it={it} pal={pal} spec={spec} hazeColor={hazeColor} part="front"
y={floating ? waterY! + H * 0.035 + Math.sin(frame / 14 + it.e.i) * 9 : undefined}
rot={floating ? Math.sin(frame / 22 + it.e.i) * (storm ? 3.5 : 1.6) : 0} />;
})}
{waterY !== null && place.elements.some((e) => e.occupied && e.float) && <rect x={0} y={waterY + H * 0.03} width={W} height={H} fill={pal.ground.water} opacity={0.35} />}
</g>
</svg>
);
}
+7 -3
View File
@@ -116,16 +116,20 @@ export const POSE_PRESETS = {
arms_up: { arms: { raise: 158, bend: -10 } },
celebrate: { arms: { raise: 150, bend: -30 }, headNod: -0.4 },
shrug: { arms: { raise: 38, bend: 100 }, headTilt: 7 },
think: { armR: { raise: 18, bend: 150 }, headTilt: -6 },
think: { armR: { raise: -19, bend: 141 }, headTilt: -6 },
hands_on_hips: { arms: { raise: 42, bend: 105 } },
cross_arms: { arms: { raise: 22, bend: 128 } },
facepalm: { armR: { raise: 26, bend: 158 }, headNod: 0.5, headTilt: 5 },
cover_mouth: { armR: { raise: 16, bend: 168 } },
facepalm: { armR: { raise: 125, bend: -103 }, headNod: 0.5, headTilt: 8 },
cover_mouth: { armR: { raise: -60, bend: 119 } },
defend: { arms: { raise: 62, bend: 118 }, lean: -4 },
reach: { armR: { raise: 70, bend: -10 }, lean: 6 },
sit: { crouch: 1, arms: { raise: 14, bend: 40 } },
kneel: { crouch: 0.6, arms: { raise: 10, bend: 20 } },
lean_in: { lean: 8, headTilt: 6 },
// Duas mãos segurando um objeto largo (livro, tábua) pelas bordas, na frente do peito.
hold_both: { arms: { raise: 51, bend: 99 } },
// Joinha: cotovelo dobrado, mão na altura do peito/ombro (a forma da mão vem do desenho: `thumbs_up`).
thumbs_up: { armR: { raise: 17, bend: 149 } },
} satisfies Record<string, BodyPatch>;
export type ExpressionName = keyof typeof EXPRESSION_PRESETS;
+1 -1
View File
@@ -152,7 +152,7 @@ function Card({ spec }: SceneProps) {
export function SceneBackground(props: SceneProps) {
switch (props.spec.scene.kind) {
case "place": return <PlaceBackground spec={props.spec} frame={props.frame} />;
case "place": return <PlaceBackground spec={props.spec} frame={props.frame} progress={props.progress} />;
case "street": return <Street {...props} />;
case "house": return <HouseFront {...props} />;
case "blueprint": return <Blueprint />;
+137 -14
View File
@@ -5,7 +5,8 @@
import { EXPRESSIONS, POSES, validateLook, type CharacterLook, type Expression, type Pose } from "./character";
import { validateTimeline, type Action } from "./motion";
import type { BodyPatch, FacePatch } from "./rig";
import { ELEMENTS, GROUNDS, PALETTES, type PaletteId, type Place } from "./places";
import { ELEMENTS, GROUNDS, LIGHT_SOURCES, PALETTES, WEATHERS, type PaletteId, type Place } from "./places";
import { SPECIES, type Species } from "./animals";
/** "place" = lugar montado por peças (ver places.tsx); os demais são fundos prontos da 1ª versão. */
export const SCENES = ["place", "street", "house", "plain", "blueprint", "card"] as const;
@@ -13,7 +14,8 @@ export const LIGHTS = ["none", "spot", "vignette"] as const;
export type SceneKind = (typeof SCENES)[number];
export const TIMES = ["night", "dawn", "day"] as const;
export type TimeOfDay = (typeof TIMES)[number];
export const ICONS = ["house", "generator", "fuel", "battery", "phone", "door", "eye", "bulb", "solar", "warning", "money", "clock"] as const;
export const ICONS = ["house", "generator", "fuel", "battery", "phone", "door", "eye", "bulb", "solar", "warning", "money", "clock",
"olive", "hammer", "tablet", "book", "ruler"] as const;
export type IconId = (typeof ICONS)[number];
export const TONES = ["info", "danger", "ok"] as const;
export type Tone = (typeof TONES)[number];
@@ -30,7 +32,7 @@ export type Person = {
/** Olha para a esquerda (espelha o desenho). */
flip?: boolean;
/** Enquadramento: corpo inteiro (padrão), meio corpo ou de perto (rosto grande, como ilustração de destaque). */
framing?: "full" | "medium" | "close";
framing?: "full" | "medium" | "close" | "insert";
/** Ajuste fino por cima da expressão/pose (ex.: { smile: 0.3, browL: { y: -6 } } ou { armR: { raise: 60 } }). */
face?: FacePatch;
body?: BodyPatch;
@@ -48,7 +50,22 @@ export type Person = {
enterS?: number;
};
export type Crowd = { kind: "crowd"; count: number; y: number; enterS?: number };
export type Actor = Person | Crowd;
/**
* Animal (figura reaproveitável, animals.tsx). `count` > 1 = fila (um atrás do outro, `gap` entre eles); `pair` =
* casal lado a lado em cada lugar da fila. `walk` anda de x até `to` (aves com `fly` voam, subindo e descendo).
* Olha para a direita; anda para a esquerda = espelha sozinho. `carry: "olive"` = ramo no bico (aves).
*/
export type Animal = {
kind: "animal";
species: Species;
x: number; y: number; scale?: number; flip?: boolean; color?: string;
count?: number; gap?: number; pair?: boolean;
walk?: { to: number; startS?: number; dur?: number };
fly?: boolean;
carry?: "olive";
enterS?: number;
};
export type Actor = Person | Crowd | Animal;
export type Prop = {
icon: IconId;
@@ -63,16 +80,57 @@ export type Prop = {
crossed?: boolean;
};
/**
* Camadas de texto/grafismo por cima da cena (overlays.tsx). `text` é o rótulo de cada uma:
* - onomatopoeia | tag | big: o texto em si; counter: rótulo pequeno + `value` grande (caixa escura arredondada);
* - namecard: nome do personagem + `lines` (função, dado) num cartão claro;
* - stat: rótulo espaçado + `value` grande colorido por `tone` (danger vermelho, info amarelo, ok verde, sem = branco);
* - checklist: `items` com `state` (empty | checked | crossed) que vão se marcando em sequência (`stepS`);
* - table: `items` ({ text, value }) com a linha `highlight` destacada; `text` = título (pode ser "");
* - progress: rótulo + barra que enche até `value` (0–100) + porcentagem;
* - grid: `value` de `total` quadradinhos preenchidos (com o número) + "N DE M".
* `panel: true` = cartela sobre fundo escuro de tela inteira; sem ele, caixa escura flutuante sobre a cena.
*/
export const TEXT_KINDS = ["onomatopoeia", "tag", "counter", "big", "namecard", "stat", "checklist", "table", "progress", "grid"] as const;
export type TextKind = (typeof TEXT_KINDS)[number];
export const CHECK_STATES = ["empty", "checked", "crossed"] as const;
export type CheckState = (typeof CHECK_STATES)[number];
export type TextRow = { text: string; value?: string; state?: CheckState };
export type TextItem = {
kind: "onomatopoeia" | "tag" | "counter" | "big";
kind: TextKind;
text: string;
/** Só no "counter": o número grande embaixo do rótulo. */
value?: string;
/** counter/stat: o número grande; progress: 0–100; grid: quantos quadradinhos preenchidos. */
value?: string | number;
x: number; y: number;
atS?: number;
tone?: Tone;
/** Graus (onomatopeia costuma ir levemente girada). */
rotate?: number;
/** namecard: 1–2 linhas menores embaixo do nome (função, dado). */
lines?: string[];
/** checklist/table: as linhas. */
items?: TextRow[];
/** table: índice da linha destacada. */
highlight?: number;
/** grid: total de quadradinhos (1–40). */
total?: number;
/** checklist: segundos entre uma marcação e a próxima (padrão 0,5). */
stepS?: number;
/** Cartela sobre fundo escuro de tela inteira (senão, caixa flutuante sobre a cena). */
panel?: boolean;
/** Escala da cartela (padrão 1; 0,5 = lista pequena no canto). */
size?: number;
};
/**
* Painel do topo. Esquerda: `badge` (bloco amarelo, "DIA 3") + `clock` (hora, anda com `clockMinutesPerSecond`) e,
* embaixo, a faixa clara com `place` (ou `label`). Direita, opcional: `valueLabel` pequeno ("CAIXA") + `value` grande
* (`valueTone`; sem ele, zero/negativo fica vermelho) e a faixa amarela `note` ("ESTREIA EM 30 DIAS").
*/
export type Hud = {
badge: string; label: string; clock?: string; clockMinutesPerSecond?: number;
place?: string; value?: string; valueLabel?: string; valueTone?: Tone; note?: string;
};
export type Word = { text: string; startS: number; endS: number; tone?: "key" | "danger" };
@@ -91,9 +149,12 @@ export type ShotSpec = {
grain?: number;
/** Luz por cima: foco do teto ("spot") ou vinheta. */
light?: (typeof LIGHTS)[number];
/** Fonte de luz posicionada (opcional): luminária (cone + poça no chão), janela (raios em diagonal) ou sol.
* x/y em fração do quadro. Sem ela, a luz sai das peças do lugar (luminária pendente > janela > sol). */
lightSource?: { kind: (typeof LIGHT_SOURCES)[number]; x: number; y?: number };
/** push = zoom no fim do trecho (1 = parado); panX = deslocamento horizontal da câmera (fração). */
camera?: { push?: number; panX?: number };
hud?: { badge: string; label: string; clock?: string; clockMinutesPerSecond?: number };
hud?: Hud;
actors?: Actor[];
props?: Prop[];
texts?: TextItem[];
@@ -124,6 +185,12 @@ export function validateSpec(spec: unknown): string[] {
if (s.scene?.kind === "card" && !s.card?.title) errors.push("scene card precisa de card.title");
if (s.palette !== undefined && !PALETTES.includes(s.palette)) errors.push(`palette precisa ser um de: ${PALETTES.join(", ")}`);
if (s.light !== undefined && !LIGHTS.includes(s.light)) errors.push(`light precisa ser um de: ${LIGHTS.join(", ")}`);
if (s.lightSource !== undefined) {
const ls = s.lightSource;
if (!ls || !LIGHT_SOURCES.includes(ls.kind) || !frac(ls.x) || (ls.y !== undefined && !frac(ls.y))) {
errors.push(`lightSource: { kind (${LIGHT_SOURCES.join(", ")}), x, y? } em fração do quadro`);
}
}
if (s.scene?.kind === "place") {
const place = s.place;
if (!place || !GROUNDS.includes(place.ground) || !Array.isArray(place.elements)) errors.push(`place precisa de ground (${GROUNDS.join(", ")}) e elements`);
@@ -132,7 +199,10 @@ export function validateSpec(spec: unknown): string[] {
for (const [i, e] of place.elements.entries()) {
if (!ELEMENTS.includes(e.kind)) errors.push(`place.elements[${i}]: peça "${e.kind}" não existe (${ELEMENTS.join(", ")})`);
if (!frac(e.x) || (e.z !== undefined && !(e.z >= 0 && e.z <= 1))) errors.push(`place.elements[${i}]: x fora do quadro ou z fora de 0–1`);
if (e.lift !== undefined && !(finite(e.lift) && e.lift >= -0.5 && e.lift <= 1)) errors.push(`place.elements[${i}]: lift entre -0,5 e 1`);
}
if (place.weather !== undefined && !WEATHERS.includes(place.weather)) errors.push(`place.weather: ${WEATHERS.join(", ")}`);
if (place.flood !== undefined && !(place.flood && frac(place.flood.from) && frac(place.flood.to))) errors.push("place.flood: { from, to } em fração da altura");
}
}
for (const [i, a] of (s.actors ?? []).entries()) {
@@ -150,18 +220,22 @@ export function validateSpec(spec: unknown): string[] {
}
}
else if (a.kind === "crowd" && (!finite(a.count) || a.count < 1 || a.count > 40 || !frac(a.y))) errors.push(`actors[${i}]: crowd inválida`);
else if ((a as { kind: string }).kind !== "crowd") errors.push(`actors[${i}]: kind inválido`);
else if (a.kind === "animal") {
if (!SPECIES.includes(a.species)) errors.push(`actors[${i}]: espécie "${a.species}" não existe (${SPECIES.join(", ")})`);
if (!frac(a.x) || !frac(a.y)) errors.push(`actors[${i}]: x/y fora do quadro`);
if (a.count !== undefined && !(Number.isInteger(a.count) && a.count >= 1 && a.count <= 12)) errors.push(`actors[${i}]: count entre 1 e 12`);
if (a.walk !== undefined && !(a.walk && frac(a.walk.to))) errors.push(`actors[${i}]: walk.to fora do quadro`);
if (a.carry !== undefined && a.carry !== "olive") errors.push(`actors[${i}]: carry só "olive"`);
}
else if (!["crowd", "person", "animal"].includes((a as { kind: string }).kind)) errors.push(`actors[${i}]: kind inválido`);
}
for (const [i, p] of (s.props ?? []).entries()) {
if (!ICONS.includes(p.icon)) errors.push(`props[${i}]: ícone "${p.icon}" não existe (${ICONS.join(", ")})`);
if (!frac(p.x) || !frac(p.y)) errors.push(`props[${i}]: x/y fora do quadro`);
if (p.tone !== undefined && !TONES.includes(p.tone)) errors.push(`props[${i}]: tone inválido`);
}
for (const [i, t] of (s.texts ?? []).entries()) {
if (!["onomatopoeia", "tag", "counter", "big"].includes(t.kind)) errors.push(`texts[${i}]: kind inválido`);
if (typeof t.text !== "string" || !t.text.trim()) errors.push(`texts[${i}]: texto vazio`);
if (!frac(t.x) || !frac(t.y)) errors.push(`texts[${i}]: x/y fora do quadro`);
}
if (s.hud !== undefined) errors.push(...validateHud(s.hud));
for (const [i, t] of (s.texts ?? []).entries()) errors.push(...validateText(t, i));
if (s.audioEnv !== undefined && (!finite(s.audioEnv.fps) || !Array.isArray(s.audioEnv.values) || s.audioEnv.values.length > 36000)) errors.push("audioEnv: { fps, values[] } (até 36 mil valores)");
for (const [i, w] of (s.words ?? []).entries()) {
if (typeof w.text !== "string" || !finite(w.startS) || !finite(w.endS) || w.endS < w.startS) errors.push(`words[${i}]: inválida`);
@@ -169,5 +243,54 @@ export function validateSpec(spec: unknown): string[] {
return errors;
}
const str = (v: unknown): v is string => typeof v === "string";
function validateHud(h: Hud): string[] {
const errors: string[] = [];
if (!h || typeof h !== "object") return ["hud precisa ser um objeto"];
if (!str(h.badge) || !str(h.label)) errors.push("hud: badge e label são texto");
for (const k of ["clock", "place", "value", "valueLabel", "note"] as const) if (h[k] !== undefined && !str(h[k])) errors.push(`hud.${k}: texto`);
if (h.clockMinutesPerSecond !== undefined && !finite(h.clockMinutesPerSecond)) errors.push("hud.clockMinutesPerSecond: número");
if (h.valueTone !== undefined && !TONES.includes(h.valueTone)) errors.push(`hud.valueTone: ${TONES.join(", ")}`);
return errors;
}
/** "97", 97 ou "97,5" → número (NaN se não for). */
export const numberOf = (v: unknown) => (typeof v === "number" ? v : typeof v === "string" && v.trim() ? Number(v.replace(/%$/, "").replace(",", ".")) : NaN);
const OPTIONAL_TEXT: TextKind[] = ["table", "stat", "checklist"];
function validateText(t: TextItem, i: number): string[] {
const errors: string[] = [];
const at = `texts[${i}]`;
if (!t || typeof t !== "object") return [`${at}: precisa ser um objeto`];
if (!TEXT_KINDS.includes(t.kind)) errors.push(`${at}: kind inválido (${TEXT_KINDS.join(", ")})`);
// Tabela e lista podem ir sem título e o stat sem rótulo (só o número); os demais precisam de texto.
if (!str(t.text) || (!t.text.trim() && !OPTIONAL_TEXT.includes(t.kind))) errors.push(`${at}: texto vazio`);
if (!frac(t.x) || !frac(t.y)) errors.push(`${at}: x/y fora do quadro`);
if (t.tone !== undefined && !TONES.includes(t.tone)) errors.push(`${at}: tone inválido`);
if (t.value !== undefined && !str(t.value) && !finite(t.value)) errors.push(`${at}: value é texto ou número`);
if (t.size !== undefined && !(finite(t.size) && t.size >= 0.3 && t.size <= 2)) errors.push(`${at}: size entre 0,3 e 2`);
if (t.lines !== undefined && !(Array.isArray(t.lines) && t.lines.length <= 3 && t.lines.every(str))) errors.push(`${at}: lines = até 3 textos`);
if (t.kind === "stat" && (t.value === undefined || !String(t.value).trim())) errors.push(`${at}: stat precisa de value`);
if (t.kind === "checklist" || t.kind === "table") {
if (!Array.isArray(t.items) || !t.items.length || t.items.length > 8) errors.push(`${at}: items com 1 a 8 linhas`);
else for (const [j, r] of t.items.entries()) {
if (!r || !str(r.text) || !r.text.trim()) errors.push(`${at}.items[${j}]: texto vazio`);
else if (r.state !== undefined && !CHECK_STATES.includes(r.state)) errors.push(`${at}.items[${j}]: state (${CHECK_STATES.join(", ")})`);
else if (r.value !== undefined && !str(r.value)) errors.push(`${at}.items[${j}]: value é texto`);
}
}
if (t.highlight !== undefined && !(Number.isInteger(t.highlight) && t.highlight >= 0 && t.highlight < (t.items?.length ?? 0))) errors.push(`${at}: highlight fora das linhas`);
if (t.stepS !== undefined && !(finite(t.stepS) && t.stepS >= 0 && t.stepS <= 5)) errors.push(`${at}: stepS entre 0 e 5`);
if (t.kind === "progress" && !(numberOf(t.value) >= 0 && numberOf(t.value) <= 100)) errors.push(`${at}: progress precisa de value entre 0 e 100`);
if (t.kind === "grid") {
const total = t.total ?? NaN;
if (!(Number.isInteger(total) && total >= 1 && total <= 40)) errors.push(`${at}: grid precisa de total inteiro entre 1 e 40`);
else if (!(Number.isInteger(numberOf(t.value)) && numberOf(t.value) >= 0 && numberOf(t.value) <= total)) errors.push(`${at}: grid precisa de value inteiro entre 0 e total`);
}
return errors;
}
/** Número de quadros do trecho (arredonda para cima: o vídeo nunca fica mais curto que o áudio). */
export const frameCount = (spec: Pick<ShotSpec, "durationS" | "fps">) => Math.max(1, Math.ceil(spec.durationS * spec.fps));
+7
View File
@@ -4,6 +4,12 @@ import { FONT_CAPTION, FONT_LABEL } from "./colors";
export * from "./colors";
/**
* Texto de apoio do grafismo (HUD, rótulos espaçados, listas, linhas do cartão de nome): Barlow Semi Condensed Bold
* (OFL-1.1, licença em assets/fonts/BarlowSemiCondensed-Bold.OFL.txt). Condensada e legível em tamanho pequeno.
*/
export const FONT_TEXT = "CartoonBarlow";
let loaded = false;
/** Carrega as fontes de assets/fonts antes do primeiro quadro (o render espera). */
export function loadFonts(): void {
@@ -13,6 +19,7 @@ export function loadFonts(): void {
const faces = [
new FontFace(FONT_CAPTION, `url(${staticFile("fonts/Anton-Regular.ttf")})`),
new FontFace(FONT_LABEL, `url(${staticFile("fonts/BebasNeue-Regular.ttf")})`),
new FontFace(FONT_TEXT, `url(${staticFile("fonts/BarlowSemiCondensed-Bold.ttf")})`),
];
Promise.all(faces.map((f) => f.load().then((ok) => document.fonts.add(ok))))
.then(() => continueRender(handle))