Estilo Cartoon (Remotion), personagens reaproveitáveis e hashtags do TikTok

Estilo Cartoon (novo, sem Godot)
- Pacote cartoon/ (Remotion 4.0.535): cada trecho é um spec JSON desenhado
  em React/SVG e renderizado em MP4; render em lote (empacota uma vez) e
  imagem parada (--still).
- Cenas montadas por peças, sem cenário pronto: paletas (noite, sépia, dia,
  entardecer, cinza), lugar com chão, interno/externo, névoa e 24 peças
  posicionadas por profundidade, foco de luz e vinheta; etiquetas,
  onomatopeias, ondas de som, X vermelho, painel do topo e legenda palavra
  por palavra.
- Montagem documental: "Cartoon" como estilo do vídeo e tipo de visual do
  trecho; plano por regras pelo texto (lugar, objetos, expressão, pose),
  tempos das palavras pela transcrição do áudio, "Gerar de novo" por trecho,
  paleta da série e elenco da história.

Personagens
- Aba Personagens: criar pela descrição, ajustar peça por peça com prévia
  ao vivo, refinar com o agente (tarefa nova "Personagem"); fichas em
  assets/characters/ e elenco em stories/<id>/cast.json. O mesmo personagem
  sai igual em qualquer cena, mudando expressão, pose e objeto na mão.

TikTok
- Hashtags passam a ser digitadas e confirmadas na lista de sugestões do
  TikTok Studio (coladas, viravam texto). Diagnóstico de alcance em
  doc/publicacao/TIKTOK_DIAGNOSTICO.md.

Docs: estudo das referências, doc/cartoon/ (personagens e cenas) e skill
cenaforge 1.46.0.

