truth-or-dare / source /src /index.tsx
Ethscriptions's picture
v2: 去掉 ROUND/emoji/平手/长按提示,标签居中,心里标黄;实况去掉赢输说明,我出+手势居中放大
121109d verified
Raw History Blame Contribute Delete
12.4 kB
import React, {useEffect, useState} from 'react';
import {
AbsoluteFill, Audio, Composition, Easing, Img, continueRender, delayRender, interpolate,
registerRoot, staticFile, useCurrentFrame, useVideoConfig,
} from 'remotion';
/* ───────────────── 内容 ───────────────── */
export type Hand = 'rock' | 'scissors' | 'paper';
type Props = {hand: Hand; round: number};
const HANDS: Record<Hand, {zh: string; file: string; beats: string}> = {
rock: {zh: '石头', file: '270a.svg', beats: '✊'},
scissors: {zh: '剪刀', file: '270c.svg', beats: '✌️'},
paper: {zh: '布', file: '1f590.svg', beats: '🖐'},
};
const TRUTH = {label: '真心话', line1: '说说看,', line2: '你多久没回家了?'};
const DARE = {label: '大冒险', line1: '现在、立刻,', line2: '给爸妈打个视频。'};
/* ───────────────── 色彩 ───────────────── */
const INK = '#0b0a0c';
const PAPER = '#f6efe4';
const AMBER = '#f5b942';
const RED = '#ff2d46';
const RED_DEEP = '#7a0d1c';
const clamp = {extrapolateLeft: 'clamp', extrapolateRight: 'clamp'} as const;
const outBack = Easing.bezier(0.34, 1.56, 0.64, 1);
const outExpo = Easing.bezier(0.16, 1, 0.3, 1);
const inExpo = Easing.bezier(0.7, 0, 0.84, 0);
/* 时间轴(30 fps, 90 帧) */
const T = {
coverHold: 12, // 0–12 封面停留(coverFrame = 6)
cardOut: 20, // 12–20 规则卡滑出
beats: [20, 30, 40], // 石头 / 剪刀 / 布
slam: 48, // 砸下
verdict: 56, // 底部结果条
end: 90,
};
/* ───────────────── 字体 ───────────────── */
const FontLoader: React.FC = () => {
const [handle] = useState(() => delayRender('fonts'));
useEffect(() => {
const faces = [
new FontFace('Smiley', `url(${staticFile('fonts/SmileySans-Oblique.ttf')})`),
new FontFace('NotoSC', `url(${staticFile('fonts/NotoSansSC.ttf')})`),
new FontFace('Poppins', `url(${staticFile('fonts/Poppins-ExtraBold.ttf')})`),
];
Promise.all(faces.map((f) => f.load())).then((loaded) => {
loaded.forEach((f) => (document.fonts as unknown as {add: (f: FontFace) => void}).add(f));
continueRender(handle);
});
}, [handle]);
return null;
};
const ZH = 'Smiley, NotoSC, "PingFang SC", sans-serif';
const BODY = 'NotoSC, "PingFang SC", sans-serif';
/* ───────────────── 背景 ───────────────── */
const Backdrop: React.FC<{heat: number}> = ({heat}) => (
<AbsoluteFill>
<AbsoluteFill style={{background: `radial-gradient(120% 90% at 50% 20%, #2a0f16 0%, ${INK} 60%)`}} />
<AbsoluteFill style={{opacity: heat, background: `radial-gradient(90% 70% at 50% 50%, ${RED_DEEP} 0%, rgba(11,10,12,0) 70%)`}} />
{/* 对角条纹 */}
<AbsoluteFill
style={{
opacity: 0.08,
backgroundImage: `repeating-linear-gradient(-28deg, ${PAPER} 0 10px, transparent 10px 44px)`,
}}
/>
{/* 暗角 */}
<AbsoluteFill style={{background: 'radial-gradient(80% 70% at 50% 45%, rgba(0,0,0,0) 55%, rgba(0,0,0,.72) 100%)'}} />
</AbsoluteFill>
);
/* ───────────────── 封面规则卡 ───────────────── */
const Cover: React.FC<{round: number; frame: number}> = ({frame}) => {
const out = interpolate(frame, [T.coverHold, T.cardOut], [0, 1], {...clamp, easing: inExpo});
const ty = -1600 * out;
const rot = -6 * out;
return (
<AbsoluteFill style={{transform: `translateY(${ty}px) rotate(${rot}deg)`, transformOrigin: '50% 100%'}}>
<div style={{position: 'absolute', top: 150, left: 0, right: 0, display: 'flex', justifyContent: 'center'}}>
<span style={{fontFamily: BODY, fontWeight: 700, fontSize: 30, letterSpacing: 4, color: PAPER, background: 'rgba(255,255,255,.08)', border: `2px solid rgba(246,239,228,.35)`, borderRadius: 999, padding: '12px 30px'}}>
真心话大冒险 · 猜拳版
</span>
</div>
<div style={{position: 'absolute', top: 262, left: 0, right: 0, textAlign: 'center', fontFamily: ZH, color: PAPER, lineHeight: 1.02}}>
<div style={{fontSize: 160, letterSpacing: 2}}>敢不敢</div>
<div style={{fontSize: 160, letterSpacing: 2}}>
跟我<span style={{color: RED}}>猜一把?</span>
</div>
</div>
<div style={{position: 'absolute', top: 648, left: 0, right: 0, textAlign: 'center', fontFamily: BODY, fontWeight: 700, fontSize: 40, color: PAPER, opacity: 0.94}}>
先在<span style={{color: AMBER}}>心里</span>出一个 · 再点进来看我出什么
</div>
<div style={{position: 'absolute', top: 750, left: 70, right: 70, height: 500, display: 'flex', gap: 0, borderRadius: 36, overflow: 'hidden', boxShadow: '0 30px 80px rgba(0,0,0,.6)'}}>
<div style={{flex: 1, background: AMBER, color: INK, padding: '46px 32px', position: 'relative'}}>
<div style={{fontFamily: 'Poppins', fontSize: 26, letterSpacing: 2, opacity: 0.75}}>IF YOU WIN</div>
<div style={{fontFamily: ZH, fontSize: 66, marginTop: 4}}>你赢 → 真心话</div>
<div style={{fontFamily: ZH, fontSize: 57, lineHeight: 1.14, marginTop: 34}}>
{TRUTH.line1}
<br />
{TRUTH.line2}
</div>
</div>
<div style={{width: 10, background: INK}} />
<div style={{flex: 1, background: RED, color: PAPER, padding: '46px 32px', position: 'relative'}}>
<div style={{fontFamily: 'Poppins', fontSize: 26, letterSpacing: 2, opacity: 0.8}}>IF YOU LOSE</div>
<div style={{fontFamily: ZH, fontSize: 66, marginTop: 4}}>你输 → 大冒险</div>
<div style={{fontFamily: ZH, fontSize: 57, lineHeight: 1.14, marginTop: 34}}>
{DARE.line1}
<br />
{DARE.line2}
</div>
</div>
</div>
</AbsoluteFill>
);
};
/* ───────────────── 倒数 ───────────────── */
const Countdown: React.FC<{frame: number}> = ({frame}) => {
if (frame < T.beats[0] - 4 || frame >= T.slam) return null;
const words = ['石头', '剪刀', '布!'];
let idx = 0;
for (let i = 0; i < T.beats.length; i++) if (frame >= T.beats[i]) idx = i;
const since = frame - T.beats[idx];
const pop = interpolate(since, [0, 6], [1.9, 1], {...clamp, easing: outBack});
const op = interpolate(since, [0, 2], [0, 1], clamp);
// 拳头上下挥动:每拍一下
const bob = Math.sin(((frame - T.beats[0]) / 10) * Math.PI) * -90;
const fistRot = Math.sin(((frame - T.beats[0]) / 10) * Math.PI) * -14;
const appear = interpolate(frame, [T.beats[0] - 4, T.beats[0]], [0, 1], {...clamp, easing: outExpo});
return (
<AbsoluteFill style={{opacity: appear}}>
<div style={{position: 'absolute', top: 300, left: 0, right: 0, display: 'flex', justifyContent: 'center'}}>
<Img src={staticFile('media/270a.svg')} style={{width: 380, height: 380, transform: `translateY(${bob}px) rotate(${fistRot}deg) scale(${appear})`, filter: 'drop-shadow(0 30px 40px rgba(0,0,0,.7))'}} />
</div>
<div style={{position: 'absolute', top: 760, left: 0, right: 0, textAlign: 'center', fontFamily: ZH, fontSize: 230, color: idx === 2 ? RED : PAPER, opacity: op, transform: `scale(${pop})`, textShadow: '0 20px 60px rgba(0,0,0,.6)'}}>
{words[idx]}
</div>
{/* 节拍点 */}
<div style={{position: 'absolute', top: 1060, left: 0, right: 0, display: 'flex', justifyContent: 'center', gap: 22}}>
{[0, 1, 2].map((i) => (
<span key={i} style={{width: 26, height: 26, borderRadius: 13, background: i <= idx ? AMBER : 'rgba(246,239,228,.25)'}} />
))}
</div>
</AbsoluteFill>
);
};
/* ───────────────── 砸下 & 结果 ───────────────── */
const Reveal: React.FC<{hand: Hand; frame: number}> = ({hand, frame}) => {
if (frame < T.slam) return null;
const s = frame - T.slam;
const scale = interpolate(s, [0, 7], [3.2, 1], {...clamp, easing: outBack});
const op = interpolate(s, [0, 2], [0, 1], clamp);
const breathe = 1 + Math.sin((s / 14) * Math.PI) * 0.025;
const ringR = interpolate(s, [0, 16], [0, 1], {...clamp, easing: outExpo});
const ringO = interpolate(s, [0, 16], [0.9, 0], clamp);
const lines = Array.from({length: 18}, (_, i) => i);
const label = interpolate(s, [5, 11], [0, 1], {...clamp, easing: outExpo});
const stamp = interpolate(frame, [T.verdict + 10, T.verdict + 16], [0, 1], {...clamp, easing: outBack});
const h = HANDS[hand];
return (
<AbsoluteFill>
{/* 冲击线 */}
<svg width={1080} height={1440} style={{position: 'absolute', inset: 0, opacity: ringO}}>
<g transform="translate(540 560)">
{lines.map((i) => {
const a = (i / lines.length) * Math.PI * 2;
const r0 = 300 + 400 * ringR;
const r1 = r0 + 140 + 260 * ringR;
return <line key={i} x1={Math.cos(a) * r0} y1={Math.sin(a) * r0} x2={Math.cos(a) * r1} y2={Math.sin(a) * r1} stroke={i % 2 ? AMBER : PAPER} strokeWidth={i % 3 ? 6 : 12} strokeLinecap="round" />;
})}
</g>
</svg>
{/* 手 */}
<div style={{position: 'absolute', top: 280, left: 0, right: 0, display: 'flex', justifyContent: 'center', opacity: op}}>
<Img src={staticFile(`media/${h.file}`)} style={{width: 620, height: 620, transform: `scale(${scale * breathe})`, filter: 'drop-shadow(0 40px 60px rgba(0,0,0,.75))'}} />
</div>
{/* 我出 + 手势(上下排列,水平居中) */}
<div style={{position: 'absolute', top: 930, left: 0, right: 0, textAlign: 'center', opacity: label, transform: `translateY(${(1 - label) * 40}px)`}}>
<div style={{fontFamily: ZH, fontSize: 84, color: PAPER, letterSpacing: 10, opacity: 0.95}}>我出</div>
<div style={{fontFamily: ZH, fontSize: 210, lineHeight: 1.05, color: AMBER, textShadow: '0 16px 50px rgba(0,0,0,.6)'}}>{h.zh}</div>
</div>
{/* 盖章 */}
<div
style={{
position: 'absolute', top: 120, right: 70, transform: `rotate(-14deg) scale(${stamp})`, opacity: stamp, transformOrigin: '50% 50%',
border: `8px solid ${RED}`, color: RED, borderRadius: 18, padding: '8px 26px', fontFamily: ZH, fontSize: 64, letterSpacing: 6,
background: 'rgba(11,10,12,.55)',
}}
>
别赖皮
</div>
</AbsoluteFill>
);
};
/* ───────────────── 主 composition ───────────────── */
export const Game: React.FC<Props> = ({hand, round}) => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
void fps;
const heat = interpolate(frame, [T.beats[0], T.slam, T.slam + 10], [0.15, 0.55, 0.85], clamp);
// 砸下时的镜头抖动 + 白闪
const s = frame - T.slam;
const shakeAmp = s >= 0 ? 26 * Math.exp(-s / 3.2) : 0;
const sx = shakeAmp * Math.sin(s * 12.9);
const sy = shakeAmp * Math.cos(s * 9.7);
const flash = s >= 0 ? interpolate(s, [0, 1, 4], [0.95, 0.6, 0], clamp) : 0;
const zoom = s >= 0 ? 1 + 0.06 * Math.exp(-s / 5) : 1;
return (
<AbsoluteFill style={{background: INK, overflow: 'hidden'}}>
<FontLoader />
<Audio src={staticFile(`audio/${hand}.wav`)} />
<AbsoluteFill style={{transform: `translate(${sx}px, ${sy}px) scale(${zoom})`}}>
<Backdrop heat={heat} />
<Countdown frame={frame} />
<Reveal hand={hand} frame={frame} />
<Cover round={round} frame={frame} />
</AbsoluteFill>
<AbsoluteFill style={{background: PAPER, opacity: flash, pointerEvents: 'none'}} />
{/* 颗粒 */}
<AbsoluteFill style={{opacity: 0.07, mixBlendMode: 'overlay', backgroundImage: 'repeating-radial-gradient(circle at 37% 61%, #fff 0 1px, transparent 1px 3px)'}} />
</AbsoluteFill>
);
};
const Root: React.FC = () => (
<>
{(['rock', 'scissors', 'paper'] as Hand[]).map((hand, i) => (
<Composition key={hand} id={`tod-${hand}`} component={Game} durationInFrames={T.end} fps={30} width={1080} height={1440} defaultProps={{hand, round: i + 1}} />
))}
</>
);
registerRoot(Root);