Testes: painel 77/77, cartoon 5/5, Publicador 87/87.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 21:36:48 -03:00
co-authored by Claude Opus 5.5
parent e7ccc91736
commit 0050cf60a7
55 changed files with 5808 additions and 50 deletions
+37
View File
@@ -0,0 +1,37 @@
// Cartão de personagem (prévia da biblioteca e conferência): um ou mais personagens lado a lado, cada um com
// expressão e pose, sobre fundo neutro, com o nome na etiqueta.
import React from "react";
import { AbsoluteFill, useCurrentFrame, useVideoConfig } from "remotion";
import { CharacterFigure } from "./CharacterFigure";
import { TagLabel } from "./overlays";
import { loadFonts } from "./theme";
import type { CharacterLook, Expression, Pose } from "./character";
import type { IconId } from "./spec";
loadFonts();
export type CardProps = {
width: number; height: number;
background?: string;
figures: { look: CharacterLook; expression?: Expression; pose?: Pose; item?: IconId; label?: string }[];
};
export function CharacterCard({ figures, background = "#2a2e45" }: CardProps) {
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
const n = Math.max(1, figures.length);
return (
<AbsoluteFill style={{ background, containerType: "size" }}>
<div style={{ position: "absolute", inset: "8% 2% 4%", display: "grid", gridTemplateColumns: `repeat(${n}, 1fr)`, alignItems: "end" }}>
{figures.map((f, i) => (
<div key={i} style={{ position: "relative", height: "100%", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "flex-end" }}>
{f.label && <div style={{ marginBottom: "4%" }}><TagLabel text={f.label} size={n > 3 ? 2.2 : 3.4} /></div>}
<div style={{ width: "90%", aspectRatio: "200 / 440", maxHeight: "86%" }}>
<CharacterFigure look={f.look} expression={f.expression} pose={f.pose} item={f.item} t={frame / fps} />
</div>
</div>
))}
</div>
</AbsoluteFill>
);
}
+199
View File
@@ -0,0 +1,199 @@
// Desenho do personagem a partir das peças (character.ts). SVG puro, sem Remotion: o painel usa o mesmo
// componente na prévia ao vivo da aba Personagens. viewBox 200×440 com os pés em (100, 440).
// `t` (segundos) só move detalhes vivos: respiração, piscar, braço acenando.
import React from "react";
import { Icon } from "./icons";
import type { IconId } from "./spec";
import { DEFAULT_LOOK, type CharacterLook, type Expression, type Pose } from "./character";
const INK = "#15161f";
/** Ângulo dos braços por pose (graus; 0 = para baixo). Direito negativo = para fora; esquerdo positivo = para fora. */
const ARMS: Record<Pose, [number, number]> = {
stand: [-8, 8], point: [-95, 8], wave: [-150, 8], hold: [-38, 8], arms_up: [-160, 160], shrug: [-55, 55], think: [150, 8],
};
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)}`;
}
function Mouth({ expression }: { expression: Expression }) {
const common = { stroke: INK, strokeWidth: 4.5, fill: "none", strokeLinecap: "round" as const };
switch (expression) {
case "happy": return <path d="M84 131 Q100 150 116 131 Q100 140 84 131 Z" fill={INK} />;
case "sad": return <path d="M87 141 Q100 129 113 141" {...common} />;
case "worried": return <path d="M86 139 Q93 133 100 139 Q107 145 114 139" {...common} />;
case "angry": return <path d="M87 139 L113 136" {...common} strokeWidth={6} />;
case "surprised": return <ellipse cx={100} cy={139} rx={8} ry={10} fill={INK} />;
case "scared": return <ellipse cx={100} cy={140} rx={10} ry={7} fill={INK} />;
default: return <path d="M88 136 Q100 140 112 136" {...common} />;
}
}
function Brows({ expression, thick, color }: { expression: Expression; thick: boolean; color: string }) {
// Inclinação da sobrancelha esquerda (a direita espelha): + sobe por dentro (triste/preocupado), − desce (bravo).
const tilt = { neutral: 0, happy: -6, sad: 16, worried: 14, angry: -18, surprised: 0, scared: 18 }[expression];
const lift = expression === "surprised" || expression === "scared" ? -7 : expression === "happy" ? -3 : 0;
const w = thick ? 7 : 4.5;
return (
<g stroke={color} strokeWidth={w} strokeLinecap="round">
<line x1={71} y1={89 + lift} x2={92} y2={89 + lift} transform={`rotate(${tilt} 92 ${89 + lift})`} />
<line x1={108} y1={89 + lift} x2={129} y2={89 + lift} transform={`rotate(${-tilt} 108 ${89 + lift})`} />
</g>
);
}
function Eyes({ expression, t }: { expression: Expression; t: number }) {
const big = expression === "surprised" || expression === "scared";
const r = big ? 12.5 : 10.5;
const pupil = expression === "scared" ? 3.4 : big ? 5.5 : 5;
const blink = (t % 3.7) < 0.12 && !big ? 0.12 : 1;
const squint = expression === "angry" ? 0.7 : expression === "happy" ? 0.8 : 1;
return (
<g>
{[82, 118].map((x) => (
<g key={x} transform={`translate(${x} 108) scale(1 ${blink * squint})`}>
<circle r={r} fill="#ffffff" />
<circle r={pupil} cx={expression === "worried" ? -1.5 : 0} cy={expression === "sad" ? 2 : 0} fill={INK} />
</g>
))}
</g>
);
}
function Glasses({ kind }: { kind: CharacterLook["glasses"] }) {
if (kind === "none") return null;
const lens = kind === "sun" ? INK : "none";
return (
<g stroke={INK} strokeWidth={4} fill={lens}>
{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>
);
}
function Beard({ style, color }: { style: CharacterLook["beard"]["style"]; color: string }) {
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 146 Q100 166 112 146 Q100 152 88 146 Z" fill={color} />;
case "mustache": return <path d="M82 128 Q100 120 118 128 Q110 134 100 130 Q90 134 82 128 Z" fill={color} />;
default: return null;
}
}
function HairBack({ look }: { look: CharacterLook }) {
if (look.hair.style !== "long") return null;
return <path d="M50 100 Q48 40 100 38 Q152 40 150 100 L156 190 Q100 205 44 190 Z" fill={look.hair.color} />;
}
function HairFront({ look }: { look: CharacterLook }) {
const c = look.hair.color;
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)} /></>;
default: return null;
}
}
function Torso({ look, w }: { look: CharacterLook; w: number }) {
const { top } = look;
const x0 = 100 - 36 * w;
const x1 = 100 + 36 * w;
const bottomY = top.style === "dress" ? 345 : 290;
const flare = top.style === "dress" ? 14 : 0;
const body = `M${x0} 172 Q${x0} 158 ${x0 + 14} 156 L${x1 - 14} 156 Q${x1} 158 ${x1} 172 L${x1 + flare} ${bottomY} L${x0 - flare} ${bottomY} Z`;
const accent = top.accent ?? shade(top.color, 1.3);
return (
<g>
{top.style === "hoodie" && <path d={`M${x0 + 6} 160 Q100 132 ${x1 - 6} 160 Z`} fill={shade(top.color, 0.8)} />}
<path d={body} fill={top.color} />
{top.style === "uniform" && <rect x={x0} y={248} width={x1 - x0} height={11} fill={accent} />}
{top.style === "shirt" && top.accent && <rect x={x0} y={252} width={x1 - x0} height={9} fill={accent} />}
{top.style === "jacket" && <><path d={`M100 158 L100 ${bottomY}`} stroke={shade(top.color, 0.6)} strokeWidth={4} /><path d="M86 158 L100 186 L114 158 Z" fill={accent} /></>}
{top.style === "hoodie" && <rect x={84} y={240} 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={196 + Math.floor(i / 2) * 70} r={3.5} fill="#ffffff" opacity={0.5} />)}
</g>
);
}
function Legs({ look, w }: { look: CharacterLook; w: number }) {
const { bottom } = look;
const gap = 10 * w;
const legW = 20 * w;
const left = 100 - gap - legW;
const right = 100 + gap;
const skinTop = look.top.style === "dress" ? 345 : bottom.style === "shorts" ? 330 : bottom.style === "skirt" ? 345 : 440;
return (
<g>
<rect x={left} y={286} width={legW} height={140} rx={6} fill={look.skin} />
<rect x={right} y={286} width={legW} height={140} rx={6} fill={look.skin} />
{look.top.style !== "dress" && bottom.style === "pants" && <><rect x={left} y={284} width={legW} height={142} rx={4} fill={bottom.color} /><rect x={right} y={284} width={legW} height={142} rx={4} fill={bottom.color} /></>}
{look.top.style !== "dress" && bottom.style === "shorts" && <path d={`M${left - 2} 284 L${right + legW + 2} 284 L${right + legW + 2} ${skinTop} L${left - 2} ${skinTop} Z`} fill={bottom.color} />}
{look.top.style !== "dress" && bottom.style === "skirt" && <path d={`M${left + 2} 284 L${right + legW - 2} 284 L${right + legW + 12} ${skinTop} L${left - 12} ${skinTop} Z`} fill={bottom.color} />}
<rect x={left - 4} y={422} width={legW + 10} height={16} rx={7} fill={look.shoes} />
<rect x={right - 6} y={422} width={legW + 10} height={16} rx={7} fill={look.shoes} />
</g>
);
}
export function CharacterFigure({ look = DEFAULT_LOOK, expression = "neutral", pose = "stand", item, t = 0 }: {
look?: CharacterLook; expression?: Expression; pose?: Pose; item?: IconId; t?: number;
}) {
const w = look.build === "slim" ? 0.86 : look.build === "heavy" ? 1.22 : 1;
const breathe = Math.sin(t * 2.2) * 1.6;
const [r0, l0] = ARMS[pose];
const swing = pose === "wave" ? Math.sin(t * 9) * 14 : Math.sin(t * 1.4) * 2.5;
const rAngle = r0 + swing;
const lAngle = l0 - (pose === "wave" ? 0 : swing);
const shoulderY = 168;
const sx = 34 * w;
const sleeve = look.top.style === "dress" ? look.skin : look.top.color;
const arm = (side: 1 | -1, angle: number, holds?: IconId) => (
<g transform={`rotate(${angle} ${100 + side * sx} ${shoulderY})`}>
<rect x={100 + side * sx - 9} y={shoulderY - 6} width={18} height={104} rx={9} fill={sleeve} />
<circle cx={100 + side * sx} cy={shoulderY + 102} r={11} fill={look.skin} />
{holds && (
<g transform={`translate(${100 + side * sx - 26} ${shoulderY + 96}) rotate(${-angle} 26 26)`}>
<svg x={0} y={0} width={52} height={52} viewBox="0 0 100 100" overflow="visible"><Icon id={holds} /></svg>
</g>
)}
</g>
);
return (
<svg viewBox="0 0 200 440" width="100%" height="100%" overflow="visible">
<g transform={`translate(100 440) scale(${look.height}) translate(-100 -440) translate(0 ${breathe * 0.3})`}>
<HairBack look={look} />
<Legs look={look} w={w} />
{arm(-1, lAngle)}
<Torso look={look} w={w} />
{pose !== "think" && arm(1, rAngle, pose === "hold" || pose === "point" ? item : undefined)}
<rect x={90} y={146} width={20} height={16} fill={shade(look.skin, 0.9)} />
<g transform={`translate(0 ${breathe * 0.4})`}>
<ellipse cx={53} cy={112} rx={8} ry={11} fill={shade(look.skin, 0.92)} />
<ellipse cx={147} cy={112} rx={8} ry={11} fill={shade(look.skin, 0.92)} />
<ellipse cx={100} cy={106} rx={47} ry={50} fill={look.skin} />
<Beard style={look.beard.style} color={look.beard.color} />
<Eyes expression={expression} t={t} />
<Brows expression={expression} thick={look.brows === "thick"} color={look.hair.style === "bald" || look.hair.style === "cap" ? look.beard.color : look.hair.color} />
<Glasses kind={look.glasses} />
<Mouth expression={expression} />
<HairFront look={look} />
</g>
{/* Pensando: a mão vai ao queixo, por cima da barba. */}
{pose === "think" && arm(1, rAngle)}
</g>
</svg>
);
}
+33
View File
@@ -0,0 +1,33 @@
import React from "react";
import { Composition } from "remotion";
import { Shot } from "./Shot";
import { frameCount, type ShotSpec } from "./spec";
import { SAMPLE } from "./sample";
import { CharacterCard, type CardProps } from "./CharacterCard";
// ATENÇÃO: a Remotion completa o que falta nas props com os `defaultProps` da composição. Por isso o padrão do
// "Shot" é um trecho VAZIO: se fosse o exemplo, o HUD, o gerador e a onomatopeia dele vazariam em todo trecho
// que não tivesse esses campos. O exemplo fica numa composição própria ("Sample"), só para o Studio.
const BLANK: ShotSpec = { schemaVersion: 1, width: 1080, height: 1920, fps: 30, durationS: 1, seed: 1, scene: { kind: "plain" } };
const BLANK_CARD: CardProps = { width: 1080, height: 1080, figures: [] };
const shotMetadata = ({ props }: { props: Record<string, unknown> }) => {
const spec = props as unknown as ShotSpec;
return { width: spec.width, height: spec.height, fps: spec.fps, durationInFrames: frameCount(spec) };
};
const asFc = (c: unknown) => c as React.FC<Record<string, unknown>>;
const asProps = (p: unknown) => p as Record<string, unknown>;
/** "Shot": um trecho (tamanho, fps e duração vêm do spec). "Character": cartão de personagem. "Sample": exemplo do Studio. */
export function Root() {
return (
<>
<Composition id="Shot" component={asFc(Shot)} defaultProps={asProps(BLANK)} width={1080} height={1920} fps={30}
durationInFrames={30} calculateMetadata={shotMetadata} />
<Composition id="Sample" component={asFc(Shot)} defaultProps={asProps(SAMPLE)} width={SAMPLE.width} height={SAMPLE.height}
fps={SAMPLE.fps} durationInFrames={frameCount(SAMPLE)} calculateMetadata={shotMetadata} />
<Composition id="Character" component={asFc(CharacterCard)} defaultProps={asProps(BLANK_CARD)} width={1080} height={1080} fps={30}
durationInFrames={90} calculateMetadata={({ props }) => ({ width: (props as unknown as CardProps).width, height: (props as unknown as CardProps).height })} />
</>
);
}
+87
View File
@@ -0,0 +1,87 @@
// Um trecho do estilo Cartoon: cena de fundo + personagens + objetos + textos + HUD + legenda, com a câmera
// fazendo um empurrão lento (nunca fica parado, como na referência).
import React from "react";
import { AbsoluteFill, useCurrentFrame, useVideoConfig } from "remotion";
import { CrowdFigure, PersonFigure } from "./actors";
import { Icon } from "./icons";
import { Captions, CrossOut, Hud, Rings, TagLabel, TextLayer, pop, shake } from "./overlays";
import { SceneBackground } from "./scenes";
import { CharacterFigure } from "./CharacterFigure";
import { LightLayer } from "./places";
import type { ShotSpec } from "./spec";
import { loadFonts } from "./theme";
loadFonts();
export function Shot(spec: ShotSpec) {
const frame = useCurrentFrame();
const { fps, durationInFrames, width, height } = useVideoConfig();
const progress = durationInFrames > 1 ? frame / (durationInFrames - 1) : 0;
const push = spec.camera?.push ?? (spec.scene.kind === "card" ? 1 : 1.07);
const zoom = 1 + (push - 1) * progress;
return (
<AbsoluteFill style={{ background: "#07080f", containerType: "size", overflow: "hidden" }}>
<AbsoluteFill style={{ transform: `scale(${zoom})`, transformOrigin: "50% 45%" }}>
<SceneBackground spec={spec} frame={frame} progress={progress} />
{(spec.actors ?? []).map((a, i) => {
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%",
opacity: k, transform: `translateY(${(1 - k) * 8}%)` }}>
<CrowdFigure c={a} frame={frame} />
</div>
);
}
if (a.character) {
// Personagem da biblioteca: mesmo visual em toda cena; muda expressão, pose e objeto na mão.
const ch = height * 0.36 * (a.scale ?? 1);
const cw = (ch * 200) / 440;
const label = a.label ?? a.character.name;
return (
<div key={i} style={{ position: "absolute", left: a.x * width - cw / 2, top: a.y * height - ch, width: cw, height: ch,
opacity: Math.min(1, k * 1.5), transform: `translateY(${(1 - k) * 10}%) scaleX(${a.flip ? -1 : 1})` }}>
<CharacterFigure look={a.character.look} expression={a.expression} pose={a.pose} item={a.item} t={frame / fps} />
{label && (
<div style={{ position: "absolute", left: "50%", top: "-15%", transform: `translateX(-50%) scaleX(${a.flip ? -1 : 1})`, textAlign: "center" }}>
<TagLabel text={label} />
{a.character.caption && <div style={{ marginTop: "0.6cqw" }}><TagLabel text={a.character.caption} tone="ok" size={2.4} /></div>}
</div>
)}
</div>
);
}
const h = height * 0.27 * (a.scale ?? 1);
return (
<div key={i} style={{ position: "absolute", left: a.x * width - (h * 200) / 420 / 2, top: a.y * height - h, width: (h * 200) / 420,
height: h, opacity: Math.min(1, k * 1.5), transform: `translateY(${(1 - k) * 12}%)` }}>
<PersonFigure p={a} frame={frame} fps={fps} />
{a.label && <div style={{ position: "absolute", left: "50%", top: "-14%", transform: "translateX(-50%)" }}><TagLabel text={a.label} /></div>}
</div>
);
})}
{(spec.props ?? []).map((p, i) => {
const k = pop(frame, fps, p.enterS ?? 0);
if (k <= 0.001) return null;
const size = height * (p.size ?? 0.16);
const s = p.shake ? shake(frame, 2.5) : { x: 0, y: 0 };
const cross = p.crossed ? pop(frame, fps, (p.enterS ?? 0) + 0.5, 90) : 0;
return (
<div key={i} style={{ position: "absolute", left: p.x * width - size / 2 + s.x, top: p.y * height - size / 2 + s.y, width: size, height: size,
transform: `scale(${0.5 + 0.5 * k})`, opacity: Math.min(1, k * 1.5) }}>
{p.rings && <div style={{ position: "absolute", inset: "-60%" }}><Rings frame={frame} fps={fps} /></div>}
<Icon id={p.icon} />
{p.crossed && <div style={{ position: "absolute", inset: "-8%" }}><CrossOut k={cross} /></div>}
{p.label && <div style={{ position: "absolute", left: "50%", top: "-22%", transform: "translateX(-50%)" }}><TagLabel text={p.label} tone={p.tone} /></div>}
</div>
);
})}
<LightLayer light={spec.light} palette={spec.palette} />
{(spec.texts ?? []).map((t, i) => <TextLayer key={i} t={t} frame={frame} fps={fps} />)}
</AbsoluteFill>
{spec.hud && <Hud hud={spec.hud} frame={frame} fps={fps} />}
{spec.words?.length ? <Captions words={spec.words} frame={frame} fps={fps} /> : null}
</AbsoluteFill>
);
}
+66
View File
@@ -0,0 +1,66 @@
// Personagens "de recorte": peças rígidas (cabeça, cabelo, tronco, braços, pernas) que se mexem por inteiro —
// sem boca sincronizada, como na referência. Multidão = silhuetas.
import React from "react";
import { COLORS } from "./colors";
import { rng } from "./random";
import type { Crowd, Person } from "./spec";
/** Pessoa em pé num viewBox 200×420; (0,0) do grupo = pés no centro. */
export function PersonFigure({ p, frame, fps }: { p: Person; frame: number; fps: number }) {
const skin = p.skin ?? "#c98a5e";
const outfit = p.outfit ?? "#9b7be0";
const hair = p.hairColor ?? "#e8e8ee";
const sway = Math.sin(frame / (fps * 0.9)) * 1.5;
const arm = p.pointing ? -70 + Math.sin(frame / (fps * 0.5)) * 4 : 6 + Math.sin(frame / fps) * 2;
return (
<svg viewBox="0 0 200 420" width="100%" height="100%" overflow="visible">
<g transform={`rotate(${sway} 100 420)`}>
<rect x={74} y={300} width={18} height={115} rx={6} fill={COLORS.ink} />
<rect x={108} y={300} width={18} height={115} rx={6} fill={COLORS.ink} />
<path d="M60 150 Q100 130 140 150 L156 320 Q100 334 44 320 Z" fill={outfit} />
{[0, 1, 2, 3, 4, 5].map((i) => <circle key={i} cx={70 + (i % 3) * 30} cy={190 + Math.floor(i / 3) * 70} r={4} fill="#ffffff" opacity={0.55} />)}
<g transform={`rotate(${arm} 142 160)`}>
<rect x={136} y={156} width={16} height={110} rx={8} fill={outfit} />
<circle cx={144} cy={270} r={10} fill={skin} />
</g>
<g transform={`rotate(${-6 - Math.sin(frame / fps) * 2} 58 160)`}>
<rect x={48} y={156} width={16} height={110} rx={8} fill={outfit} />
<circle cx={56} cy={270} r={10} fill={skin} />
</g>
<rect x={90} y={118} width={20} height={26} fill={skin} />
<circle cx={100} cy={92} r={40} fill={skin} />
{p.hair === "bun" && <><circle cx={100} cy={46} r={20} fill={hair} /><path d="M60 88 Q100 40 140 88 Q140 64 100 56 Q60 64 60 88" fill={hair} /></>}
{(p.hair ?? "short") === "short" && <path d="M58 90 Q60 46 100 48 Q142 46 142 90 Q132 64 100 64 Q70 64 58 90" fill={hair} />}
{p.glasses && (
<g fill="none" stroke={COLORS.ink} strokeWidth={4}>
<circle cx={84} cy={92} r={11} /><circle cx={116} cy={92} r={11} /><line x1={95} y1={92} x2={105} y2={92} />
</g>
)}
<circle cx={84} cy={93} r={4} fill={COLORS.ink} />
<circle cx={116} cy={93} r={4} fill={COLORS.ink} />
<path d="M88 112 Q100 118 112 112" stroke={COLORS.ink} strokeWidth={4} fill="none" strokeLinecap="round" />
</g>
</svg>
);
}
/** Fila de silhuetas pretas (multidão no portão). */
export function CrowdFigure({ c, frame }: { c: Crowd; frame: 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 }));
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;
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>
);
})}
</svg>
);
}
+80
View File
@@ -0,0 +1,80 @@
// Personagem do estilo Cartoon montado por PEÇAS (não é desenho pronto): o mesmo personagem sai igual em
// qualquer cena e história, mudando só expressão, pose e o que tem na mão. Guardado na biblioteca de
// personagens (assets/characters/<id>/character.json) e copiado no spec de cada trecho.
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 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;
export const BOTTOM_STYLES = ["pants", "shorts", "skirt"] as const;
export const EXPRESSIONS = ["neutral", "happy", "sad", "worried", "angry", "surprised", "scared"] as const;
export const POSES = ["stand", "point", "wave", "hold", "arms_up", "shrug", "think"] as const;
export type Expression = (typeof EXPRESSIONS)[number];
export type Pose = (typeof POSES)[number];
export type CharacterLook = {
build: (typeof BUILDS)[number];
/** Altura relativa (0,85 a 1,15). Criança ≈ 0,8 é aceito também. */
height: number;
skin: string;
hair: { style: (typeof HAIR_STYLES)[number]; color: string };
beard: { style: (typeof BEARD_STYLES)[number]; color: string };
glasses: (typeof GLASSES)[number];
brows: (typeof BROWS)[number];
top: { style: (typeof TOP_STYLES)[number]; color: string; accent?: string };
bottom: { style: (typeof BOTTOM_STYLES)[number]; color: string };
shoes: string;
};
/** Ficha do personagem na biblioteca. `kind: "3d"` aponta para a pessoa articulada da Godot (godot/kits). */
export type Character = {
schemaVersion: 1;
id: string;
name: string;
/** Texto curto que aparece na etiqueta (ex.: "Engenheiro de minas · 58 anos"). */
caption?: string;
description?: string;
kind: "cartoon" | "3d";
look: CharacterLook;
/** Só kind "3d": parâmetros da pessoa articulada da Godot. */
godot?: Record<string, unknown>;
createdAt?: string;
updatedAt?: string;
};
export const DEFAULT_LOOK: CharacterLook = {
build: "average", height: 1, skin: "#c98a5e",
hair: { style: "short", color: "#3a2a1e" }, beard: { style: "none", color: "#3a2a1e" },
glasses: "none", brows: "thin",
top: { style: "shirt", color: "#4f7a4a", accent: "#e8b13a" }, bottom: { style: "pants", color: "#2b3350" }, shoes: "#1b1b22",
};
const HEX = /^#[0-9a-f]{6}$/i;
const one = <T extends readonly string[]>(list: T, v: unknown): v is T[number] => typeof v === "string" && list.includes(v);
/** Confere a aparência e devolve os problemas (vazio = ok). */
export function validateLook(look: unknown): string[] {
const l = look as Partial<CharacterLook> | null;
if (!l || typeof l !== "object") return ["look precisa ser um objeto"];
const errors: string[] = [];
if (!one(BUILDS, l.build)) errors.push(`build: ${BUILDS.join("|")}`);
if (typeof l.height !== "number" || !(l.height >= 0.6 && l.height <= 1.2)) errors.push("height entre 0,6 e 1,2");
for (const [k, v] of [["skin", l.skin], ["hair.color", l.hair?.color], ["beard.color", l.beard?.color], ["top.color", l.top?.color],
["bottom.color", l.bottom?.color], ["shoes", l.shoes]] as const) {
if (typeof v !== "string" || !HEX.test(v)) errors.push(`${k}: cor #rrggbb`);
}
if (l.top?.accent !== undefined && !HEX.test(l.top.accent)) errors.push("top.accent: cor #rrggbb");
if (!one(HAIR_STYLES, l.hair?.style)) errors.push(`hair.style: ${HAIR_STYLES.join("|")}`);
if (!one(BEARD_STYLES, l.beard?.style)) errors.push(`beard.style: ${BEARD_STYLES.join("|")}`);
if (!one(GLASSES, l.glasses)) errors.push(`glasses: ${GLASSES.join("|")}`);
if (!one(BROWS, l.brows)) errors.push(`brows: ${BROWS.join("|")}`);
if (!one(TOP_STYLES, l.top?.style)) errors.push(`top.style: ${TOP_STYLES.join("|")}`);
if (!one(BOTTOM_STYLES, l.bottom?.style)) errors.push(`bottom.style: ${BOTTOM_STYLES.join("|")}`);
return errors;
}
export const isExpression = (v: unknown): v is Expression => one(EXPRESSIONS, v);
export const isPose = (v: unknown): v is Pose => one(POSES, v);
+32
View File
@@ -0,0 +1,32 @@
// Cores e nomes de fonte do estilo Cartoon (vetor chapado). Sem Remotion: o painel também usa.
import type { TimeOfDay, Tone } from "./spec";
export const SKY: Record<TimeOfDay, [string, string]> = {
night: ["#0b0e22", "#1c2147"],
dawn: ["#2a2c5c", "#8a6a9c"],
day: ["#5aa9e6", "#bfe3f5"],
};
export const COLORS = {
ground: "#14172e",
road: "#1a1d38",
roadLine: "#3a3f6b",
house: ["#3b3f74", "#34386a", "#2f3362", "#41467e"],
houseFar: "#2a2d57",
roof: "#272a52",
window: "#1b1d3a",
light: "#ffc94a",
glow: "rgba(255, 190, 70, 0.35)",
text: "#ffffff",
key: "#ffcf3f",
danger: "#ff4d4d",
ok: "#3ddc84",
ink: "#0c0d1a",
blueprint: "#10245a",
grid: "rgba(120, 160, 255, 0.12)",
};
export const TONE_BG: Record<Tone, string> = { info: "#ffcf3f", danger: "#ff4d4d", ok: "#3ddc84" };
export const TONE_FG: Record<Tone, string> = { info: "#141414", danger: "#ffffff", ok: "#0c2a18" };
export const FONT_CAPTION = "CartoonAnton";
export const FONT_LABEL = "CartoonBebas";
+77
View File
@@ -0,0 +1,77 @@
// Ícones chapados (viewBox 100×100). Formas simples, sem contorno, na paleta do estilo.
import React from "react";
import { COLORS } from "./colors";
import type { IconId } from "./spec";
const INK = COLORS.ink;
const DRAW: Record<IconId, React.ReactNode> = {
house: (<>
<polygon points="8,46 50,12 92,46" fill={COLORS.roof} />
<rect x={16} y={44} width={68} height={48} fill={COLORS.house[3]} />
<rect x={24} y={54} width={14} height={14} rx={2} fill={COLORS.light} />
<rect x={62} y={54} width={14} height={14} rx={2} fill={COLORS.light} />
<rect x={44} y={66} width={12} height={26} fill={COLORS.window} />
</>),
generator: (<>
<rect x={8} y={30} width={84} height={56} rx={8} fill="#2a2d3c" />
<rect x={14} y={22} width={58} height={16} rx={6} fill="#e8463d" />
<rect x={16} y={44} width={34} height={34} rx={4} fill="#4a4e63" />
{[0, 1, 2, 3, 4].map((i) => <rect key={i} x={19} y={48 + i * 6} width={28} height={3} fill="#2a2d3c" />)}
<circle cx={64} cy={52} r={4} fill="#11121a" /><circle cx={76} cy={52} r={4} fill="#11121a" />
<circle cx={70} cy={68} r={3} fill={COLORS.ok} />
<rect x={10} y={86} width={14} height={6} fill="#11121a" /><rect x={76} y={86} width={14} height={6} fill="#11121a" />
</>),
fuel: (<>
<rect x={20} y={22} width={60} height={72} rx={8} fill="#c8352f" />
<rect x={26} y={50} width={48} height={38} rx={4} fill="#e6b347" />
<path d="M30 22 L30 12 L60 12 L60 22" stroke="#c8352f" strokeWidth={6} fill="none" />
<rect x={66} y={8} width={12} height={14} fill="#c8352f" />
<path d="M30 56 L70 84 M70 56 L30 84" stroke="#c8352f" strokeWidth={3} />
</>),
battery: (<>
<rect x={28} y={14} width={44} height={80} rx={8} fill="#1d2b2a" stroke={COLORS.ok} strokeWidth={4} />
<rect x={40} y={6} width={20} height={10} rx={3} fill={COLORS.ok} />
<polygon points="54,30 38,58 50,58 46,80 62,50 50,50" fill={COLORS.ok} />
</>),
phone: (<>
<rect x={30} y={8} width={40} height={84} rx={8} fill="#15161f" />
<rect x={35} y={16} width={30} height={64} rx={3} fill="#2c3150" />
<rect x={42} y={40} width={16} height={8} rx={2} fill={COLORS.danger} />
</>),
door: (<>
<rect x={24} y={6} width={52} height={90} rx={3} fill="#4a2f22" />
<rect x={30} y={14} width={40} height={34} rx={2} fill="#3c251b" />
<rect x={30} y={54} width={40} height={34} rx={2} fill="#3c251b" />
<circle cx={66} cy={56} r={3.5} fill="#e6c27a" />
</>),
eye: (<>
<path d="M6 50 Q50 10 94 50 Q50 90 6 50 Z" fill="#f4f6ff" />
<circle cx={50} cy={50} r={20} fill="#2c3466" /><circle cx={50} cy={50} r={9} fill={INK} /><circle cx={56} cy={44} r={4} fill="#fff" />
</>),
bulb: (<>
<circle cx={50} cy={40} r={28} fill={COLORS.light} />
<rect x={38} y={64} width={24} height={16} rx={3} fill="#9aa0b8" /><rect x={42} y={80} width={16} height={8} rx={3} fill="#6c7190" />
</>),
solar: (<>
<polygon points="10,70 30,30 92,30 72,70" fill="#2b4fb8" />
<path d="M30 50 L82 50 M27 40 L87 40 M24 60 L77 60 M45 30 L35 70 M61 30 L51 70 M77 30 L67 70" stroke="#8fb0ff" strokeWidth={2} />
<rect x={46} y={70} width={6} height={22} fill="#6c7190" />
</>),
warning: (<>
<polygon points="50,8 94,88 6,88" fill={COLORS.key} />
<rect x={46} y={34} width={8} height={30} rx={3} fill={INK} /><circle cx={50} cy={74} r={5} fill={INK} />
</>),
money: (<>
<rect x={8} y={26} width={84} height={48} rx={6} fill="#3a9e5f" />
<circle cx={50} cy={50} r={14} fill="#2b7a49" /><text x={50} y={57} textAnchor="middle" fontSize={20} fontWeight={700} fill="#d9f5e3">$</text>
</>),
clock: (<>
<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} />
</>),
};
export function Icon({ id }: { id: IconId }) {
return <svg viewBox="0 0 100 100" width="100%" height="100%" overflow="visible">{DRAW[id]}</svg>;
}
+4
View File
@@ -0,0 +1,4 @@
import { registerRoot } from "remotion";
import { Root } from "./Root";
registerRoot(Root);
+132
View File
@@ -0,0 +1,132 @@
// 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).
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";
/** 0 → 1 com mola, a partir de `startS` (antes disso, 0). */
export function pop(frame: number, fps: number, startS = 0, stiffness = 220): number {
const f = frame - Math.round(startS * fps);
return f < 0 ? 0 : spring({ frame: f, fps, config: { damping: 13, stiffness, mass: 0.6 } });
}
/** Tremor determinístico de ±amp px (vibração do gerador, onomatopeia). */
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 };
}
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 }) {
return (
<span style={{ fontFamily: FONT_LABEL, fontSize: `${size}cqw`, letterSpacing: "0.04em", lineHeight: 1, whiteSpace: "nowrap",
padding: "0.25em 0.5em 0.15em", borderRadius: "0.25em", background: TONE_BG[tone], color: TONE_FG[tone],
boxShadow: "0 0.15em 0 rgba(0,0,0,0.35)" }}>
{text.toUpperCase()}
</span>
);
}
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") {
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>
);
}
const s = 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,
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()}
</div>
);
}
/** Anéis que crescem e somem em volta de (x, y) — barulho, luz chamando atenção. */
export function Rings({ frame, fps, color = COLORS.key }: { frame: number; fps: number; color?: string }) {
const period = fps * 1.3;
return (
<svg viewBox="-100 -100 200 200" width="100%" height="100%" overflow="visible" style={{ position: "absolute", inset: 0 }}>
{[0, 1, 2].map((i) => {
const p = ((frame + (i * period) / 3) % period) / period;
return <circle key={i} r={30 + p * 70} fill="none" stroke={color} strokeWidth={2.5} opacity={(1 - p) * 0.8} />;
})}
</svg>
);
}
/** X vermelho que se desenha por cima de algo ("não faça"). */
export function CrossOut({ k }: { k: number }) {
const len = 140 * Math.min(1, k);
return (
<svg viewBox="0 0 100 100" width="100%" height="100%" overflow="visible" style={{ position: "absolute", inset: 0 }}>
<line x1={0} y1={0} x2={len / 1.41} y2={len / 1.41} stroke={COLORS.danger} strokeWidth={9} strokeLinecap="round" />
{k > 0.5 && <line x1={100} y1={0} x2={100 - ((k - 0.5) * 2 * 140) / 1.41} y2={((k - 0.5) * 2 * 140) / 1.41} stroke={COLORS.danger} strokeWidth={9} strokeLinecap="round" />}
</svg>
);
}
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")}`;
}
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>
);
}
/** Agrupa as palavras em blocos de até 3 (quebra também depois de pontuação), como a legenda da referência. */
export function captionChunks(words: Word[]): Word[][] {
const chunks: Word[][] = [];
let current: Word[] = [];
for (const w of words) {
current.push(w);
if (current.length >= 3 || /[.,!?;:…]$/.test(w.text)) { chunks.push(current); current = []; }
}
if (current.length) chunks.push(current);
return chunks;
}
export function Captions({ words, frame, fps, y = 0.665 }: { 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;
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 }}>
{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";
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)" }}>
{w.text.toUpperCase().replace(/[.,;:]$/, "")}
</span>
);
})}
</div>
);
}
+142
View File
@@ -0,0 +1,142 @@
// 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).
import React from "react";
import { rng } from "./random";
import type { ShotSpec } from "./spec";
export const PALETTES = ["night", "sepia", "day", "dusk", "gray"] as const;
export type PaletteId = (typeof PALETTES)[number];
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;
export type ElementKind = (typeof ELEMENTS)[number];
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). */
horizon?: number;
fog?: boolean;
elements: { kind: ElementKind; x: number; z?: number; scale?: number; flip?: boolean; color?: string }[];
};
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;
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("")}`;
}
/** 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>;
default: return null;
}
}
export function PlaceBackground({ spec, frame }: { spec: ShotSpec; frame: number }) {
const place = spec.place!;
const pal = palette(spec.palette);
const horizon = (place.horizon ?? 0.56) * H;
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);
const rand = rng(spec.seed + 13);
const stars = !place.indoor && (spec.palette ?? "night") === "night"
? Array.from({ length: 60 }, () => ({ x: rand() * W, y: rand() * horizon * 0.8, r: 1 + rand() * 2, p: rand() * 6 })) : [];
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>
</defs>
<rect width={W} height={H} fill={place.indoor ? pal.wall : "url(#placeSky)"} />
{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>
);
})}
{place.fog && <rect x={0} y={horizon - H * 0.15} width={W} height={H * 0.5} 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%)" }} />;
}
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} />
</svg>
);
}
+11
View File
@@ -0,0 +1,11 @@
/** Sorteio determinístico (mulberry32): a mesma semente desenha sempre o mesmo cenário. */
export function rng(seed: number): () => number {
let a = (Math.floor(seed) >>> 0) || 1;
return () => {
a = (a + 0x6d2b79f5) >>> 0;
let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
+19
View File
@@ -0,0 +1,19 @@
// Trecho de exemplo (Studio e teste de render). Conteúdo próprio, só para mostrar as peças.
import type { ShotSpec } from "./spec";
const say = (text: string, from: number, step = 0.42) =>
text.split(" ").map((w, i) => ({ text: w.replace(/[*_]/g, ""), startS: from + i * step, endS: from + (i + 1) * step,
tone: w.startsWith("*") ? ("key" as const) : w.startsWith("_") ? ("danger" as const) : undefined }));
export const SAMPLE: ShotSpec = {
schemaVersion: 1,
width: 1080, height: 1920, fps: 30, durationS: 6,
seed: 11,
scene: { kind: "street", time: "night", litHouse: true },
camera: { push: 1.08, panX: 0.05 },
hud: { badge: "Tempestade", label: "Noite 1", clock: "22:00", clockMinutesPerSecond: 1 },
actors: [{ kind: "person", x: 0.28, y: 0.6, outfit: "#f2c230", hair: "short", hairColor: "#3a2a1e", label: "Seu João", enterS: 0.4, pointing: true }],
props: [{ icon: "generator", x: 0.72, y: 0.52, size: 0.12, label: "Gerador", shake: true, rings: true, enterS: 1.2 }],
texts: [{ kind: "onomatopoeia", text: "Vrrrum", x: 0.68, y: 0.4, atS: 1.6, rotate: -6 }],
words: say("A única casa *acesa da rua chama _atenção", 0.3),
};
+162
View File
@@ -0,0 +1,162 @@
// Fundos do estilo Cartoon, desenhados num espaço fixo de 1080×1920 (o SVG escala para o tamanho do vídeo).
import React from "react";
import { COLORS, FONT_CAPTION, FONT_LABEL, SKY } from "./theme";
import { rng } from "./random";
import { PlaceBackground } from "./places";
import type { ShotSpec, TimeOfDay } from "./spec";
export const W = 1080;
export const H = 1920;
type SceneProps = { spec: ShotSpec; frame: number; progress: number };
function Sky({ time, seed, frame }: { time: TimeOfDay; seed: number; frame: number }) {
const [top, bottom] = SKY[time];
const rand = rng(seed + 7);
const stars = time === "day" ? [] : Array.from({ length: 70 }, () => ({ x: rand() * W, y: rand() * H * 0.45, r: 1 + rand() * 2.2, p: rand() * 6 }));
return (
<>
<defs>
<linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stopColor={top} />
<stop offset="1" stopColor={bottom} />
</linearGradient>
<radialGradient id="glow">
<stop offset="0" stopColor="rgba(255,200,80,0.55)" />
<stop offset="1" stopColor="rgba(255,200,80,0)" />
</radialGradient>
</defs>
<rect width={W} height={H} fill="url(#sky)" />
{stars.map((s, i) => (
<circle key={i} cx={s.x} cy={s.y} r={s.r} fill="#fff" opacity={0.35 + 0.35 * Math.sin(frame / 12 + s.p)} />
))}
{time === "night" && <circle cx={W * 0.2} cy={H * 0.11} r={38} fill="#f4ecc8" />}
{time === "dawn" && <circle cx={W * 0.8} cy={H * 0.2} r={46} fill="#ffd36b" />}
{time === "day" && <circle cx={W * 0.82} cy={H * 0.1} r={56} fill="#ffe27a" />}
</>
);
}
/** Casa chapada: corpo, telhado, janelas (acesas ou não) e porta. */
export function HouseShape({ x, base, w, h, color, lit, detail = true }: {
x: number; base: number; w: number; h: number; color: string; lit?: boolean; detail?: boolean;
}) {
const roofH = h * 0.42;
const win = w * 0.18;
const winY = base - h * 0.62;
const windowFill = lit ? COLORS.light : COLORS.window;
return (
<g>
{lit && <ellipse cx={x + w / 2} cy={base - h * 0.5} rx={w * 1.4} ry={h * 1.3} fill="url(#glow)" />}
<polygon points={`${x - w * 0.06},${base - h} ${x + w / 2},${base - h - roofH} ${x + w * 1.06},${base - h}`} fill={COLORS.roof} />
<rect x={x} y={base - h} width={w} height={h} fill={color} />
{detail && (
<>
<rect x={x + w * 0.14} y={winY} width={win} height={win * 1.1} rx={3} fill={windowFill} />
<rect x={x + w * 0.68} y={winY} width={win} height={win * 1.1} rx={3} fill={windowFill} />
<rect x={x + w * 0.42} y={base - h * 0.48} width={w * 0.16} height={h * 0.48} fill={COLORS.window} />
</>
)}
</g>
);
}
function Street({ spec, frame, progress }: SceneProps) {
const time = spec.scene.time ?? "night";
const pan = (spec.camera?.panX ?? 0) * W * progress;
const rand = rng(spec.seed);
const rows = [
{ base: H * 0.43, w: 92, h: 70, gap: 6, color: COLORS.houseFar, depth: 0.25, detail: false },
{ base: H * 0.5, w: 150, h: 110, gap: 14, color: COLORS.house[2], depth: 0.5, detail: true },
{ base: H * 0.6, w: 250, h: 180, gap: 30, color: COLORS.house[0], depth: 1, detail: true },
];
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice">
<Sky time={time} seed={spec.seed} frame={frame} />
{rows.map((row, r) => {
const count = Math.ceil((W * 1.6) / (row.w + row.gap)) + 2;
const start = -W * 0.3 - pan * row.depth;
const litIndex = spec.scene.litHouse && r === 2 ? Math.floor(count / 2) - 1 : -1;
return (
<g key={r}>
<rect x={0} y={row.base} width={W} height={H * 0.6 - row.base + 2} fill={r === 2 ? COLORS.ground : "transparent"} />
{Array.from({ length: count }, (_, i) => {
const jitter = (rand() - 0.5) * row.h * 0.18;
return (
<HouseShape key={i} x={start + i * (row.w + row.gap)} base={row.base} w={row.w} h={row.h + jitter}
color={row.color} lit={i === litIndex} detail={row.detail} />
);
})}
</g>
);
})}
<rect x={0} y={H * 0.6} width={W} height={H * 0.4} fill={COLORS.road} />
{Array.from({ length: 9 }, (_, i) => (
<rect key={i} x={((i * 160 - pan * 1.2) % (W + 160)) - 80} y={H * 0.735} width={90} height={8} rx={4} fill={COLORS.roadLine} />
))}
</svg>
);
}
function HouseFront({ spec, frame }: SceneProps) {
const time = spec.scene.time ?? "night";
const lit = !!spec.scene.litHouse;
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice">
<Sky time={time} seed={spec.seed} frame={frame} />
<polygon points={`-40,${H * 0.3} ${W / 2},${H * 0.17} ${W + 40},${H * 0.3}`} fill={COLORS.roof} />
<rect x={0} y={H * 0.3} width={W} height={H * 0.32} fill={COLORS.house[3]} />
<rect x={W * 0.08} y={H * 0.36} width={W * 0.2} height={H * 0.08} rx={6} fill={lit ? COLORS.light : COLORS.window} />
<rect x={W * 0.72} y={H * 0.36} width={W * 0.2} height={H * 0.08} rx={6} fill={lit ? COLORS.light : COLORS.window} />
<rect x={0} y={H * 0.53} width={W} height={H * 0.09} fill={COLORS.house[1]} />
{Array.from({ length: 13 }, (_, i) => (
<rect key={i} x={W * 0.34 + i * 26} y={H * 0.53} width={7} height={H * 0.09} fill={COLORS.ink} />
))}
<rect x={W * 0.33} y={H * 0.53} width={W * 0.34} height={10} fill={COLORS.ink} />
<rect x={0} y={H * 0.62} width={W} height={H * 0.38} fill={COLORS.road} />
</svg>
);
}
function Plain({ spec, frame }: SceneProps) {
const time = spec.scene.time ?? "night";
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice">
<Sky time={time} seed={spec.seed} frame={frame} />
<rect x={0} y={H * 0.6} width={W} height={H * 0.4} fill={COLORS.road} />
</svg>
);
}
function Blueprint() {
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice">
<rect width={W} height={H} fill={COLORS.blueprint} />
{Array.from({ length: 28 }, (_, i) => <rect key={`v${i}`} x={i * 40} y={0} width={1.5} height={H} fill={COLORS.grid} />)}
{Array.from({ length: 49 }, (_, i) => <rect key={`h${i}`} x={0} y={i * 40} width={W} height={1.5} fill={COLORS.grid} />)}
</svg>
);
}
function Card({ spec }: SceneProps) {
const card = spec.card!;
return (
<div style={{ position: "absolute", inset: 0, background: "#07080f", display: "flex", flexDirection: "column",
alignItems: "center", justifyContent: "center", gap: "1.2%", textAlign: "center", padding: "0 8%" }}>
<div style={{ fontFamily: FONT_CAPTION, fontSize: "11cqw", color: COLORS.text, lineHeight: 1 }}>{card.title}</div>
{card.subtitle && <div style={{ fontFamily: FONT_LABEL, fontSize: "6cqw", color: COLORS.key }}>{card.subtitle}</div>}
{card.footer && <div style={{ fontFamily: FONT_LABEL, fontSize: "3.2cqw", color: "#b7b9cc", marginTop: "6%" }}>{card.footer}</div>}
</div>
);
}
export function SceneBackground(props: SceneProps) {
switch (props.spec.scene.kind) {
case "place": return <PlaceBackground spec={props.spec} frame={props.frame} />;
case "street": return <Street {...props} />;
case "house": return <HouseFront {...props} />;
case "blueprint": return <Blueprint />;
case "card": return <Card {...props} />;
default: return <Plain {...props} />;
}
}
+152
View File
@@ -0,0 +1,152 @@
// Contrato de um trecho do estilo Cartoon (versão 1). O painel escreve este JSON por trecho da montagem e o
// render (render.ts) transforma cada um num MP4 com a duração do áudio do trecho. Posições (x, y) são frações
// do quadro (0 = esquerda/topo, 1 = direita/base). Tempos em segundos, a partir do início do trecho.
import { EXPRESSIONS, POSES, validateLook, type CharacterLook, type Expression, type Pose } from "./character";
import { ELEMENTS, GROUNDS, PALETTES, type PaletteId, type Place } from "./places";
/** "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;
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 type IconId = (typeof ICONS)[number];
export const TONES = ["info", "danger", "ok"] as const;
export type Tone = (typeof TONES)[number];
export type Person = {
kind: "person";
x: number; y: number; scale?: number;
/** Personagem da biblioteca (aparência por peças). Sem ele, usa o boneco simples abaixo (outfit/hair…). */
character?: { name: string; caption?: string; look: CharacterLook };
expression?: Expression;
pose?: Pose;
/** Objeto na mão (pose "hold" ou "point"). */
item?: IconId;
/** Olha para a esquerda (espelha o desenho). */
flip?: boolean;
/** Cor da roupa (hex). */
outfit?: string;
hair?: "short" | "bun" | "none";
hairColor?: string;
skin?: string;
glasses?: boolean;
/** Braço direito levantado (apontando/segurando). */
pointing?: boolean;
label?: string;
enterS?: number;
};
export type Crowd = { kind: "crowd"; count: number; y: number; enterS?: number };
export type Actor = Person | Crowd;
export type Prop = {
icon: IconId;
x: number; y: number;
/** Altura em fração do quadro (padrão 0,16). */
size?: number;
label?: string;
tone?: Tone;
enterS?: number;
shake?: boolean;
rings?: boolean;
crossed?: boolean;
};
export type TextItem = {
kind: "onomatopoeia" | "tag" | "counter" | "big";
text: string;
/** Só no "counter": o número grande embaixo do rótulo. */
value?: string;
x: number; y: number;
atS?: number;
tone?: Tone;
/** Graus (onomatopeia costuma ir levemente girada). */
rotate?: number;
};
export type Word = { text: string; startS: number; endS: number; tone?: "key" | "danger" };
export type ShotSpec = {
schemaVersion: 1;
width: number; height: number; fps: number;
durationS: number;
seed: number;
scene: { kind: SceneKind; time?: TimeOfDay; litHouse?: boolean };
/** Paleta do estilo (a mesma na história inteira dá a "cara" da série). */
palette?: PaletteId;
/** Lugar montado por peças (scene.kind "place"). */
place?: Place;
/** Luz por cima: foco do teto ("spot") ou vinheta. */
light?: (typeof LIGHTS)[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 };
actors?: Actor[];
props?: Prop[];
texts?: TextItem[];
/** Legenda palavra por palavra (tempos da narração). Vazio = sem legenda. */
words?: Word[];
card?: { title: string; subtitle?: string; footer?: string };
};
const finite = (v: unknown) => typeof v === "number" && Number.isFinite(v);
const frac = (v: unknown) => finite(v) && (v as number) >= -0.5 && (v as number) <= 1.5;
/** Confere o spec e devolve a lista de problemas (vazia = válido). Não aceita nada além de dados. */
export function validateSpec(spec: unknown): string[] {
const errors: string[] = [];
const s = spec as Partial<ShotSpec> | null;
if (!s || typeof s !== "object") return ["o spec precisa ser um objeto"];
if (s.schemaVersion !== 1) errors.push("schemaVersion precisa ser 1");
if (!finite(s.width) || !finite(s.height) || s.width! < 64 || s.height! < 64 || s.width! % 2 || s.height! % 2) {
errors.push("width/height precisam ser números pares ≥ 64");
}
if (!finite(s.fps) || s.fps! < 1 || s.fps! > 60) errors.push("fps entre 1 e 60");
if (!finite(s.durationS) || s.durationS! <= 0 || s.durationS! > 120) errors.push("durationS entre 0 e 120 s");
if (!finite(s.seed)) errors.push("seed precisa ser número");
if (!s.scene || !SCENES.includes(s.scene.kind)) errors.push(`scene.kind precisa ser um de: ${SCENES.join(", ")}`);
if (s.scene?.time !== undefined && !TIMES.includes(s.scene.time)) errors.push(`scene.time precisa ser um de: ${TIMES.join(", ")}`);
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.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`);
else {
if (place.elements.length > 40) errors.push("place: no máximo 40 peças");
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`);
}
}
}
for (const [i, a] of (s.actors ?? []).entries()) {
if (a.kind === "person" && (!frac(a.x) || !frac(a.y))) errors.push(`actors[${i}]: x/y fora do quadro`);
else if (a.kind === "person" && a.character && (typeof a.character.name !== "string" || validateLook(a.character.look).length)) {
errors.push(`actors[${i}].character: ${validateLook(a.character.look).join("; ") || "name obrigatório"}`);
} else if (a.kind === "person" && a.expression !== undefined && !EXPRESSIONS.includes(a.expression)) errors.push(`actors[${i}]: expressão (${EXPRESSIONS.join(", ")})`);
else if (a.kind === "person" && a.pose !== undefined && !POSES.includes(a.pose)) errors.push(`actors[${i}]: pose (${POSES.join(", ")})`);
else if (a.kind === "person" && a.item !== undefined && !ICONS.includes(a.item)) errors.push(`actors[${i}]: item "${a.item}" não existe`);
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.kind !== "person" && a.kind !== "crowd") 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`);
}
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`);
}
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));
+20
View File
@@ -0,0 +1,20 @@
// Fontes do estilo Cartoon (carregadas pela Remotion antes do 1º quadro). As cores ficam em colors.ts.
import { continueRender, delayRender, staticFile } from "remotion";
import { FONT_CAPTION, FONT_LABEL } from "./colors";
export * from "./colors";
let loaded = false;
/** Carrega as fontes de assets/fonts antes do primeiro quadro (o render espera). */
export function loadFonts(): void {
if (loaded || typeof document === "undefined") return;
loaded = true;
const handle = delayRender("fontes do Cartoon");
const faces = [
new FontFace(FONT_CAPTION, `url(${staticFile("fonts/Anton-Regular.ttf")})`),
new FontFace(FONT_LABEL, `url(${staticFile("fonts/BebasNeue-Regular.ttf")})`),
];
Promise.all(faces.map((f) => f.load().then((ok) => document.fonts.add(ok))))
.then(() => continueRender(handle))
.catch((error) => { console.error("fontes do Cartoon:", error); continueRender(handle); });
}