Spaces:
Paused
Paused
步骤3:渲染引擎 + 9 个场景 + WebGL 后期 + 播放器(横屏/竖屏)
Browse files- Dockerfile +24 -0
- README.md +2 -1
- src/mv/MvApp.tsx +671 -0
- src/mv/engine/audio.ts +116 -0
- src/mv/engine/draw.ts +613 -0
- src/mv/engine/post.ts +336 -0
- src/mv/engine/renderer.ts +140 -0
- src/mv/engine/scenesA.ts +703 -0
- src/mv/engine/scenesB.ts +842 -0
- src/mv/engine/timeline.ts +70 -0
- src/mv/engine/types.ts +35 -0
- src/mv/engine/util.ts +104 -0
- src/mv/styles.css +816 -0
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ---- build -------------------------------------------------------------
|
| 2 |
+
FROM node:20-alpine AS build
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
COPY package.json ./
|
| 5 |
+
RUN npm install --no-audit --no-fund
|
| 6 |
+
COPY . .
|
| 7 |
+
# the song lives in 素材/; copy it into the site (download it if LFS was not materialised)
|
| 8 |
+
RUN mkdir -p public && \
|
| 9 |
+
if [ -f "素材/黑街.mp3" ] && [ "$(stat -c%s "素材/黑街.mp3")" -gt 100000 ]; then \
|
| 10 |
+
cp "素材/黑街.mp3" public/heijie.mp3; \
|
| 11 |
+
else \
|
| 12 |
+
wget -q -O public/heijie.mp3 "https://huggingface.co/spaces/Ethscriptions/video/resolve/main/%E7%B4%A0%E6%9D%90/%E9%BB%91%E8%A1%97.mp3"; \
|
| 13 |
+
fi && \
|
| 14 |
+
npm run build
|
| 15 |
+
|
| 16 |
+
# ---- run ---------------------------------------------------------------
|
| 17 |
+
FROM node:20-alpine
|
| 18 |
+
WORKDIR /app
|
| 19 |
+
COPY --from=build /app/dist ./dist
|
| 20 |
+
COPY server.mjs ./
|
| 21 |
+
ENV PORT=3000
|
| 22 |
+
EXPOSE 3000
|
| 23 |
+
USER node
|
| 24 |
+
CMD ["node", "server.mjs"]
|
README.md
CHANGED
|
@@ -151,7 +151,7 @@ pinned: false
|
|
| 151 |
|
| 152 |
- [x] 步骤 1:克隆仓库,下载 LFS 素材,抽帧,分析画面和音乐 → 写好本 README → **推送**
|
| 153 |
- [x] 步骤 2:删除旧代码,搭好新项目骨架(Vite + React + TS + Dockerfile + 静态服务器 + 音频特征数据)→ **推送**
|
| 154 |
-
- [
|
| 155 |
- [ ] 步骤 4:浏览器本地 MP4 导出(24/30/60fps,横 / 竖屏,多分辨率)→ **推送**
|
| 156 |
- [ ] 步骤 5:平台文案(小红书 / 抖音 / 视频号 / B 站)+ 多比例多款封面,可多选下载 → **推送**
|
| 157 |
- [ ] 步骤 6:整体打磨、移动端测试、构建验证、Space 运行检查 → **最终推送**
|
|
@@ -162,3 +162,4 @@ pinned: false
|
|
| 162 |
|
| 163 |
- **步骤 1** ✅ 素材下载与分析完成(211 张截图、调色板 / 亮度 / 平涂率统计、BPM 105.5、Drop 位置 38.2s / 109.4s),计划已写入 README。
|
| 164 |
- **步骤 2** ✅ 删除旧 `Dockerfile`(kvideo 镜像),新建 Vite + React + TS 项目骨架:`package.json`、`vite.config.ts`、`index.html`、零依赖静态服务器 `server.mjs`(支持 Range,音频可拖动)、新 `Dockerfile`;加入 60Hz 音频特征数据、字体子集(ZCOOL 庆科黄油体 / 思源黑体 Black / Anton,共约 196KB)。
|
|
|
|
|
|
| 151 |
|
| 152 |
- [x] 步骤 1:克隆仓库,下载 LFS 素材,抽帧,分析画面和音乐 → 写好本 README → **推送**
|
| 153 |
- [x] 步骤 2:删除旧代码,搭好新项目骨架(Vite + React + TS + Dockerfile + 静态服务器 + 音频特征数据)→ **推送**
|
| 154 |
+
- [x] 步骤 3:渲染引擎 + 全部 9 个场景 + WebGL 后期 + 播放器(横屏 / 竖屏)→ **推送**
|
| 155 |
- [ ] 步骤 4:浏览器本地 MP4 导出(24/30/60fps,横 / 竖屏,多分辨率)→ **推送**
|
| 156 |
- [ ] 步骤 5:平台文案(小红书 / 抖音 / 视频号 / B 站)+ 多比例多款封面,可多选下载 → **推送**
|
| 157 |
- [ ] 步骤 6:整体打磨、移动端测试、构建验证、Space 运行检查 → **最终推送**
|
|
|
|
| 162 |
|
| 163 |
- **步骤 1** ✅ 素材下载与分析完成(211 张截图、调色板 / 亮度 / 平涂率统计、BPM 105.5、Drop 位置 38.2s / 109.4s),计划已写入 README。
|
| 164 |
- **步骤 2** ✅ 删除旧 `Dockerfile`(kvideo 镜像),新建 Vite + React + TS 项目骨架:`package.json`、`vite.config.ts`、`index.html`、零依赖静态服务器 `server.mjs`(支持 Range,音频可拖动)、新 `Dockerfile`;加入 60Hz 音频特征数据、字体子集(ZCOOL 庆科黄油体 / 思源黑体 Black / Anton,共约 196KB)。
|
| 165 |
+
- **步骤 3** ✅ 渲染引擎完成:9 个场景(霓虹点亮 / 雨夜长街 / 隧道 / Drop1 四种快切镜头 / 红月天台 / 葱姜蒜夜市 / 心跳暗场 / 飙车光轨 / 粒子汇聚终章)、程序化「夜行者」角色、雨丝与积水倒影、WebGL 后期(辉光 / 色差 / 故障 / 青橙调色 / 颗粒 / 扫描线 / 暗角)、原创字幕;播放器支持横屏 16:9 / 竖屏 9:16、拖动进度、分镜跳转、全屏。已用无头浏览器逐场景截图检查亮度与构图。
|
src/mv/MvApp.tsx
ADDED
|
@@ -0,0 +1,671 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
+
import { zipSync } from 'fflate'
|
| 3 |
+
import './styles.css'
|
| 4 |
+
import { DURATION } from './engine/audio'
|
| 5 |
+
import { Renderer } from './engine/renderer'
|
| 6 |
+
import { SCENES, sceneAt } from './engine/timeline'
|
| 7 |
+
import { AUDIO_URL, loadFonts } from './fonts'
|
| 8 |
+
import { exportMp4, webCodecsSupported, type ExportResult } from './export/exportMp4'
|
| 9 |
+
import { DESIGNS, RATIOS, RATIO_SIZE, renderCover, type CoverItem, type Ratio } from './covers/covers'
|
| 10 |
+
import { PLATFORMS, countChars, formatTags } from './copy/platforms'
|
| 11 |
+
|
| 12 |
+
type Orient = 'landscape' | 'portrait'
|
| 13 |
+
|
| 14 |
+
const fmt = (t: number) => {
|
| 15 |
+
const m = Math.floor(t / 60)
|
| 16 |
+
const s = Math.floor(t % 60)
|
| 17 |
+
return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
function useToast() {
|
| 21 |
+
const [msg, setMsg] = useState<string | null>(null)
|
| 22 |
+
const timer = useRef<number>(0)
|
| 23 |
+
const show = useCallback((m: string) => {
|
| 24 |
+
setMsg(m)
|
| 25 |
+
window.clearTimeout(timer.current)
|
| 26 |
+
timer.current = window.setTimeout(() => setMsg(null), 1600)
|
| 27 |
+
}, [])
|
| 28 |
+
return { msg, show }
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
async function copyText(text: string): Promise<boolean> {
|
| 32 |
+
try {
|
| 33 |
+
await navigator.clipboard.writeText(text)
|
| 34 |
+
return true
|
| 35 |
+
} catch {
|
| 36 |
+
const ta = document.createElement('textarea')
|
| 37 |
+
ta.value = text
|
| 38 |
+
ta.style.position = 'fixed'
|
| 39 |
+
ta.style.opacity = '0'
|
| 40 |
+
document.body.appendChild(ta)
|
| 41 |
+
ta.select()
|
| 42 |
+
let ok = false
|
| 43 |
+
try {
|
| 44 |
+
ok = document.execCommand('copy')
|
| 45 |
+
} catch {
|
| 46 |
+
ok = false
|
| 47 |
+
}
|
| 48 |
+
document.body.removeChild(ta)
|
| 49 |
+
return ok
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function download(url: string, name: string) {
|
| 54 |
+
const a = document.createElement('a')
|
| 55 |
+
a.href = url
|
| 56 |
+
a.download = name
|
| 57 |
+
document.body.appendChild(a)
|
| 58 |
+
a.click()
|
| 59 |
+
a.remove()
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// ====================================================================== App
|
| 63 |
+
export default function MvApp() {
|
| 64 |
+
const [ready, setReady] = useState(false)
|
| 65 |
+
const [orient, setOrient] = useState<Orient>(() => (typeof window !== 'undefined' && window.innerHeight > window.innerWidth ? 'portrait' : 'landscape'))
|
| 66 |
+
const toast = useToast()
|
| 67 |
+
useEffect(() => {
|
| 68 |
+
loadFonts().then(() => setReady(true))
|
| 69 |
+
// debug / QA hook: render a single frame offscreen
|
| 70 |
+
;(window as unknown as { __mvSnap: unknown }).__mvSnap = async (t: number, w: number, h: number) => {
|
| 71 |
+
await loadFonts()
|
| 72 |
+
const r = new Renderer()
|
| 73 |
+
r.setSize(w, h)
|
| 74 |
+
const t0 = performance.now()
|
| 75 |
+
r.render(t)
|
| 76 |
+
const ms = performance.now() - t0
|
| 77 |
+
return { url: r.out.toDataURL('image/jpeg', 0.85), ms, webgl: r.webgl }
|
| 78 |
+
}
|
| 79 |
+
;(window as unknown as { __mvExport: unknown }).__mvExport = exportMp4
|
| 80 |
+
}, [])
|
| 81 |
+
return (
|
| 82 |
+
<div className="mv-root">
|
| 83 |
+
<header className="mv-header">
|
| 84 |
+
<div className="mv-brand">
|
| 85 |
+
<span className="mv-logo">黑街</span>
|
| 86 |
+
<div>
|
| 87 |
+
<div className="mv-brand-en">BLACK STREET · MV</div>
|
| 88 |
+
<div className="mv-brand-sub">DJ鐘董《黑街》DJ葱姜蒜进行曲 · 浏览器实时渲染</div>
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
<nav className="mv-nav">
|
| 92 |
+
<a href="#player">播放</a>
|
| 93 |
+
<a href="#export">导出</a>
|
| 94 |
+
<a href="#copy">文案</a>
|
| 95 |
+
<a href="#covers">封面</a>
|
| 96 |
+
</nav>
|
| 97 |
+
</header>
|
| 98 |
+
<Player ready={ready} orient={orient} setOrient={setOrient} />
|
| 99 |
+
<ExportPanel orient={orient} ready={ready} />
|
| 100 |
+
<CopyPanel toast={toast.show} />
|
| 101 |
+
<CoverPanel ready={ready} toast={toast.show} />
|
| 102 |
+
<footer className="mv-footer">
|
| 103 |
+
画面为原创程序化动画(Canvas 2D + WebGL),所有渲染、导出都在你的浏览器本地完成,不上传任何数据。
|
| 104 |
+
<br />
|
| 105 |
+
音乐版权归原作者 DJ鐘董 所有。
|
| 106 |
+
</footer>
|
| 107 |
+
{toast.msg && <div className="mv-toast">{toast.msg}</div>}
|
| 108 |
+
</div>
|
| 109 |
+
)
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// ====================================================================== Player
|
| 113 |
+
function Player({ ready, orient, setOrient }: { ready: boolean; orient: Orient; setOrient: (o: Orient) => void }) {
|
| 114 |
+
const canvasRef = useRef<HTMLCanvasElement>(null)
|
| 115 |
+
const audioRef = useRef<HTMLAudioElement>(null)
|
| 116 |
+
const wrapRef = useRef<HTMLDivElement>(null)
|
| 117 |
+
const rendererRef = useRef<Renderer | null>(null)
|
| 118 |
+
const tRef = useRef(0)
|
| 119 |
+
const dirty = useRef(true)
|
| 120 |
+
const [playing, setPlaying] = useState(false)
|
| 121 |
+
const [time, setTime] = useState(0)
|
| 122 |
+
const [theater, setTheater] = useState(false)
|
| 123 |
+
const [started, setStarted] = useState(false)
|
| 124 |
+
const [fps, setFps] = useState(0)
|
| 125 |
+
|
| 126 |
+
useEffect(() => {
|
| 127 |
+
if (!canvasRef.current) return
|
| 128 |
+
rendererRef.current = new Renderer(canvasRef.current)
|
| 129 |
+
}, [])
|
| 130 |
+
|
| 131 |
+
useEffect(() => {
|
| 132 |
+
const r = rendererRef.current
|
| 133 |
+
if (!r) return
|
| 134 |
+
const hi = window.devicePixelRatio > 1.5 && Math.max(window.innerWidth, window.innerHeight) > 1100
|
| 135 |
+
const [w, h] = hi ? [1600, 900] : [1280, 720]
|
| 136 |
+
if (orient === 'landscape') r.setSize(w, h)
|
| 137 |
+
else r.setSize(h, w)
|
| 138 |
+
dirty.current = true
|
| 139 |
+
}, [orient])
|
| 140 |
+
|
| 141 |
+
useEffect(() => {
|
| 142 |
+
if (ready) dirty.current = true
|
| 143 |
+
}, [ready])
|
| 144 |
+
|
| 145 |
+
useEffect(() => {
|
| 146 |
+
let raf = 0
|
| 147 |
+
let last = performance.now()
|
| 148 |
+
let frames = 0
|
| 149 |
+
let lastUi = 0
|
| 150 |
+
const loop = (now: number) => {
|
| 151 |
+
raf = requestAnimationFrame(loop)
|
| 152 |
+
const a = audioRef.current
|
| 153 |
+
const r = rendererRef.current
|
| 154 |
+
if (!r || !a) return
|
| 155 |
+
const isPlaying = !a.paused && !a.ended
|
| 156 |
+
if (isPlaying) {
|
| 157 |
+
tRef.current = a.currentTime
|
| 158 |
+
dirty.current = true
|
| 159 |
+
}
|
| 160 |
+
if (dirty.current) {
|
| 161 |
+
r.render(tRef.current)
|
| 162 |
+
dirty.current = false
|
| 163 |
+
frames++
|
| 164 |
+
}
|
| 165 |
+
if (now - lastUi > 120) {
|
| 166 |
+
setTime(tRef.current)
|
| 167 |
+
lastUi = now
|
| 168 |
+
}
|
| 169 |
+
if (now - last > 1000) {
|
| 170 |
+
setFps(isPlaying ? Math.round((frames * 1000) / (now - last)) : 0)
|
| 171 |
+
frames = 0
|
| 172 |
+
last = now
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
raf = requestAnimationFrame(loop)
|
| 176 |
+
return () => cancelAnimationFrame(raf)
|
| 177 |
+
}, [])
|
| 178 |
+
|
| 179 |
+
const toggle = useCallback(() => {
|
| 180 |
+
const a = audioRef.current
|
| 181 |
+
if (!a) return
|
| 182 |
+
setStarted(true)
|
| 183 |
+
if (a.paused) {
|
| 184 |
+
if (a.ended || a.currentTime >= DURATION - 0.05) a.currentTime = 0
|
| 185 |
+
a.play().catch(() => {})
|
| 186 |
+
} else a.pause()
|
| 187 |
+
}, [])
|
| 188 |
+
|
| 189 |
+
const seek = useCallback((t: number) => {
|
| 190 |
+
const a = audioRef.current
|
| 191 |
+
const v = Math.max(0, Math.min(DURATION, t))
|
| 192 |
+
tRef.current = v
|
| 193 |
+
if (a) a.currentTime = v
|
| 194 |
+
dirty.current = true
|
| 195 |
+
setTime(v)
|
| 196 |
+
}, [])
|
| 197 |
+
|
| 198 |
+
useEffect(() => {
|
| 199 |
+
const onKey = (e: KeyboardEvent) => {
|
| 200 |
+
if ((e.target as HTMLElement)?.closest('input,textarea')) return
|
| 201 |
+
if (e.code === 'Space') {
|
| 202 |
+
e.preventDefault()
|
| 203 |
+
toggle()
|
| 204 |
+
} else if (e.code === 'ArrowRight') seek(tRef.current + 5)
|
| 205 |
+
else if (e.code === 'ArrowLeft') seek(tRef.current - 5)
|
| 206 |
+
else if (e.code === 'Escape') setTheater(false)
|
| 207 |
+
}
|
| 208 |
+
window.addEventListener('keydown', onKey)
|
| 209 |
+
return () => window.removeEventListener('keydown', onKey)
|
| 210 |
+
}, [toggle, seek])
|
| 211 |
+
|
| 212 |
+
const fullscreen = () => {
|
| 213 |
+
const el = wrapRef.current as (HTMLDivElement & { webkitRequestFullscreen?: () => void }) | null
|
| 214 |
+
if (!el) return
|
| 215 |
+
if (document.fullscreenElement) {
|
| 216 |
+
document.exitFullscreen().catch(() => {})
|
| 217 |
+
return
|
| 218 |
+
}
|
| 219 |
+
if (el.requestFullscreen) el.requestFullscreen().catch(() => setTheater(true))
|
| 220 |
+
else if (el.webkitRequestFullscreen) el.webkitRequestFullscreen()
|
| 221 |
+
else setTheater(true)
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
const scene = sceneAt(time)
|
| 225 |
+
return (
|
| 226 |
+
<section id="player" className="mv-section">
|
| 227 |
+
<div className="mv-player-head">
|
| 228 |
+
<h2>
|
| 229 |
+
<span className="mv-h-idx">01</span> 在线观看
|
| 230 |
+
</h2>
|
| 231 |
+
<div className="mv-seg">
|
| 232 |
+
<button className={orient === 'landscape' ? 'on' : ''} onClick={() => setOrient('landscape')}>
|
| 233 |
+
横屏 16:9
|
| 234 |
+
</button>
|
| 235 |
+
<button className={orient === 'portrait' ? 'on' : ''} onClick={() => setOrient('portrait')}>
|
| 236 |
+
竖屏 9:16
|
| 237 |
+
</button>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
<div ref={wrapRef} className={`mv-stage-wrap ${orient} ${theater ? 'theater' : ''}`}>
|
| 241 |
+
<div className={`mv-stage ${orient}`} onClick={toggle}>
|
| 242 |
+
<canvas ref={canvasRef} className="mv-canvas" />
|
| 243 |
+
{!playing && (
|
| 244 |
+
<button className="mv-bigplay" aria-label="播放">
|
| 245 |
+
<svg viewBox="0 0 24 24" width="38" height="38">
|
| 246 |
+
<path d="M8 5v14l11-7z" fill="currentColor" />
|
| 247 |
+
</svg>
|
| 248 |
+
{!started && <span>{ready ? '点击播放(建议戴耳机)' : '加载字体中…'}</span>}
|
| 249 |
+
</button>
|
| 250 |
+
)}
|
| 251 |
+
<div className="mv-scene-tag" style={{ borderColor: scene.color }}>
|
| 252 |
+
{scene.name}
|
| 253 |
+
</div>
|
| 254 |
+
</div>
|
| 255 |
+
<div className="mv-controls">
|
| 256 |
+
<button className="mv-ctrl" onClick={toggle} aria-label={playing ? '暂停' : '播放'}>
|
| 257 |
+
{playing ? (
|
| 258 |
+
<svg viewBox="0 0 24 24" width="22" height="22">
|
| 259 |
+
<path d="M6 5h4v14H6zM14 5h4v14h-4z" fill="currentColor" />
|
| 260 |
+
</svg>
|
| 261 |
+
) : (
|
| 262 |
+
<svg viewBox="0 0 24 24" width="22" height="22">
|
| 263 |
+
<path d="M8 5v14l11-7z" fill="currentColor" />
|
| 264 |
+
</svg>
|
| 265 |
+
)}
|
| 266 |
+
</button>
|
| 267 |
+
<span className="mv-time">
|
| 268 |
+
{fmt(time)} / {fmt(DURATION)}
|
| 269 |
+
</span>
|
| 270 |
+
<div className="mv-track">
|
| 271 |
+
<div className="mv-track-segs">
|
| 272 |
+
{SCENES.map((s) => (
|
| 273 |
+
<div key={s.id} className="mv-track-seg" style={{ width: `${((s.end - s.start) / DURATION) * 100}%`, background: s.color }} title={s.name} />
|
| 274 |
+
))}
|
| 275 |
+
</div>
|
| 276 |
+
<div className="mv-track-fill" style={{ width: `${(time / DURATION) * 100}%` }} />
|
| 277 |
+
<input type="range" min={0} max={DURATION} step={0.01} value={time} onChange={(e) => seek(parseFloat(e.target.value))} aria-label="进度" />
|
| 278 |
+
</div>
|
| 279 |
+
<span className="mv-fps">{fps ? `${fps} fps` : ''}</span>
|
| 280 |
+
<button className="mv-ctrl" onClick={fullscreen} aria-label="全屏">
|
| 281 |
+
<svg viewBox="0 0 24 24" width="20" height="20">
|
| 282 |
+
<path d="M4 9V4h5v2H6v3zm10-5h6v5h-2V6h-4zM4 15h2v3h3v2H4zm14 3v-3h2v5h-6v-2z" fill="currentColor" />
|
| 283 |
+
</svg>
|
| 284 |
+
</button>
|
| 285 |
+
{theater && (
|
| 286 |
+
<button className="mv-ctrl" onClick={() => setTheater(false)}>
|
| 287 |
+
✕
|
| 288 |
+
</button>
|
| 289 |
+
)}
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
<div className="mv-chips">
|
| 293 |
+
{SCENES.map((s, i) => (
|
| 294 |
+
<button key={s.id} className={`mv-chip ${scene.id === s.id ? 'on' : ''}`} onClick={() => seek(s.start + 0.02)}>
|
| 295 |
+
<i style={{ background: s.color }} />
|
| 296 |
+
<b>{String(i + 1).padStart(2, '0')}</b> {s.name}
|
| 297 |
+
<em>{fmt(s.start)}</em>
|
| 298 |
+
</button>
|
| 299 |
+
))}
|
| 300 |
+
</div>
|
| 301 |
+
<audio
|
| 302 |
+
ref={audioRef}
|
| 303 |
+
src={AUDIO_URL}
|
| 304 |
+
preload="auto"
|
| 305 |
+
onPlay={() => setPlaying(true)}
|
| 306 |
+
onPause={() => setPlaying(false)}
|
| 307 |
+
onEnded={() => {
|
| 308 |
+
setPlaying(false)
|
| 309 |
+
dirty.current = true
|
| 310 |
+
}}
|
| 311 |
+
/>
|
| 312 |
+
</section>
|
| 313 |
+
)
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
// ====================================================================== Export
|
| 317 |
+
function ExportPanel({ orient, ready }: { orient: Orient; ready: boolean }) {
|
| 318 |
+
const [o, setO] = useState<Orient>(orient)
|
| 319 |
+
const [res, setRes] = useState<'1080' | '720'>('1080')
|
| 320 |
+
const [fps, setFps] = useState<24 | 30 | 60>(30)
|
| 321 |
+
const [state, setState] = useState<'idle' | 'running' | 'done' | 'error'>('idle')
|
| 322 |
+
const [prog, setProg] = useState({ stage: '', progress: 0, eta: 0, frame: 0, total: 0 })
|
| 323 |
+
const [result, setResult] = useState<(ExportResult & { url: string; name: string }) | null>(null)
|
| 324 |
+
const [err, setErr] = useState('')
|
| 325 |
+
const ctrl = useRef<AbortController | null>(null)
|
| 326 |
+
useEffect(() => setO(orient), [orient])
|
| 327 |
+
const supported = useMemo(() => (typeof window !== 'undefined' ? webCodecsSupported() : true), [])
|
| 328 |
+
|
| 329 |
+
const size = useMemo(() => {
|
| 330 |
+
const [a, b] = res === '1080' ? [1920, 1080] : [1280, 720]
|
| 331 |
+
return o === 'landscape' ? [a, b] : [b, a]
|
| 332 |
+
}, [o, res])
|
| 333 |
+
|
| 334 |
+
const start = async () => {
|
| 335 |
+
if (!ready) return
|
| 336 |
+
ctrl.current = new AbortController()
|
| 337 |
+
setState('running')
|
| 338 |
+
setErr('')
|
| 339 |
+
if (result) URL.revokeObjectURL(result.url)
|
| 340 |
+
setResult(null)
|
| 341 |
+
try {
|
| 342 |
+
const r = await exportMp4({
|
| 343 |
+
width: size[0],
|
| 344 |
+
height: size[1],
|
| 345 |
+
fps,
|
| 346 |
+
signal: ctrl.current.signal,
|
| 347 |
+
onProgress: (p) => setProg((prev) => ({ ...prev, ...p, eta: p.eta ?? prev.eta, frame: p.frame ?? prev.frame, total: p.total ?? prev.total })),
|
| 348 |
+
})
|
| 349 |
+
const url = URL.createObjectURL(r.blob)
|
| 350 |
+
const name = `黑街_BLACK-STREET_${size[0]}x${size[1]}_${fps}fps.${r.ext}`
|
| 351 |
+
setResult({ ...r, url, name })
|
| 352 |
+
setState('done')
|
| 353 |
+
download(url, name)
|
| 354 |
+
} catch (e) {
|
| 355 |
+
if ((e as Error).name === 'AbortError') setState('idle')
|
| 356 |
+
else {
|
| 357 |
+
setErr((e as Error).message || String(e))
|
| 358 |
+
setState('error')
|
| 359 |
+
}
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
const frames = Math.ceil(DURATION * fps)
|
| 363 |
+
return (
|
| 364 |
+
<section id="export" className="mv-section">
|
| 365 |
+
<h2>
|
| 366 |
+
<span className="mv-h-idx">02</span> 导出 MP4 <small>浏览器本地渲染 · 不上传</small>
|
| 367 |
+
</h2>
|
| 368 |
+
<div className="mv-card mv-export">
|
| 369 |
+
<div className="mv-opt">
|
| 370 |
+
<label>画面方向</label>
|
| 371 |
+
<div className="mv-seg">
|
| 372 |
+
<button className={o === 'landscape' ? 'on' : ''} onClick={() => setO('landscape')} disabled={state === 'running'}>
|
| 373 |
+
横屏 16:9
|
| 374 |
+
</button>
|
| 375 |
+
<button className={o === 'portrait' ? 'on' : ''} onClick={() => setO('portrait')} disabled={state === 'running'}>
|
| 376 |
+
竖屏 9:16(手机)
|
| 377 |
+
</button>
|
| 378 |
+
</div>
|
| 379 |
+
</div>
|
| 380 |
+
<div className="mv-opt">
|
| 381 |
+
<label>分辨率</label>
|
| 382 |
+
<div className="mv-seg">
|
| 383 |
+
<button className={res === '1080' ? 'on' : ''} onClick={() => setRes('1080')} disabled={state === 'running'}>
|
| 384 |
+
1080P
|
| 385 |
+
</button>
|
| 386 |
+
<button className={res === '720' ? 'on' : ''} onClick={() => setRes('720')} disabled={state === 'running'}>
|
| 387 |
+
720P(更快)
|
| 388 |
+
</button>
|
| 389 |
+
</div>
|
| 390 |
+
</div>
|
| 391 |
+
<div className="mv-opt">
|
| 392 |
+
<label>帧率</label>
|
| 393 |
+
<div className="mv-seg">
|
| 394 |
+
{([24, 30, 60] as const).map((f) => (
|
| 395 |
+
<button key={f} className={fps === f ? 'on' : ''} onClick={() => setFps(f)} disabled={state === 'running'}>
|
| 396 |
+
{f} fps
|
| 397 |
+
</button>
|
| 398 |
+
))}
|
| 399 |
+
</div>
|
| 400 |
+
</div>
|
| 401 |
+
<div className="mv-export-meta">
|
| 402 |
+
输出:{size[0]}×{size[1]} · {fps}fps · H.264 + AAC · 共 {frames.toLocaleString()} 帧 · 时长 {fmt(DURATION)}
|
| 403 |
+
{!supported && <div className="mv-warn">当前浏览器不支持 WebCodecs 快速编码,将使用实时录制(需要约 2.5 分钟)。推荐使用最新版 Chrome / Edge。</div>}
|
| 404 |
+
</div>
|
| 405 |
+
{state !== 'running' ? (
|
| 406 |
+
<button className="mv-primary" onClick={start} disabled={!ready}>
|
| 407 |
+
{ready ? '开始导出 MP4' : '准备中…'}
|
| 408 |
+
</button>
|
| 409 |
+
) : (
|
| 410 |
+
<div className="mv-progress">
|
| 411 |
+
<div className="mv-progress-bar">
|
| 412 |
+
<div style={{ width: `${(prog.progress * 100).toFixed(1)}%` }} />
|
| 413 |
+
</div>
|
| 414 |
+
<div className="mv-progress-info">
|
| 415 |
+
<span>
|
| 416 |
+
{prog.stage} {(prog.progress * 100).toFixed(1)}%
|
| 417 |
+
{prog.total ? ` · ${prog.frame}/${prog.total} 帧` : ''}
|
| 418 |
+
</span>
|
| 419 |
+
<span>{prog.eta ? `预计剩余 ${fmt(prog.eta)}` : ''}</span>
|
| 420 |
+
</div>
|
| 421 |
+
<button className="mv-ghost" onClick={() => ctrl.current?.abort()}>
|
| 422 |
+
取消
|
| 423 |
+
</button>
|
| 424 |
+
<p className="mv-hint">导出期间请保持本页面在前台,切到后台会变慢。</p>
|
| 425 |
+
</div>
|
| 426 |
+
)}
|
| 427 |
+
{state === 'error' && <div className="mv-warn">导出失败:{err}</div>}
|
| 428 |
+
{state === 'done' && result && (
|
| 429 |
+
<div className="mv-result">
|
| 430 |
+
<video src={result.url} controls playsInline className={o} />
|
| 431 |
+
<div>
|
| 432 |
+
<a className="mv-primary" href={result.url} download={result.name}>
|
| 433 |
+
再次下载 {result.ext.toUpperCase()}({(result.blob.size / 1024 / 1024).toFixed(1)} MB)
|
| 434 |
+
</a>
|
| 435 |
+
{result.note && <p className="mv-hint">{result.note}</p>}
|
| 436 |
+
</div>
|
| 437 |
+
</div>
|
| 438 |
+
)}
|
| 439 |
+
</div>
|
| 440 |
+
</section>
|
| 441 |
+
)
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
// ====================================================================== Copy
|
| 445 |
+
function CopyPanel({ toast }: { toast: (m: string) => void }) {
|
| 446 |
+
const [pid, setPid] = useState(PLATFORMS[0].id)
|
| 447 |
+
const p = PLATFORMS.find((x) => x.id === pid)!
|
| 448 |
+
const [titles, setTitles] = useState<Record<string, string>>(() => Object.fromEntries(PLATFORMS.map((x) => [x.id, x.titles[0]])))
|
| 449 |
+
const [descs, setDescs] = useState<Record<string, string>>(() => Object.fromEntries(PLATFORMS.map((x) => [x.id, x.desc])))
|
| 450 |
+
const [tags, setTags] = useState<Record<string, string[]>>(() => Object.fromEntries(PLATFORMS.map((x) => [x.id, [...x.tags]])))
|
| 451 |
+
const [newTag, setNewTag] = useState('')
|
| 452 |
+
const title = titles[pid]
|
| 453 |
+
const tcount = countChars(title)
|
| 454 |
+
const myTags = tags[pid]
|
| 455 |
+
const allTags = useMemo(() => Array.from(new Set([...p.tags, ...myTags])), [p, myTags])
|
| 456 |
+
const overTitle = tcount > p.titleLimit
|
| 457 |
+
const overTags = p.tagLimit != null && myTags.length > p.tagLimit
|
| 458 |
+
const doCopy = async (text: string, what: string) => {
|
| 459 |
+
const ok = await copyText(text)
|
| 460 |
+
toast(ok ? `已复制${what}` : '复制失败,请手动选择文本')
|
| 461 |
+
}
|
| 462 |
+
const toggleTag = (t: string) => setTags((prev) => ({ ...prev, [pid]: prev[pid].includes(t) ? prev[pid].filter((x) => x !== t) : [...prev[pid], t] }))
|
| 463 |
+
const addTag = () => {
|
| 464 |
+
const t = newTag.replace(/^#/, '').trim()
|
| 465 |
+
if (!t) return
|
| 466 |
+
setTags((prev) => ({ ...prev, [pid]: prev[pid].includes(t) ? prev[pid] : [...prev[pid], t] }))
|
| 467 |
+
setNewTag('')
|
| 468 |
+
}
|
| 469 |
+
const tagText = formatTags(p, myTags)
|
| 470 |
+
return (
|
| 471 |
+
<section id="copy" className="mv-section">
|
| 472 |
+
<h2>
|
| 473 |
+
<span className="mv-h-idx">03</span> 发布文案 <small>标题 · 描述 · 话题,一键复制</small>
|
| 474 |
+
</h2>
|
| 475 |
+
<div className="mv-tabs">
|
| 476 |
+
{PLATFORMS.map((x) => (
|
| 477 |
+
<button key={x.id} className={x.id === pid ? 'on' : ''} onClick={() => setPid(x.id)} style={{ ['--pc' as string]: x.color }}>
|
| 478 |
+
{x.name}
|
| 479 |
+
</button>
|
| 480 |
+
))}
|
| 481 |
+
</div>
|
| 482 |
+
<div className="mv-card mv-copy" style={{ ['--pc' as string]: p.color }}>
|
| 483 |
+
<div className="mv-copy-tip">{p.tip}</div>
|
| 484 |
+
<div className="mv-field">
|
| 485 |
+
<div className="mv-field-head">
|
| 486 |
+
<label>标题</label>
|
| 487 |
+
<span className={overTitle ? 'bad' : 'good'}>
|
| 488 |
+
{tcount}/{p.titleLimit} 字
|
| 489 |
+
</span>
|
| 490 |
+
<button className="mv-copybtn" onClick={() => doCopy(title, '标题')}>
|
| 491 |
+
复制标题
|
| 492 |
+
</button>
|
| 493 |
+
</div>
|
| 494 |
+
<input className="mv-input" value={title} onChange={(e) => setTitles((prev) => ({ ...prev, [pid]: e.target.value }))} />
|
| 495 |
+
<div className="mv-alts">
|
| 496 |
+
{p.titles.map((t) => (
|
| 497 |
+
<button key={t} className={t === title ? 'on' : ''} onClick={() => setTitles((prev) => ({ ...prev, [pid]: t }))}>
|
| 498 |
+
{t} <em>{countChars(t)}字</em>
|
| 499 |
+
</button>
|
| 500 |
+
))}
|
| 501 |
+
</div>
|
| 502 |
+
</div>
|
| 503 |
+
<div className="mv-field">
|
| 504 |
+
<div className="mv-field-head">
|
| 505 |
+
<label>描述</label>
|
| 506 |
+
<span className="good">{countChars(descs[pid])} 字</span>
|
| 507 |
+
<button className="mv-copybtn" onClick={() => doCopy(descs[pid], '描述')}>
|
| 508 |
+
复制描述
|
| 509 |
+
</button>
|
| 510 |
+
</div>
|
| 511 |
+
<textarea className="mv-input" rows={p.id === 'bili' ? 12 : 6} value={descs[pid]} onChange={(e) => setDescs((prev) => ({ ...prev, [pid]: e.target.value }))} />
|
| 512 |
+
</div>
|
| 513 |
+
<div className="mv-field">
|
| 514 |
+
<div className="mv-field-head">
|
| 515 |
+
<label>{p.tagStyle === 'comma' ? '标签' : '话题'}</label>
|
| 516 |
+
<span className={overTags ? 'bad' : 'good'}>
|
| 517 |
+
{myTags.length}
|
| 518 |
+
{p.tagLimit != null ? `/${p.tagLimit}` : ''} 个{p.tagLimit == null ? '(不限)' : ''}
|
| 519 |
+
</span>
|
| 520 |
+
<button className="mv-copybtn" onClick={() => doCopy(tagText, p.tagStyle === 'comma' ? '标签' : '话题')}>
|
| 521 |
+
复制{p.tagStyle === 'comma' ? '标签' : '话题'}
|
| 522 |
+
</button>
|
| 523 |
+
</div>
|
| 524 |
+
<div className="mv-tags">
|
| 525 |
+
{allTags.map((t) => (
|
| 526 |
+
<button key={t} className={myTags.includes(t) ? 'on' : ''} onClick={() => toggleTag(t)}>
|
| 527 |
+
#{t}
|
| 528 |
+
</button>
|
| 529 |
+
))}
|
| 530 |
+
<span className="mv-addtag">
|
| 531 |
+
<input value={newTag} placeholder="添加话题" onChange={(e) => setNewTag(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && addTag()} />
|
| 532 |
+
<button onClick={addTag}>+</button>
|
| 533 |
+
</span>
|
| 534 |
+
</div>
|
| 535 |
+
<pre className="mv-tagtext">{tagText}</pre>
|
| 536 |
+
</div>
|
| 537 |
+
<button className="mv-primary" onClick={() => doCopy(`${title}\n\n${descs[pid]}\n\n${tagText}`, '全部内容')}>
|
| 538 |
+
一键复制全部({p.name})
|
| 539 |
+
</button>
|
| 540 |
+
{(overTitle || overTags) && <div className="mv-warn">有内容超出 {p.name} 的限制,请调整后再发布。</div>}
|
| 541 |
+
</div>
|
| 542 |
+
</section>
|
| 543 |
+
)
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
// ====================================================================== Covers
|
| 547 |
+
function CoverPanel({ ready, toast }: { ready: boolean; toast: (m: string) => void }) {
|
| 548 |
+
const [items, setItems] = useState<CoverItem[]>([])
|
| 549 |
+
const [sel, setSel] = useState<Set<string>>(new Set())
|
| 550 |
+
const [filter, setFilter] = useState<Ratio | 'all'>('all')
|
| 551 |
+
const [busy, setBusy] = useState(false)
|
| 552 |
+
const [view, setView] = useState<CoverItem | null>(null)
|
| 553 |
+
const started = useRef(false)
|
| 554 |
+
useEffect(() => {
|
| 555 |
+
if (!ready || started.current) return
|
| 556 |
+
started.current = true
|
| 557 |
+
let cancelled = false
|
| 558 |
+
;(async () => {
|
| 559 |
+
setBusy(true)
|
| 560 |
+
for (const ratio of RATIOS) {
|
| 561 |
+
for (const d of DESIGNS) {
|
| 562 |
+
if (cancelled) return
|
| 563 |
+
await new Promise((r) => setTimeout(r, 30))
|
| 564 |
+
try {
|
| 565 |
+
const it = await renderCover(ratio, d)
|
| 566 |
+
setItems((prev) => [...prev, it])
|
| 567 |
+
} catch (e) {
|
| 568 |
+
console.warn('cover failed', e)
|
| 569 |
+
}
|
| 570 |
+
}
|
| 571 |
+
}
|
| 572 |
+
setBusy(false)
|
| 573 |
+
})()
|
| 574 |
+
return () => {
|
| 575 |
+
cancelled = true
|
| 576 |
+
}
|
| 577 |
+
}, [ready])
|
| 578 |
+
const shown = items.filter((i) => filter === 'all' || i.ratio === filter)
|
| 579 |
+
const toggle = (k: string) =>
|
| 580 |
+
setSel((prev) => {
|
| 581 |
+
const n = new Set(prev)
|
| 582 |
+
if (n.has(k)) n.delete(k)
|
| 583 |
+
else n.add(k)
|
| 584 |
+
return n
|
| 585 |
+
})
|
| 586 |
+
const selected = items.filter((i) => sel.has(i.key))
|
| 587 |
+
const fileName = (i: CoverItem) => `黑街封面_${i.ratio.replace(':', 'x')}_${i.design.name}_${i.width}x${i.height}.jpg`
|
| 588 |
+
const downloadSel = async () => {
|
| 589 |
+
for (const i of selected) {
|
| 590 |
+
download(i.url, fileName(i))
|
| 591 |
+
await new Promise((r) => setTimeout(r, 350))
|
| 592 |
+
}
|
| 593 |
+
toast(`已下载 ${selected.length} 张封面`)
|
| 594 |
+
}
|
| 595 |
+
const zipSel = async () => {
|
| 596 |
+
const files: Record<string, Uint8Array> = {}
|
| 597 |
+
for (const i of selected) files[fileName(i)] = new Uint8Array(await i.blob.arrayBuffer())
|
| 598 |
+
const z = zipSync(files, { level: 0 })
|
| 599 |
+
const url = URL.createObjectURL(new Blob([z], { type: 'application/zip' }))
|
| 600 |
+
download(url, `黑街封面_${selected.length}张.zip`)
|
| 601 |
+
setTimeout(() => URL.revokeObjectURL(url), 5000)
|
| 602 |
+
toast('ZIP 已生成')
|
| 603 |
+
}
|
| 604 |
+
return (
|
| 605 |
+
<section id="covers" className="mv-section">
|
| 606 |
+
<h2>
|
| 607 |
+
<span className="mv-h-idx">04</span> 封面 <small>16:9 · 4:3 · 3:4 · 每种比例 {DESIGNS.length} 款,可多选</small>
|
| 608 |
+
</h2>
|
| 609 |
+
<div className="mv-cover-bar">
|
| 610 |
+
<div className="mv-seg">
|
| 611 |
+
{(['all', ...RATIOS] as const).map((r) => (
|
| 612 |
+
<button key={r} className={filter === r ? 'on' : ''} onClick={() => setFilter(r)}>
|
| 613 |
+
{r === 'all' ? '全部' : `${r}(${RATIO_SIZE[r].join('×')})`}
|
| 614 |
+
</button>
|
| 615 |
+
))}
|
| 616 |
+
</div>
|
| 617 |
+
<div className="mv-cover-actions">
|
| 618 |
+
<button className="mv-ghost" onClick={() => setSel(new Set([...sel, ...shown.map((i) => i.key)]))}>
|
| 619 |
+
全选{filter === 'all' ? '' : ' ' + filter}
|
| 620 |
+
</button>
|
| 621 |
+
<button className="mv-ghost" onClick={() => setSel(new Set())}>
|
| 622 |
+
清空
|
| 623 |
+
</button>
|
| 624 |
+
<button className="mv-primary sm" disabled={!selected.length} onClick={downloadSel}>
|
| 625 |
+
下载选中({selected.length})
|
| 626 |
+
</button>
|
| 627 |
+
<button className="mv-primary sm alt" disabled={!selected.length} onClick={zipSel}>
|
| 628 |
+
打包 ZIP
|
| 629 |
+
</button>
|
| 630 |
+
</div>
|
| 631 |
+
</div>
|
| 632 |
+
{busy && <div className="mv-hint">正在生成封面… {items.length}/{RATIOS.length * DESIGNS.length}</div>}
|
| 633 |
+
<div className="mv-cover-grid">
|
| 634 |
+
{shown.map((i) => (
|
| 635 |
+
<div key={i.key} className={`mv-cover ${sel.has(i.key) ? 'on' : ''} r${i.ratio.replace(':', '')}`} onClick={() => toggle(i.key)}>
|
| 636 |
+
<img src={i.url} alt={i.design.name} loading="lazy" />
|
| 637 |
+
<div className="mv-cover-check">{sel.has(i.key) ? '✓' : ''}</div>
|
| 638 |
+
<div className="mv-cover-meta">
|
| 639 |
+
<b>{i.design.name}</b>
|
| 640 |
+
<span>{i.ratio}</span>
|
| 641 |
+
<button
|
| 642 |
+
onClick={(e) => {
|
| 643 |
+
e.stopPropagation()
|
| 644 |
+
setView(i)
|
| 645 |
+
}}
|
| 646 |
+
>
|
| 647 |
+
大图
|
| 648 |
+
</button>
|
| 649 |
+
</div>
|
| 650 |
+
</div>
|
| 651 |
+
))}
|
| 652 |
+
</div>
|
| 653 |
+
{view && (
|
| 654 |
+
<div className="mv-lightbox" onClick={() => setView(null)}>
|
| 655 |
+
<img src={view.url} alt={view.design.name} />
|
| 656 |
+
<div className="mv-lightbox-bar" onClick={(e) => e.stopPropagation()}>
|
| 657 |
+
<span>
|
| 658 |
+
{view.design.name} · {view.ratio} · {view.width}×{view.height}
|
| 659 |
+
</span>
|
| 660 |
+
<button className="mv-primary sm" onClick={() => download(view.url, fileName(view))}>
|
| 661 |
+
下载
|
| 662 |
+
</button>
|
| 663 |
+
<button className="mv-ghost" onClick={() => setView(null)}>
|
| 664 |
+
关闭
|
| 665 |
+
</button>
|
| 666 |
+
</div>
|
| 667 |
+
</div>
|
| 668 |
+
)}
|
| 669 |
+
</section>
|
| 670 |
+
)
|
| 671 |
+
}
|
src/mv/engine/audio.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import feat from '../audio/features'
|
| 2 |
+
|
| 3 |
+
// Precomputed (offline) audio analysis of 黑街.mp3 at 60 Hz.
|
| 4 |
+
// Using precomputed envelopes makes the animation deterministic: the realtime
|
| 5 |
+
// preview and the frame-by-frame MP4 export see exactly the same values.
|
| 6 |
+
|
| 7 |
+
function decode(b64: string): Float32Array {
|
| 8 |
+
const s = atob(b64)
|
| 9 |
+
const out = new Float32Array(s.length)
|
| 10 |
+
for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i) / 255
|
| 11 |
+
return out
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const RATE = feat.fps
|
| 15 |
+
const LOW = decode(feat.low)
|
| 16 |
+
const MID = decode(feat.mid)
|
| 17 |
+
const HIGH = decode(feat.high)
|
| 18 |
+
const RMS = decode(feat.rms)
|
| 19 |
+
const KICK = decode(feat.kick)
|
| 20 |
+
|
| 21 |
+
export const DURATION = 144.3
|
| 22 |
+
export const BEAT = 60 / 105.47
|
| 23 |
+
export const BAR = BEAT * 4
|
| 24 |
+
export const DROP1 = 38.15
|
| 25 |
+
export const BREAK = 72.95
|
| 26 |
+
export const DROP2 = 109.436
|
| 27 |
+
|
| 28 |
+
function sample(arr: Float32Array, t: number): number {
|
| 29 |
+
const x = t * RATE
|
| 30 |
+
const i = Math.floor(x)
|
| 31 |
+
if (i < 0) return arr[0]
|
| 32 |
+
if (i >= arr.length - 1) return arr[arr.length - 1]
|
| 33 |
+
const f = x - i
|
| 34 |
+
return arr[i] * (1 - f) + arr[i + 1] * f
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/** Kick envelope with fast attack, exponential release (looks punchier). */
|
| 38 |
+
function kickEnv(t: number): number {
|
| 39 |
+
const i = Math.floor(t * RATE)
|
| 40 |
+
let m = 0
|
| 41 |
+
for (let k = 0; k < 14; k++) {
|
| 42 |
+
const j = i - k
|
| 43 |
+
if (j < 0 || j >= KICK.length) continue
|
| 44 |
+
const v = KICK[j] * Math.exp(-k / 4)
|
| 45 |
+
if (v > m) m = v
|
| 46 |
+
}
|
| 47 |
+
return Math.min(1, m * 1.3)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export interface AudioFrame {
|
| 51 |
+
t: number
|
| 52 |
+
low: number
|
| 53 |
+
mid: number
|
| 54 |
+
high: number
|
| 55 |
+
rms: number
|
| 56 |
+
kick: number
|
| 57 |
+
/** continuous beat position (beats since anchor) */
|
| 58 |
+
beatPos: number
|
| 59 |
+
beat: number
|
| 60 |
+
beatPhase: number
|
| 61 |
+
bar: number
|
| 62 |
+
barPhase: number
|
| 63 |
+
/** 1 right on the beat, decays quickly */
|
| 64 |
+
pulse: number
|
| 65 |
+
/** true during Drop 1 / Drop 2 */
|
| 66 |
+
drop: boolean
|
| 67 |
+
/** 0..1 overall energy (smoothed) */
|
| 68 |
+
energy: number
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
export function beatPosAt(t: number): number {
|
| 72 |
+
const anchor = t < (BREAK + DROP2) / 2 ? DROP1 : DROP2
|
| 73 |
+
return (t - anchor) / BEAT
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
export function analyse(t: number): AudioFrame {
|
| 77 |
+
const beatPos = beatPosAt(t)
|
| 78 |
+
const beat = Math.floor(beatPos)
|
| 79 |
+
const beatPhase = beatPos - beat
|
| 80 |
+
const barPos = beatPos / 4
|
| 81 |
+
const bar = Math.floor(barPos)
|
| 82 |
+
const barPhase = barPos - bar
|
| 83 |
+
const drop = (t >= DROP1 && t < BREAK) || t >= DROP2
|
| 84 |
+
const low = sample(LOW, t)
|
| 85 |
+
const rms = sample(RMS, t)
|
| 86 |
+
let energy = 0
|
| 87 |
+
for (let k = 0; k < 6; k++) energy += sample(RMS, t - k * 0.08)
|
| 88 |
+
energy /= 6
|
| 89 |
+
return {
|
| 90 |
+
t,
|
| 91 |
+
low,
|
| 92 |
+
mid: sample(MID, t),
|
| 93 |
+
high: sample(HIGH, t),
|
| 94 |
+
rms,
|
| 95 |
+
kick: kickEnv(t),
|
| 96 |
+
beatPos,
|
| 97 |
+
beat,
|
| 98 |
+
beatPhase,
|
| 99 |
+
bar,
|
| 100 |
+
barPhase,
|
| 101 |
+
pulse: Math.exp(-beatPhase * 7),
|
| 102 |
+
drop,
|
| 103 |
+
energy,
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/** Time (seconds) of a beat index relative to the anchor that governs time t. */
|
| 108 |
+
export function beatTime(t: number, beatIndex: number): number {
|
| 109 |
+
const anchor = t < (BREAK + DROP2) / 2 ? DROP1 : DROP2
|
| 110 |
+
return anchor + beatIndex * BEAT
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
export function bandAt(t: number, which: 'low' | 'mid' | 'high' | 'rms'): number {
|
| 114 |
+
const arr = which === 'low' ? LOW : which === 'mid' ? MID : which === 'high' ? HIGH : RMS
|
| 115 |
+
return sample(arr, t)
|
| 116 |
+
}
|
src/mv/engine/draw.ts
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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'./util'
|
| 2 |
+
|
| 3 |
+
type C2D = CanvasRenderingContext2D
|
| 4 |
+
|
| 5 |
+
// ---------------------------------------------------------------- sky / fog
|
| 6 |
+
export function vGradient(ctx: C2D, x: number, y: number, w: number, h: number, stops: [number, string][]) {
|
| 7 |
+
const g = ctx.createLinearGradient(0, y, 0, y + h)
|
| 8 |
+
for (const [o, c] of stops) g.addColorStop(o, c)
|
| 9 |
+
ctx.fillStyle = g
|
| 10 |
+
ctx.fillRect(x, y, w, h)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export function glowBlob(ctx: C2D, x: number, y: number, r: number, color: string, alpha: number) {
|
| 14 |
+
if (alpha <= 0.002 || r <= 0) return
|
| 15 |
+
const g = ctx.createRadialGradient(x, y, 0, x, y, r)
|
| 16 |
+
g.addColorStop(0, rgba(color, alpha))
|
| 17 |
+
g.addColorStop(0.4, rgba(color, alpha * 0.35))
|
| 18 |
+
g.addColorStop(1, rgba(color, 0))
|
| 19 |
+
ctx.fillStyle = g
|
| 20 |
+
ctx.fillRect(x - r, y - r, r * 2, r * 2)
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
export function fogBand(ctx: C2D, W: number, y: number, h: number, color: string, alpha: number) {
|
| 24 |
+
const g = ctx.createLinearGradient(0, y - h, 0, y + h)
|
| 25 |
+
g.addColorStop(0, rgba(color, 0))
|
| 26 |
+
g.addColorStop(0.5, rgba(color, alpha))
|
| 27 |
+
g.addColorStop(1, rgba(color, 0))
|
| 28 |
+
ctx.fillStyle = g
|
| 29 |
+
ctx.fillRect(0, y - h, W, h * 2)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// ---------------------------------------------------------------- buildings
|
| 33 |
+
export interface SkylineOpts {
|
| 34 |
+
W: number
|
| 35 |
+
seed: number
|
| 36 |
+
baseY: number
|
| 37 |
+
scroll: number
|
| 38 |
+
cell: number
|
| 39 |
+
minH: number
|
| 40 |
+
maxH: number
|
| 41 |
+
color: string
|
| 42 |
+
t: number
|
| 43 |
+
windows?: boolean
|
| 44 |
+
density?: number
|
| 45 |
+
winAlpha?: number
|
| 46 |
+
/** per-building height multiplier (equalizer etc.) */
|
| 47 |
+
hMod?: (k: number) => number
|
| 48 |
+
/** per-building window brightness boost */
|
| 49 |
+
litMod?: (k: number, row: number, rows: number) => number
|
| 50 |
+
roof?: boolean
|
| 51 |
+
rimColor?: string
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
export function skyline(ctx: C2D, o: SkylineOpts) {
|
| 55 |
+
const k0 = Math.floor(o.scroll / o.cell) - 1
|
| 56 |
+
const k1 = k0 + Math.ceil(o.W / o.cell) + 3
|
| 57 |
+
const blds: { x: number; w: number; top: number; h: number; k: number }[] = []
|
| 58 |
+
ctx.fillStyle = o.color
|
| 59 |
+
for (let k = k0; k <= k1; k++) {
|
| 60 |
+
const cellX = k * o.cell - o.scroll
|
| 61 |
+
const w = o.cell * (0.6 + 0.4 * hash(k * 7.13 + o.seed))
|
| 62 |
+
const x = cellX + (o.cell - w) * hash(k * 3.31 + o.seed)
|
| 63 |
+
let h = lerp(o.minH, o.maxH, Math.pow(hash(k * 1.71 + o.seed * 3.1), 1.4))
|
| 64 |
+
if (o.hMod) h *= o.hMod(k)
|
| 65 |
+
const top = o.baseY - h
|
| 66 |
+
ctx.fillRect(x, top, w, h + 4)
|
| 67 |
+
if (o.roof !== false) {
|
| 68 |
+
const r = hash(k * 9.7 + o.seed)
|
| 69 |
+
if (r > 0.55) {
|
| 70 |
+
// stepped crown
|
| 71 |
+
ctx.fillRect(x + w * 0.18, top - h * 0.05, w * 0.64, h * 0.05 + 1)
|
| 72 |
+
}
|
| 73 |
+
if (r > 0.72) {
|
| 74 |
+
// antenna
|
| 75 |
+
ctx.fillRect(x + w * (0.3 + 0.4 * hash(k + o.seed)), top - h * 0.18, Math.max(1, w * 0.025), h * 0.18)
|
| 76 |
+
}
|
| 77 |
+
if (r < 0.2) {
|
| 78 |
+
// water tank
|
| 79 |
+
const tw = w * 0.22
|
| 80 |
+
ctx.fillRect(x + w * 0.6, top - tw * 0.9, tw, tw * 0.9)
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
blds.push({ x, w, top, h, k })
|
| 84 |
+
}
|
| 85 |
+
if (o.rimColor) {
|
| 86 |
+
ctx.fillStyle = o.rimColor
|
| 87 |
+
for (const b of blds) ctx.fillRect(b.x, b.top, Math.max(1, b.w * 0.03), b.h)
|
| 88 |
+
}
|
| 89 |
+
if (o.windows === false) return
|
| 90 |
+
const dens = o.density ?? 0.3
|
| 91 |
+
const wa = o.winAlpha ?? 0.8
|
| 92 |
+
const sp = o.cell * 0.1
|
| 93 |
+
const ww = sp * 0.42
|
| 94 |
+
const wh = sp * 0.55
|
| 95 |
+
const flickT = Math.floor(o.t * 6)
|
| 96 |
+
for (let pass = 0; pass < 2; pass++) {
|
| 97 |
+
ctx.fillStyle = pass === 0 ? PALETTE.sodium : PALETTE.cyan
|
| 98 |
+
for (const b of blds) {
|
| 99 |
+
const cols = Math.max(1, Math.floor((b.w - sp * 0.6) / sp))
|
| 100 |
+
const rows = Math.max(1, Math.floor((b.h - sp) / (sp * 1.25)))
|
| 101 |
+
const ox = b.x + (b.w - cols * sp) / 2 + (sp - ww) / 2
|
| 102 |
+
for (let r = 0; r < rows; r++) {
|
| 103 |
+
const y = b.top + sp * 0.8 + r * sp * 1.25
|
| 104 |
+
for (let c = 0; c < cols; c++) {
|
| 105 |
+
const hv = hash3(b.k, r, c + o.seed)
|
| 106 |
+
let lit = hv < dens
|
| 107 |
+
const boost = o.litMod ? o.litMod(b.k, r, rows) : 0
|
| 108 |
+
if (!lit && boost <= 0) continue
|
| 109 |
+
const col = hash3(b.k + 3, r, c) > 0.82 ? 1 : 0
|
| 110 |
+
if (col !== pass) continue
|
| 111 |
+
if (hv < dens * 0.08) lit = hash3(b.k, r, flickT + c) > 0.3
|
| 112 |
+
const a = clamp((lit ? wa * (0.55 + 0.45 * hash3(c, r, b.k)) : 0) + boost)
|
| 113 |
+
if (a <= 0.02) continue
|
| 114 |
+
ctx.globalAlpha = a
|
| 115 |
+
ctx.fillRect(ox + c * sp, y, ww, wh)
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
ctx.globalAlpha = 1
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// ---------------------------------------------------------------- rain
|
| 124 |
+
export interface RainOpts {
|
| 125 |
+
count: number
|
| 126 |
+
speed: number
|
| 127 |
+
len: number
|
| 128 |
+
slant: number
|
| 129 |
+
color: string
|
| 130 |
+
alpha: number
|
| 131 |
+
width: number
|
| 132 |
+
seed?: number
|
| 133 |
+
}
|
| 134 |
+
export function rain(ctx: C2D, W: number, H: number, t: number, o: RainOpts) {
|
| 135 |
+
const seed = o.seed ?? 0
|
| 136 |
+
ctx.strokeStyle = rgba(o.color, o.alpha)
|
| 137 |
+
ctx.lineWidth = o.width
|
| 138 |
+
ctx.lineCap = 'round'
|
| 139 |
+
ctx.beginPath()
|
| 140 |
+
const span = W + H * Math.abs(o.slant)
|
| 141 |
+
for (let i = 0; i < o.count; i++) {
|
| 142 |
+
const s = 0.6 + 0.8 * hash(i * 1.7 + seed)
|
| 143 |
+
const y = fract(hash(i * 1.31 + seed) + (t * o.speed * s) / H) * (H + o.len * 2) - o.len
|
| 144 |
+
const x = hash(i * 2.17 + seed) * span - (o.slant > 0 ? H * o.slant : 0) + y * o.slant
|
| 145 |
+
const l = o.len * s
|
| 146 |
+
ctx.moveTo(x, y)
|
| 147 |
+
ctx.lineTo(x + l * o.slant, y + l)
|
| 148 |
+
}
|
| 149 |
+
ctx.stroke()
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
export function splashes(ctx: C2D, W: number, y0: number, y1: number, t: number, count: number, color: string, alpha: number, u: number) {
|
| 153 |
+
if (!(y1 > y0 + 1)) return
|
| 154 |
+
ctx.strokeStyle = rgba(color, alpha)
|
| 155 |
+
ctx.lineWidth = Math.max(1, u * 1.2)
|
| 156 |
+
ctx.beginPath()
|
| 157 |
+
for (let i = 0; i < count; i++) {
|
| 158 |
+
const period = 0.5 + hash(i * 3.1) * 0.6
|
| 159 |
+
const ph = fract(t / period + hash(i * 5.3))
|
| 160 |
+
const cyc = Math.floor(t / period + hash(i * 5.3))
|
| 161 |
+
const x = hash2(i, cyc) * W
|
| 162 |
+
const y = lerp(y0, y1, hash2(i + 9, cyc))
|
| 163 |
+
const r = Math.max(0.01, ph * u * (8 + 10 * hash(i)) * (0.4 + (y - y0) / Math.max(1, y1 - y0)))
|
| 164 |
+
ctx.moveTo(x + r, y)
|
| 165 |
+
ctx.ellipse(x, y, r, r * 0.28, 0, 0, Math.PI * 2)
|
| 166 |
+
}
|
| 167 |
+
ctx.globalAlpha = 1
|
| 168 |
+
ctx.stroke()
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
// ---------------------------------------------------------------- figures
|
| 172 |
+
export interface WalkerOpts {
|
| 173 |
+
run?: number
|
| 174 |
+
color?: string
|
| 175 |
+
rim?: string
|
| 176 |
+
rimSide?: number
|
| 177 |
+
facing?: number
|
| 178 |
+
coat?: number
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/** Procedural side-view hooded figure. phase: 0..1 per full stride (2 steps). */
|
| 182 |
+
export function walker(ctx: C2D, x: number, y: number, h: number, phase: number, o: WalkerOpts = {}) {
|
| 183 |
+
const run = o.run ?? 0
|
| 184 |
+
const facing = o.facing ?? 1
|
| 185 |
+
const col = o.color ?? '#040507'
|
| 186 |
+
const drawBody = (color: string, farColor: string, dx: number) => {
|
| 187 |
+
const P = Math.PI * 2
|
| 188 |
+
const bob = Math.abs(Math.sin(phase * P * 2)) * h * (0.012 + run * 0.02)
|
| 189 |
+
const lean = 0.06 + run * 0.28
|
| 190 |
+
const hipX = x + dx
|
| 191 |
+
const hipY = y - h * 0.47 - bob + run * h * 0.03
|
| 192 |
+
const shX = hipX + Math.sin(lean) * h * 0.31 * facing
|
| 193 |
+
const shY = hipY - Math.cos(lean) * h * 0.31
|
| 194 |
+
const L1 = h * 0.25
|
| 195 |
+
const L2 = h * 0.245
|
| 196 |
+
const leg = (ph: number, c: string) => {
|
| 197 |
+
const s = Math.sin(ph * P)
|
| 198 |
+
const th = s * (0.42 + run * 0.45)
|
| 199 |
+
const knee = Math.max(0, Math.cos(ph * P)) * (0.35 + run * 1.1) + 0.06
|
| 200 |
+
const kx = hipX + Math.sin(th) * L1 * facing
|
| 201 |
+
const ky = hipY + Math.cos(th) * L1
|
| 202 |
+
const sa = th - knee
|
| 203 |
+
const fx = kx + Math.sin(sa) * L2 * facing
|
| 204 |
+
const fy = ky + Math.cos(sa) * L2
|
| 205 |
+
ctx.strokeStyle = c
|
| 206 |
+
ctx.lineWidth = h * 0.072
|
| 207 |
+
ctx.beginPath()
|
| 208 |
+
ctx.moveTo(hipX, hipY)
|
| 209 |
+
ctx.lineTo(kx, ky)
|
| 210 |
+
ctx.lineTo(fx, fy)
|
| 211 |
+
ctx.stroke()
|
| 212 |
+
// shoe
|
| 213 |
+
ctx.lineWidth = h * 0.05
|
| 214 |
+
ctx.beginPath()
|
| 215 |
+
ctx.moveTo(fx - h * 0.01 * facing, fy)
|
| 216 |
+
ctx.lineTo(fx + h * 0.06 * facing, fy + h * 0.004)
|
| 217 |
+
ctx.stroke()
|
| 218 |
+
}
|
| 219 |
+
const arm = (ph: number, c: string) => {
|
| 220 |
+
const s = Math.sin(ph * P)
|
| 221 |
+
const a = -s * (0.45 + run * 0.7)
|
| 222 |
+
const elbow = 0.25 + run * 1.2
|
| 223 |
+
const ex = shX + Math.sin(a) * h * 0.17 * facing
|
| 224 |
+
const ey = shY + Math.cos(a) * h * 0.17
|
| 225 |
+
const fa = a - elbow * -1
|
| 226 |
+
const hx = ex + Math.sin(a + elbow) * h * 0.155 * facing
|
| 227 |
+
const hy = ey + Math.cos(a + elbow) * h * 0.155
|
| 228 |
+
void fa
|
| 229 |
+
ctx.strokeStyle = c
|
| 230 |
+
ctx.lineWidth = h * 0.058
|
| 231 |
+
ctx.beginPath()
|
| 232 |
+
ctx.moveTo(shX, shY + h * 0.02)
|
| 233 |
+
ctx.lineTo(ex, ey)
|
| 234 |
+
ctx.lineTo(hx, hy)
|
| 235 |
+
ctx.stroke()
|
| 236 |
+
}
|
| 237 |
+
ctx.lineCap = 'round'
|
| 238 |
+
ctx.lineJoin = 'round'
|
| 239 |
+
leg(phase + 0.5, farColor)
|
| 240 |
+
arm(phase, farColor)
|
| 241 |
+
// torso (hoodie)
|
| 242 |
+
ctx.fillStyle = color
|
| 243 |
+
ctx.beginPath()
|
| 244 |
+
const tw = h * 0.085
|
| 245 |
+
ctx.moveTo(hipX - tw * facing, hipY + h * 0.02)
|
| 246 |
+
ctx.quadraticCurveTo(hipX - tw * 1.25 * facing, (hipY + shY) / 2, shX - tw * 1.1 * facing, shY)
|
| 247 |
+
ctx.lineTo(shX + tw * 0.9 * facing, shY + h * 0.01)
|
| 248 |
+
ctx.quadraticCurveTo(hipX + tw * 1.25 * facing, (hipY + shY) / 2, hipX + tw * 0.95 * facing, hipY + h * 0.03)
|
| 249 |
+
ctx.closePath()
|
| 250 |
+
ctx.fill()
|
| 251 |
+
// coat tail flutter
|
| 252 |
+
const coat = o.coat ?? 0.6
|
| 253 |
+
if (coat > 0) {
|
| 254 |
+
const fl = Math.sin(phase * P * 2) * 0.5 + 0.5
|
| 255 |
+
ctx.beginPath()
|
| 256 |
+
ctx.moveTo(hipX - tw * facing, hipY - h * 0.02)
|
| 257 |
+
ctx.lineTo(hipX - (tw + h * (0.05 + 0.06 * run + 0.02 * fl) * coat) * facing, hipY + h * 0.1)
|
| 258 |
+
ctx.lineTo(hipX + tw * 0.6 * facing, hipY + h * 0.06)
|
| 259 |
+
ctx.closePath()
|
| 260 |
+
ctx.fill()
|
| 261 |
+
}
|
| 262 |
+
// head + hood
|
| 263 |
+
const hx = shX + h * 0.02 * facing
|
| 264 |
+
const hy = shY - h * 0.085
|
| 265 |
+
ctx.beginPath()
|
| 266 |
+
ctx.arc(hx, hy, h * 0.072, 0, Math.PI * 2)
|
| 267 |
+
ctx.fill()
|
| 268 |
+
ctx.beginPath()
|
| 269 |
+
ctx.moveTo(hx + h * 0.06 * facing, hy - h * 0.05)
|
| 270 |
+
ctx.quadraticCurveTo(hx - h * 0.02 * facing, hy - h * 0.11, hx - h * 0.1 * facing, hy - h * 0.02)
|
| 271 |
+
ctx.lineTo(hx - h * 0.075 * facing, hy + h * 0.07)
|
| 272 |
+
ctx.lineTo(hx, hy + h * 0.06)
|
| 273 |
+
ctx.closePath()
|
| 274 |
+
ctx.fill()
|
| 275 |
+
leg(phase, color)
|
| 276 |
+
arm(phase + 0.5, color)
|
| 277 |
+
}
|
| 278 |
+
if (o.rim) {
|
| 279 |
+
const side = o.rimSide ?? -1
|
| 280 |
+
drawBody(o.rim, o.rim, side * h * 0.014)
|
| 281 |
+
}
|
| 282 |
+
drawBody(col, '#0d0f14', 0)
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
/** Rear-view hooded figure (standing / slight sway). */
|
| 286 |
+
export function figureBack(ctx: C2D, x: number, y: number, h: number, sway = 0, o: { color?: string; rim?: string } = {}) {
|
| 287 |
+
const draw = (c: string, dx: number) => {
|
| 288 |
+
ctx.fillStyle = c
|
| 289 |
+
const sw = sway * h * 0.02
|
| 290 |
+
// legs
|
| 291 |
+
ctx.fillRect(x - h * 0.075 + dx, y - h * 0.46, h * 0.065, h * 0.46)
|
| 292 |
+
ctx.fillRect(x + h * 0.012 + dx, y - h * 0.46, h * 0.065, h * 0.46)
|
| 293 |
+
// body
|
| 294 |
+
ctx.beginPath()
|
| 295 |
+
ctx.moveTo(x - h * 0.13 + dx + sw, y - h * 0.8)
|
| 296 |
+
ctx.quadraticCurveTo(x - h * 0.17 + dx, y - h * 0.6, x - h * 0.12 + dx, y - h * 0.4)
|
| 297 |
+
ctx.lineTo(x + h * 0.12 + dx, y - h * 0.4)
|
| 298 |
+
ctx.quadraticCurveTo(x + h * 0.17 + dx, y - h * 0.6, x + h * 0.13 + dx + sw, y - h * 0.8)
|
| 299 |
+
ctx.closePath()
|
| 300 |
+
ctx.fill()
|
| 301 |
+
// arms
|
| 302 |
+
ctx.fillRect(x - h * 0.18 + dx + sw, y - h * 0.78, h * 0.055, h * 0.36)
|
| 303 |
+
ctx.fillRect(x + h * 0.125 + dx + sw, y - h * 0.78, h * 0.055, h * 0.36)
|
| 304 |
+
// hood
|
| 305 |
+
ctx.beginPath()
|
| 306 |
+
ctx.ellipse(x + dx + sw * 1.3, y - h * 0.88, h * 0.085, h * 0.1, 0, 0, Math.PI * 2)
|
| 307 |
+
ctx.fill()
|
| 308 |
+
}
|
| 309 |
+
if (o.rim) draw(o.rim, -h * 0.012)
|
| 310 |
+
draw(o.color ?? '#030405', 0)
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
// ---------------------------------------------------------------- neon
|
| 314 |
+
export interface NeonOpts {
|
| 315 |
+
font?: string
|
| 316 |
+
align?: CanvasTextAlign
|
| 317 |
+
baseline?: CanvasTextBaseline
|
| 318 |
+
tube?: boolean
|
| 319 |
+
core?: string
|
| 320 |
+
blur?: number
|
| 321 |
+
weight?: string
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
export function neonText(ctx: C2D, text: string, x: number, y: number, size: number, color: string, on: number, o: NeonOpts = {}) {
|
| 325 |
+
ctx.save()
|
| 326 |
+
ctx.font = `${o.weight ?? ''} ${size}px ${o.font ?? FONT.neon}`
|
| 327 |
+
ctx.textAlign = o.align ?? 'center'
|
| 328 |
+
ctx.textBaseline = o.baseline ?? 'middle'
|
| 329 |
+
const tube = o.tube ?? false
|
| 330 |
+
if (on < 0.98) {
|
| 331 |
+
// unlit glass tube
|
| 332 |
+
ctx.globalAlpha = 1
|
| 333 |
+
if (tube) {
|
| 334 |
+
ctx.strokeStyle = '#2a1d22'
|
| 335 |
+
ctx.lineWidth = size * 0.045
|
| 336 |
+
ctx.strokeText(text, x, y)
|
| 337 |
+
} else {
|
| 338 |
+
ctx.fillStyle = '#1d1519'
|
| 339 |
+
ctx.fillText(text, x, y)
|
| 340 |
+
}
|
| 341 |
+
}
|
| 342 |
+
if (on > 0.02) {
|
| 343 |
+
ctx.globalAlpha = clamp(on)
|
| 344 |
+
ctx.shadowColor = color
|
| 345 |
+
ctx.shadowBlur = size * (o.blur ?? 0.3)
|
| 346 |
+
if (tube) {
|
| 347 |
+
ctx.strokeStyle = color
|
| 348 |
+
ctx.lineWidth = size * 0.05
|
| 349 |
+
ctx.strokeText(text, x, y)
|
| 350 |
+
ctx.shadowBlur = size * 0.08
|
| 351 |
+
ctx.strokeStyle = o.core ?? '#fff3f5'
|
| 352 |
+
ctx.lineWidth = size * 0.018
|
| 353 |
+
ctx.strokeText(text, x, y)
|
| 354 |
+
} else {
|
| 355 |
+
ctx.fillStyle = color
|
| 356 |
+
ctx.fillText(text, x, y)
|
| 357 |
+
ctx.shadowBlur = size * 0.06
|
| 358 |
+
ctx.globalAlpha = clamp(on) * 0.75
|
| 359 |
+
ctx.fillStyle = o.core ?? '#fff3f5'
|
| 360 |
+
ctx.fillText(text, x, y)
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
ctx.restore()
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
export function neonSign(
|
| 367 |
+
ctx: C2D,
|
| 368 |
+
x: number,
|
| 369 |
+
y: number,
|
| 370 |
+
w: number,
|
| 371 |
+
h: number,
|
| 372 |
+
text: string,
|
| 373 |
+
color: string,
|
| 374 |
+
on: number,
|
| 375 |
+
vertical: boolean,
|
| 376 |
+
) {
|
| 377 |
+
ctx.save()
|
| 378 |
+
ctx.fillStyle = 'rgba(6,6,10,0.92)'
|
| 379 |
+
ctx.fillRect(x, y, w, h)
|
| 380 |
+
ctx.lineWidth = Math.max(1, Math.min(w, h) * 0.05)
|
| 381 |
+
ctx.strokeStyle = on > 0.3 ? color : '#221a1e'
|
| 382 |
+
if (on > 0.3) {
|
| 383 |
+
ctx.shadowColor = color
|
| 384 |
+
ctx.shadowBlur = Math.min(w, h) * 0.5 * on
|
| 385 |
+
}
|
| 386 |
+
ctx.globalAlpha = on > 0.3 ? on : 1
|
| 387 |
+
const inset = Math.min(w, h) * 0.08
|
| 388 |
+
ctx.strokeRect(x + inset, y + inset, w - inset * 2, h - inset * 2)
|
| 389 |
+
ctx.restore()
|
| 390 |
+
const chars = Array.from(text)
|
| 391 |
+
if (vertical) {
|
| 392 |
+
const cs = Math.min(w * 0.66, (h * 0.86) / chars.length)
|
| 393 |
+
const total = cs * chars.length
|
| 394 |
+
chars.forEach((c, i) => neonText(ctx, c, x + w / 2, y + (h - total) / 2 + cs * (i + 0.5), cs * 0.92, color, on, { blur: 0.25 }))
|
| 395 |
+
} else {
|
| 396 |
+
const cs = Math.min(h * 0.62, (w * 0.86) / chars.length)
|
| 397 |
+
neonText(ctx, text, x + w / 2, y + h / 2, cs, color, on, { blur: 0.25 })
|
| 398 |
+
}
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
// ---------------------------------------------------------------- light
|
| 402 |
+
export function lightCone(ctx: C2D, x: number, y: number, len: number, spread: number, angle: number, color: string, alpha: number) {
|
| 403 |
+
if (alpha <= 0.003) return
|
| 404 |
+
ctx.save()
|
| 405 |
+
ctx.translate(x, y)
|
| 406 |
+
ctx.rotate(angle)
|
| 407 |
+
const g = ctx.createLinearGradient(0, 0, 0, len)
|
| 408 |
+
g.addColorStop(0, rgba(color, alpha))
|
| 409 |
+
g.addColorStop(0.6, rgba(color, alpha * 0.25))
|
| 410 |
+
g.addColorStop(1, rgba(color, 0))
|
| 411 |
+
ctx.fillStyle = g
|
| 412 |
+
ctx.beginPath()
|
| 413 |
+
ctx.moveTo(-len * 0.01, 0)
|
| 414 |
+
ctx.lineTo(len * 0.01, 0)
|
| 415 |
+
ctx.lineTo(Math.tan(spread) * len, len)
|
| 416 |
+
ctx.lineTo(-Math.tan(spread) * len, len)
|
| 417 |
+
ctx.closePath()
|
| 418 |
+
ctx.fill()
|
| 419 |
+
ctx.restore()
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
export function streetLamp(ctx: C2D, x: number, groundY: number, h: number, on: number, color = PALETTE.sodium) {
|
| 423 |
+
ctx.fillStyle = '#07080b'
|
| 424 |
+
ctx.fillRect(x - h * 0.012, groundY - h, h * 0.024, h)
|
| 425 |
+
ctx.fillRect(x - h * 0.012, groundY - h, h * 0.16, h * 0.018)
|
| 426 |
+
const lx = x + h * 0.14
|
| 427 |
+
const ly = groundY - h + h * 0.03
|
| 428 |
+
ctx.fillRect(lx - h * 0.035, ly - h * 0.02, h * 0.07, h * 0.025)
|
| 429 |
+
lightCone(ctx, lx, ly, h * 1.05, 0.42, 0, color, 0.22 * on)
|
| 430 |
+
glowBlob(ctx, lx, ly, h * 0.12, color, 0.9 * on)
|
| 431 |
+
// pool of light on ground
|
| 432 |
+
ctx.save()
|
| 433 |
+
ctx.globalAlpha = 0.35 * on
|
| 434 |
+
const g = ctx.createRadialGradient(lx, groundY, 0, lx, groundY, h * 0.5)
|
| 435 |
+
g.addColorStop(0, rgba(color, 0.5))
|
| 436 |
+
g.addColorStop(1, rgba(color, 0))
|
| 437 |
+
ctx.fillStyle = g
|
| 438 |
+
ctx.scale(1, 0.25)
|
| 439 |
+
ctx.fillRect(lx - h * 0.5, (groundY - h * 0.5) * 4, h, h * 4)
|
| 440 |
+
ctx.restore()
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
// ---------------------------------------------------------------- effects
|
| 444 |
+
export function wetReflection(
|
| 445 |
+
ctx: C2D,
|
| 446 |
+
scratch: HTMLCanvasElement,
|
| 447 |
+
W: number,
|
| 448 |
+
H: number,
|
| 449 |
+
groundY: number,
|
| 450 |
+
t: number,
|
| 451 |
+
alpha: number,
|
| 452 |
+
ripple: number,
|
| 453 |
+
) {
|
| 454 |
+
const s = scratch.getContext('2d')!
|
| 455 |
+
s.setTransform(1, 0, 0, 1, 0, 0)
|
| 456 |
+
s.globalAlpha = 1
|
| 457 |
+
s.globalCompositeOperation = 'copy'
|
| 458 |
+
s.drawImage(ctx.canvas, 0, 0)
|
| 459 |
+
s.globalCompositeOperation = 'source-over'
|
| 460 |
+
ctx.save()
|
| 461 |
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
| 462 |
+
const regionH = H - groundY
|
| 463 |
+
const strips = Math.max(12, Math.floor(regionH / Math.max(2, H / 260)))
|
| 464 |
+
const bh = regionH / strips
|
| 465 |
+
ctx.globalAlpha = alpha
|
| 466 |
+
for (let i = 0; i < strips; i++) {
|
| 467 |
+
const dy = i * bh
|
| 468 |
+
const srcY = groundY - dy - bh * 1.02
|
| 469 |
+
if (srcY < 0) break
|
| 470 |
+
const k = i / strips
|
| 471 |
+
const off = Math.sin(i * 0.83 + t * 3.1) * ripple * (0.3 + k) + Math.sin(i * 2.1 - t * 5) * ripple * 0.4 * k
|
| 472 |
+
ctx.save()
|
| 473 |
+
ctx.translate(off, groundY + dy + bh)
|
| 474 |
+
ctx.scale(1, -1)
|
| 475 |
+
ctx.drawImage(scratch, 0, srcY, W, bh * 1.02, 0, 0, W, bh * 1.02)
|
| 476 |
+
ctx.restore()
|
| 477 |
+
}
|
| 478 |
+
ctx.restore()
|
| 479 |
+
// darken / tint the wet ground
|
| 480 |
+
vGradient(ctx, 0, groundY, W, regionH, [
|
| 481 |
+
[0, 'rgba(4,6,10,0.25)'],
|
| 482 |
+
[1, 'rgba(4,6,10,0.85)'],
|
| 483 |
+
])
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
export function speedLines(ctx: C2D, cx: number, cy: number, R: number, t: number, count: number, color: string, alpha: number, inner = 0.35) {
|
| 487 |
+
ctx.fillStyle = rgba(color, alpha)
|
| 488 |
+
ctx.beginPath()
|
| 489 |
+
const fr = Math.floor(t * 18)
|
| 490 |
+
for (let i = 0; i < count; i++) {
|
| 491 |
+
if (hash2(i, fr) < 0.35) continue
|
| 492 |
+
const a = hash(i * 1.37) * Math.PI * 2
|
| 493 |
+
const wdt = 0.004 + 0.012 * hash(i * 4.1 + fr)
|
| 494 |
+
const r0 = R * (inner + 0.4 * hash2(i, fr + 1))
|
| 495 |
+
const r1 = R * 1.6
|
| 496 |
+
ctx.moveTo(cx + Math.cos(a) * r0, cy + Math.sin(a) * r0)
|
| 497 |
+
ctx.lineTo(cx + Math.cos(a - wdt) * r1, cy + Math.sin(a - wdt) * r1)
|
| 498 |
+
ctx.lineTo(cx + Math.cos(a + wdt) * r1, cy + Math.sin(a + wdt) * r1)
|
| 499 |
+
ctx.closePath()
|
| 500 |
+
}
|
| 501 |
+
ctx.fill()
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
/** Bottom subtitle with typewriter reveal. */
|
| 505 |
+
export function caption(ctx: C2D, W: number, H: number, text: string, lt: number, dur: number, portrait: boolean) {
|
| 506 |
+
const chars = Array.from(text)
|
| 507 |
+
const size = portrait ? Math.min(W * 0.06, H * 0.034) : H * 0.048
|
| 508 |
+
const y = portrait ? H * 0.8 : H * 0.875
|
| 509 |
+
const reveal = clamp(lt / Math.min(0.9, dur * 0.3))
|
| 510 |
+
const fade = clamp((dur - lt) / 0.35)
|
| 511 |
+
const n = Math.ceil(chars.length * reveal)
|
| 512 |
+
ctx.save()
|
| 513 |
+
ctx.font = `${size}px ${FONT.black}`
|
| 514 |
+
ctx.textBaseline = 'middle'
|
| 515 |
+
ctx.textAlign = 'left'
|
| 516 |
+
const spacing = size * 0.12
|
| 517 |
+
const widths = chars.map((c) => ctx.measureText(c).width)
|
| 518 |
+
const total = widths.reduce((s, w) => s + w + spacing, -spacing)
|
| 519 |
+
let x = (W - total) / 2
|
| 520 |
+
// accent bar
|
| 521 |
+
ctx.globalAlpha = fade
|
| 522 |
+
ctx.fillStyle = PALETTE.red
|
| 523 |
+
ctx.fillRect(x - size * 0.55, y - size * 0.45, size * 0.12, size * 0.9)
|
| 524 |
+
ctx.lineJoin = 'round'
|
| 525 |
+
for (let i = 0; i < n; i++) {
|
| 526 |
+
const c = chars[i]
|
| 527 |
+
const fresh = clamp((reveal * chars.length - i) / 1.5)
|
| 528 |
+
ctx.globalAlpha = fade * fresh
|
| 529 |
+
ctx.strokeStyle = 'rgba(0,0,0,0.85)'
|
| 530 |
+
ctx.lineWidth = size * 0.16
|
| 531 |
+
ctx.strokeText(c, x, y + (1 - fresh) * size * 0.25)
|
| 532 |
+
ctx.fillStyle = i === n - 1 && reveal < 1 ? PALETTE.sodium : PALETTE.bone
|
| 533 |
+
ctx.fillText(c, x, y + (1 - fresh) * size * 0.25)
|
| 534 |
+
x += widths[i] + spacing
|
| 535 |
+
}
|
| 536 |
+
ctx.restore()
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
/** Big poster text with manual RGB split. */
|
| 540 |
+
export function splitText(ctx: C2D, text: string, x: number, y: number, size: number, font: string, color: string, split: number, align: CanvasTextAlign = 'center') {
|
| 541 |
+
ctx.save()
|
| 542 |
+
ctx.font = `${size}px ${font}`
|
| 543 |
+
ctx.textAlign = align
|
| 544 |
+
ctx.textBaseline = 'middle'
|
| 545 |
+
if (split > 0.5) {
|
| 546 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 547 |
+
ctx.fillStyle = 'rgba(255,40,80,0.85)'
|
| 548 |
+
ctx.fillText(text, x - split, y)
|
| 549 |
+
ctx.fillStyle = 'rgba(40,220,255,0.85)'
|
| 550 |
+
ctx.fillText(text, x + split, y)
|
| 551 |
+
ctx.globalCompositeOperation = 'source-over'
|
| 552 |
+
}
|
| 553 |
+
ctx.fillStyle = color
|
| 554 |
+
ctx.fillText(text, x, y)
|
| 555 |
+
ctx.restore()
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
export function marquee(ctx: C2D, text: string, y: number, W: number, size: number, offset: number, color: string, font = FONT.latin) {
|
| 559 |
+
ctx.save()
|
| 560 |
+
ctx.font = `${size}px ${font}`
|
| 561 |
+
ctx.textBaseline = 'middle'
|
| 562 |
+
ctx.textAlign = 'left'
|
| 563 |
+
ctx.fillStyle = color
|
| 564 |
+
const w = ctx.measureText(text).width + size
|
| 565 |
+
let x = -fract(offset / w) * w
|
| 566 |
+
while (x < W) {
|
| 567 |
+
ctx.fillText(text, x, y)
|
| 568 |
+
x += w
|
| 569 |
+
}
|
| 570 |
+
ctx.restore()
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
export function halftone(ctx: C2D, W: number, H: number, cell: number, color: string, f: (x: number, y: number) => number) {
|
| 574 |
+
ctx.fillStyle = color
|
| 575 |
+
ctx.beginPath()
|
| 576 |
+
for (let y = cell / 2; y < H; y += cell) {
|
| 577 |
+
for (let x = cell / 2; x < W; x += cell) {
|
| 578 |
+
const r = f(x / W, y / H) * cell * 0.5
|
| 579 |
+
if (r < 0.4) continue
|
| 580 |
+
ctx.moveTo(x + r, y)
|
| 581 |
+
ctx.arc(x, y, r, 0, Math.PI * 2)
|
| 582 |
+
}
|
| 583 |
+
}
|
| 584 |
+
ctx.fill()
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
export function lantern(ctx: C2D, x: number, y: number, r: number, swing: number, on: number) {
|
| 588 |
+
ctx.save()
|
| 589 |
+
ctx.translate(x, y)
|
| 590 |
+
ctx.rotate(swing)
|
| 591 |
+
ctx.strokeStyle = '#1a0d0a'
|
| 592 |
+
ctx.lineWidth = Math.max(1, r * 0.05)
|
| 593 |
+
ctx.beginPath()
|
| 594 |
+
ctx.moveTo(0, -r * 1.6)
|
| 595 |
+
ctx.lineTo(0, -r * 0.9)
|
| 596 |
+
ctx.stroke()
|
| 597 |
+
glowBlob(ctx, 0, 0, r * 3.2, PALETTE.amber, 0.35 * on)
|
| 598 |
+
const g = ctx.createRadialGradient(-r * 0.25, -r * 0.2, r * 0.1, 0, 0, r)
|
| 599 |
+
g.addColorStop(0, '#ffd59a')
|
| 600 |
+
g.addColorStop(0.45, '#ff4a2e')
|
| 601 |
+
g.addColorStop(1, '#7a0f12')
|
| 602 |
+
ctx.fillStyle = g
|
| 603 |
+
ctx.beginPath()
|
| 604 |
+
ctx.ellipse(0, 0, r, r * 0.85,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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// WebGL post-processing: bloom + chromatic aberration + glitch + grade + grain.
|
| 2 |
+
// WebGL1 API for the widest device support (incl. older iOS Safari).
|
| 3 |
+
|
| 4 |
+
export interface PostParams {
|
| 5 |
+
time: number
|
| 6 |
+
flash: number
|
| 7 |
+
flashColor: [number, number, number]
|
| 8 |
+
aberr: number
|
| 9 |
+
glitch: number
|
| 10 |
+
zoom: number
|
| 11 |
+
shake: [number, number]
|
| 12 |
+
bloom: number
|
| 13 |
+
grain: number
|
| 14 |
+
vignette: number
|
| 15 |
+
scan: number
|
| 16 |
+
/** 0 = normal, 1 = full black-out (used for hard cut to black) */
|
| 17 |
+
black: number
|
| 18 |
+
seed: number
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const VS = `
|
| 22 |
+
attribute vec2 p;
|
| 23 |
+
varying vec2 uv;
|
| 24 |
+
void main(){ uv = p*0.5+0.5; gl_Position = vec4(p,0.0,1.0); }`
|
| 25 |
+
|
| 26 |
+
const FS_BRIGHT = `
|
| 27 |
+
precision mediump float;
|
| 28 |
+
varying vec2 uv;
|
| 29 |
+
uniform sampler2D src;
|
| 30 |
+
uniform vec2 texel;
|
| 31 |
+
void main(){
|
| 32 |
+
vec3 c = vec3(0.0);
|
| 33 |
+
c += texture2D(src, uv + texel*vec2(-1.0,-1.0)).rgb;
|
| 34 |
+
c += texture2D(src, uv + texel*vec2( 1.0,-1.0)).rgb;
|
| 35 |
+
c += texture2D(src, uv + texel*vec2(-1.0, 1.0)).rgb;
|
| 36 |
+
c += texture2D(src, uv + texel*vec2( 1.0, 1.0)).rgb;
|
| 37 |
+
c *= 0.25;
|
| 38 |
+
float l = max(max(c.r,c.g),c.b);
|
| 39 |
+
float k = smoothstep(0.42, 0.95, l);
|
| 40 |
+
gl_FragColor = vec4(c*k, 1.0);
|
| 41 |
+
}`
|
| 42 |
+
|
| 43 |
+
const FS_BLUR = `
|
| 44 |
+
precision mediump float;
|
| 45 |
+
varying vec2 uv;
|
| 46 |
+
uniform sampler2D src;
|
| 47 |
+
uniform vec2 dir;
|
| 48 |
+
void main(){
|
| 49 |
+
vec3 c = texture2D(src, uv).rgb * 0.227027;
|
| 50 |
+
c += texture2D(src, uv + dir*1.3846).rgb * 0.3162162;
|
| 51 |
+
c += texture2D(src, uv - dir*1.3846).rgb * 0.3162162;
|
| 52 |
+
c += texture2D(src, uv + dir*3.2307).rgb * 0.0702702;
|
| 53 |
+
c += texture2D(src, uv - dir*3.2307).rgb * 0.0702702;
|
| 54 |
+
gl_FragColor = vec4(c, 1.0);
|
| 55 |
+
}`
|
| 56 |
+
|
| 57 |
+
const FS_FINAL = `
|
| 58 |
+
precision highp float;
|
| 59 |
+
varying vec2 uv;
|
| 60 |
+
uniform sampler2D scene;
|
| 61 |
+
uniform sampler2D bloomA;
|
| 62 |
+
uniform sampler2D bloomB;
|
| 63 |
+
uniform vec2 res;
|
| 64 |
+
uniform float time;
|
| 65 |
+
uniform float flash;
|
| 66 |
+
uniform vec3 flashColor;
|
| 67 |
+
uniform float aberr;
|
| 68 |
+
uniform float glitch;
|
| 69 |
+
uniform float zoom;
|
| 70 |
+
uniform vec2 shake;
|
| 71 |
+
uniform float bloom;
|
| 72 |
+
uniform float grain;
|
| 73 |
+
uniform float vignette;
|
| 74 |
+
uniform float scan;
|
| 75 |
+
uniform float black;
|
| 76 |
+
uniform float seed;
|
| 77 |
+
|
| 78 |
+
float h1(float n){ return fract(sin(n*127.1+seed*13.7)*43758.5453); }
|
| 79 |
+
float h2(vec2 p){ return fract(sin(dot(p, vec2(12.9898,78.233)) + seed)*43758.5453); }
|
| 80 |
+
|
| 81 |
+
void main(){
|
| 82 |
+
vec2 q = uv;
|
| 83 |
+
// zoom punch & shake around the centre
|
| 84 |
+
q = (q - 0.5) / zoom + 0.5 + shake;
|
| 85 |
+
// subtle lens barrel
|
| 86 |
+
vec2 cc = q - 0.5;
|
| 87 |
+
q = 0.5 + cc * (1.0 + 0.035*dot(cc,cc));
|
| 88 |
+
// glitch: horizontal block displacement
|
| 89 |
+
if (glitch > 0.001) {
|
| 90 |
+
float row = floor(q.y * 24.0);
|
| 91 |
+
float tt = floor(time * 30.0);
|
| 92 |
+
float r = h1(row + tt*7.0);
|
| 93 |
+
if (r < glitch*0.45) {
|
| 94 |
+
q.x += (h1(row*3.1 + tt) - 0.5) * 0.18 * glitch;
|
| 95 |
+
}
|
| 96 |
+
float big = floor(q.y * 6.0);
|
| 97 |
+
if (h1(big + tt*1.7) < glitch*0.15) q.x = fract(q.x + 0.06);
|
| 98 |
+
}
|
| 99 |
+
float ab = aberr + glitch*0.012;
|
| 100 |
+
vec2 dir = (q - 0.5);
|
| 101 |
+
vec3 col;
|
| 102 |
+
col.r = texture2D(scene, q + dir*ab).r;
|
| 103 |
+
col.g = texture2D(scene, q).g;
|
| 104 |
+
col.b = texture2D(scene, q - dir*ab).b;
|
| 105 |
+
// outside edges -> black
|
| 106 |
+
if (q.x < 0.0 || q.x > 1.0 || q.y < 0.0 || q.y > 1.0) col = vec3(0.0);
|
| 107 |
+
|
| 108 |
+
vec3 b = texture2D(bloomA, uv).rgb * 0.8 + texture2D(bloomB, uv).rgb * 1.0;
|
| 109 |
+
col += b * bloom;
|
| 110 |
+
|
| 111 |
+
// filmic grade: teal shadows, warm highlights (inspired by the reference palette)
|
| 112 |
+
float l = dot(col, vec3(0.299,0.587,0.114));
|
| 113 |
+
vec3 shadowTint = vec3(0.86, 1.0, 1.10);
|
| 114 |
+
vec3 highTint = vec3(1.08, 0.99, 0.88);
|
| 115 |
+
col *= mix(shadowTint, highTint, smoothstep(0.15, 0.75, l));
|
| 116 |
+
col = mix(vec3(l), col, 1.06);
|
| 117 |
+
// soft shoulder tonemap
|
| 118 |
+
col = col / (1.0 + col*0.18) * 1.14;
|
| 119 |
+
// lifted, slightly teal blacks (filmic look from the reference footage)
|
| 120 |
+
col = col * 0.94 + vec3(0.018, 0.028, 0.036);
|
| 121 |
+
|
| 122 |
+
// scanlines + grain
|
| 123 |
+
float s = sin(uv.y * res.y * 3.14159) * 0.5 + 0.5;
|
| 124 |
+
col *= 1.0 - scan * (1.0 - s);
|
| 125 |
+
float g = h2(uv*res + fract(time*61.0)*vec2(91.7, 37.3)) - 0.5;
|
| 126 |
+
col += g * grain;
|
| 127 |
+
|
| 128 |
+
// vignette
|
| 129 |
+
vec2 v = uv - 0.5;
|
| 130 |
+
col *= mix(1.0, smoothstep(0.85, 0.2, length(v*vec2(1.0, res.y/res.x*0.9+0.1))), vignette);
|
| 131 |
+
|
| 132 |
+
col = mix(col, flashColor, clamp(flash, 0.0, 1.0));
|
| 133 |
+
col *= 1.0 - black;
|
| 134 |
+
gl_FragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
|
| 135 |
+
}`
|
| 136 |
+
|
| 137 |
+
interface FBO {
|
| 138 |
+
fb: WebGLFramebuffer
|
| 139 |
+
tex: WebGLTexture
|
| 140 |
+
w: number
|
| 141 |
+
h: number
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
export class Post {
|
| 145 |
+
gl: WebGLRenderingContext
|
| 146 |
+
private progBright: WebGLProgram
|
| 147 |
+
private progBlur: WebGLProgram
|
| 148 |
+
private progFinal: WebGLProgram
|
| 149 |
+
private sceneTex: WebGLTexture
|
| 150 |
+
private buf: WebGLBuffer
|
| 151 |
+
private fA!: FBO
|
| 152 |
+
private fB!: FBO
|
| 153 |
+
private fC!: FBO
|
| 154 |
+
private fD!: FBO
|
| 155 |
+
private W = 0
|
| 156 |
+
private H = 0
|
| 157 |
+
private uni = new Map<WebGLProgram, Map<string, WebGLUniformLocation | null>>()
|
| 158 |
+
|
| 159 |
+
static create(canvas: HTMLCanvasElement): Post | null {
|
| 160 |
+
try {
|
| 161 |
+
const gl = canvas.getContext('webgl', {
|
| 162 |
+
preserveDrawingBuffer: true,
|
| 163 |
+
antialias: false,
|
| 164 |
+
premultipliedAlpha: false,
|
| 165 |
+
alpha: false,
|
| 166 |
+
}) as WebGLRenderingContext | null
|
| 167 |
+
if (!gl) return null
|
| 168 |
+
return new Post(gl)
|
| 169 |
+
} catch {
|
| 170 |
+
return null
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
constructor(gl: WebGLRenderingContext) {
|
| 175 |
+
this.gl = gl
|
| 176 |
+
this.progBright = this.program(VS, FS_BRIGHT)
|
| 177 |
+
this.progBlur = this.program(VS, FS_BLUR)
|
| 178 |
+
this.progFinal = this.program(VS, FS_FINAL)
|
| 179 |
+
this.buf = gl.createBuffer()!
|
| 180 |
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.buf)
|
| 181 |
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW)
|
| 182 |
+
this.sceneTex = this.texture()
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
private shader(type: number, src: string) {
|
| 186 |
+
const gl = this.gl
|
| 187 |
+
const s = gl.createShader(type)!
|
| 188 |
+
gl.shaderSource(s, src)
|
| 189 |
+
gl.compileShader(s)
|
| 190 |
+
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s) || 'shader')
|
| 191 |
+
return s
|
| 192 |
+
}
|
| 193 |
+
private program(vs: string, fs: string) {
|
| 194 |
+
const gl = this.gl
|
| 195 |
+
const p = gl.createProgram()!
|
| 196 |
+
gl.attachShader(p, this.shader(gl.VERTEX_SHADER, vs))
|
| 197 |
+
gl.attachShader(p, this.shader(gl.FRAGMENT_SHADER, fs))
|
| 198 |
+
gl.linkProgram(p)
|
| 199 |
+
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p) || 'link')
|
| 200 |
+
return p
|
| 201 |
+
}
|
| 202 |
+
private u(p: WebGLProgram, name: string) {
|
| 203 |
+
let m = this.uni.get(p)
|
| 204 |
+
if (!m) {
|
| 205 |
+
m = new Map()
|
| 206 |
+
this.uni.set(p, m)
|
| 207 |
+
}
|
| 208 |
+
if (!m.has(name)) m.set(name, this.gl.getUniformLocation(p, name))
|
| 209 |
+
return m.get(name)!
|
| 210 |
+
}
|
| 211 |
+
private texture() {
|
| 212 |
+
const gl = this.gl
|
| 213 |
+
const t = gl.createTexture()!
|
| 214 |
+
gl.bindTexture(gl.TEXTURE_2D, t)
|
| 215 |
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
| 216 |
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
| 217 |
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
|
| 218 |
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
|
| 219 |
+
return t
|
| 220 |
+
}
|
| 221 |
+
private fbo(w: number, h: number): FBO {
|
| 222 |
+
const gl = this.gl
|
| 223 |
+
const tex = this.texture()
|
| 224 |
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null)
|
| 225 |
+
const fb = gl.createFramebuffer()!
|
| 226 |
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fb)
|
| 227 |
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0)
|
| 228 |
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
|
| 229 |
+
return { fb, tex, w, h }
|
| 230 |
+
}
|
| 231 |
+
private freeFbo(f?: FBO) {
|
| 232 |
+
if (!f) return
|
| 233 |
+
this.gl.deleteFramebuffer(f.fb)
|
| 234 |
+
this.gl.deleteTexture(f.tex)
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
resize(W: number, H: number) {
|
| 238 |
+
if (W === this.W && H === this.H) return
|
| 239 |
+
this.W = W
|
| 240 |
+
this.H = H
|
| 241 |
+
;[this.fA, this.fB, this.fC, this.fD].forEach((f) => this.freeFbo(f))
|
| 242 |
+
const qw = Math.max(2, Math.round(W / 4))
|
| 243 |
+
const qh = Math.max(2, Math.round(H / 4))
|
| 244 |
+
const ew = Math.max(2, Math.round(W / 12))
|
| 245 |
+
const eh = Math.max(2, Math.round(H / 12))
|
| 246 |
+
this.fA = this.fbo(qw, qh)
|
| 247 |
+
this.fB = this.fbo(qw, qh)
|
| 248 |
+
this.fC = this.fbo(ew, eh)
|
| 249 |
+
this.fD = this.fbo(ew, eh)
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
private draw(p: WebGLProgram) {
|
| 253 |
+
const gl = this.gl
|
| 254 |
+
gl.useProgram(p)
|
| 255 |
+
const loc = gl.getAttribLocation(p, 'p')
|
| 256 |
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.buf)
|
| 257 |
+
gl.enableVertexAttribArray(loc)
|
| 258 |
+
gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0)
|
| 259 |
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
private bindTex(p: WebGLProgram, name: string, tex: WebGLTexture, unit: number) {
|
| 263 |
+
const gl = this.gl
|
| 264 |
+
gl.activeTexture(gl.TEXTURE0 + unit)
|
| 265 |
+
gl.bindTexture(gl.TEXTURE_2D, tex)
|
| 266 |
+
gl.uniform1i(this.u(p, name), unit)
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
private blur(src: FBO, tmp: FBO, scale: number) {
|
| 270 |
+
const gl = this.gl
|
| 271 |
+
const p = this.progBlur
|
| 272 |
+
gl.useProgram(p)
|
| 273 |
+
gl.bindFramebuffer(gl.FRAMEBUFFER, tmp.fb)
|
| 274 |
+
gl.viewport(0, 0, tmp.w, tmp.h)
|
| 275 |
+
this.bindTex(p, 'src', src.tex, 0)
|
| 276 |
+
gl.uniform2f(this.u(p, 'dir'), scale / src.w, 0)
|
| 277 |
+
this.draw(p)
|
| 278 |
+
gl.bindFramebuffer(gl.FRAMEBUFFER, src.fb)
|
| 279 |
+
gl.viewport(0, 0, src.w, src.h)
|
| 280 |
+
this.bindTex(p, 'src', tmp.tex, 0)
|
| 281 |
+
gl.uniform2f(this.u(p, 'dir'), 0, scale / src.h)
|
| 282 |
+
this.draw(p)
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
private down(src: WebGLTexture, srcW: number, srcH: number, dst: FBO) {
|
| 286 |
+
const gl = this.gl
|
| 287 |
+
const p = this.progBright
|
| 288 |
+
gl.useProgram(p)
|
| 289 |
+
gl.bindFramebuffer(gl.FRAMEBUFFER, dst.fb)
|
| 290 |
+
gl.viewport(0, 0, dst.w, dst.h)
|
| 291 |
+
this.bindTex(p, 'src', src, 0)
|
| 292 |
+
gl.uniform2f(this.u(p, 'texel'), 1.5 / srcW, 1.5 / srcH)
|
| 293 |
+
this.draw(p)
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
render(source: HTMLCanvasElement, pp: PostParams) {
|
| 297 |
+
const gl = this.gl
|
| 298 |
+
const W = source.width
|
| 299 |
+
const H = source.height
|
| 300 |
+
this.resize(W, H)
|
| 301 |
+
gl.bindTexture(gl.TEXTURE_2D, this.sceneTex)
|
| 302 |
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true)
|
| 303 |
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source)
|
| 304 |
+
|
| 305 |
+
// bloom chain
|
| 306 |
+
this.down(this.sceneTex, W, H, this.fA)
|
| 307 |
+
this.blur(this.fA, this.fB, 1.0)
|
| 308 |
+
this.blur(this.fA, this.fB, 2.0)
|
| 309 |
+
this.down(this.fA.tex, this.fA.w, this.fA.h, this.fC)
|
| 310 |
+
this.blur(this.fC, this.fD, 1.0)
|
| 311 |
+
this.blur(this.fC, this.fD, 2.0)
|
| 312 |
+
|
| 313 |
+
const p = this.progFinal
|
| 314 |
+
gl.useProgram(p)
|
| 315 |
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
|
| 316 |
+
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight)
|
| 317 |
+
this.bindTex(p, 'scene', this.sceneTex, 0)
|
| 318 |
+
this.bindTex(p, 'bloomA', this.fA.tex, 1)
|
| 319 |
+
this.bindTex(p, 'bloomB', this.fC.tex, 2)
|
| 320 |
+
gl.uniform2f(this.u(p, 'res'), W, H)
|
| 321 |
+
gl.uniform1f(this.u(p, 'time'), pp.time)
|
| 322 |
+
gl.uniform1f(this.u(p, 'flash'), pp.flash)
|
| 323 |
+
gl.uniform3f(this.u(p, 'flashColor'), pp.flashColor[0], pp.flashColor[1], pp.flashColor[2])
|
| 324 |
+
gl.uniform1f(this.u(p, 'aberr'), pp.aberr)
|
| 325 |
+
gl.uniform1f(this.u(p, 'glitch'), pp.glitch)
|
| 326 |
+
gl.uniform1f(this.u(p, 'zoom'), pp.zoom)
|
| 327 |
+
gl.uniform2f(this.u(p, 'shake'), pp.shake[0], pp.shake[1])
|
| 328 |
+
gl.uniform1f(this.u(p, 'bloom'), pp.bloom)
|
| 329 |
+
gl.uniform1f(this.u(p, 'grain'), pp.grain)
|
| 330 |
+
gl.uniform1f(this.u(p, 'vignette'), pp.vignette)
|
| 331 |
+
gl.uniform1f(this.u(p, 'scan'), pp.scan)
|
| 332 |
+
gl.uniform1f(this.u(p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
| 2 |
+
import { caption } from './draw'
|
| 3 |
+
import { Post, type PostParams } from './post'
|
| 4 |
+
import { CUTS, captionAt, sceneAt } from './timeline'
|
| 5 |
+
import type { SceneCtx } from './types'
|
| 6 |
+
import { clamp, hash, noise1, smoothstep } from './util'
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* One renderer = one output canvas. renderFrame(t) is a pure function of t,
|
| 10 |
+
* shared by the live preview, the cover generator and the MP4 exporter.
|
| 11 |
+
*/
|
| 12 |
+
export class Renderer {
|
| 13 |
+
readonly out: HTMLCanvasElement
|
| 14 |
+
private scene: HTMLCanvasElement
|
| 15 |
+
private sctx: CanvasRenderingContext2D
|
| 16 |
+
private scratch: HTMLCanvasElement
|
| 17 |
+
private post: Post | null
|
| 18 |
+
private out2d: CanvasRenderingContext2D | null = null
|
| 19 |
+
private cache = new Map<string, unknown>()
|
| 20 |
+
private warned = false
|
| 21 |
+
W = 0
|
| 22 |
+
H = 0
|
| 23 |
+
|
| 24 |
+
constructor(out?: HTMLCanvasElement) {
|
| 25 |
+
this.out = out ?? document.createElement('canvas')
|
| 26 |
+
this.scene = document.createElement('canvas')
|
| 27 |
+
this.sctx = this.scene.getContext('2d', { alpha: false })!
|
| 28 |
+
this.scratch = document.createElement('canvas')
|
| 29 |
+
this.post = Post.create(this.out)
|
| 30 |
+
if (!this.post) this.out2d = this.out.getContext('2d')
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
get webgl() {
|
| 34 |
+
return !!this.post
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
setSize(W: number, H: number) {
|
| 38 |
+
W = Math.max(2, Math.round(W / 2) * 2)
|
| 39 |
+
H = Math.max(2, Math.round(H / 2) * 2)
|
| 40 |
+
if (W === this.W && H === this.H) return
|
| 41 |
+
this.W = W
|
| 42 |
+
this.H = H
|
| 43 |
+
for (const c of [this.out, this.scene, this.scratch]) {
|
| 44 |
+
c.width = W
|
| 45 |
+
c.height = H
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
render(tIn: number) {
|
| 50 |
+
const t = clamp(Number.isFinite(tIn) ? tIn : 0, 0, DURATION)
|
| 51 |
+
const { W, H } = this
|
| 52 |
+
const a = analyse(t)
|
| 53 |
+
const sc = sceneAt(t)
|
| 54 |
+
const ctx = this.sctx
|
| 55 |
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
| 56 |
+
ctx.globalAlpha = 1
|
| 57 |
+
ctx.globalCompositeOperation = 'source-over'
|
| 58 |
+
ctx.shadowBlur = 0
|
| 59 |
+
ctx.shadowColor = 'transparent'
|
| 60 |
+
ctx.filter = 'none'
|
| 61 |
+
const s: SceneCtx = {
|
| 62 |
+
ctx,
|
| 63 |
+
W,
|
| 64 |
+
H,
|
| 65 |
+
P: H > W,
|
| 66 |
+
u: Math.min(W, H) / 1000,
|
| 67 |
+
t,
|
| 68 |
+
lt: t - sc.start,
|
| 69 |
+
dur: sc.end - sc.start,
|
| 70 |
+
a,
|
| 71 |
+
scratch: this.scratch,
|
| 72 |
+
cache: this.cache,
|
| 73 |
+
}
|
| 74 |
+
ctx.save()
|
| 75 |
+
try {
|
| 76 |
+
sc.fn(s)
|
| 77 |
+
} catch (e) {
|
| 78 |
+
// never let a single drawing glitch break playback / export
|
| 79 |
+
if (!this.warned) console.warn('scene error', sc.id, t, e)
|
| 80 |
+
this.warned = true
|
| 81 |
+
}
|
| 82 |
+
ctx.restore()
|
| 83 |
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
| 84 |
+
ctx.globalAlpha = 1
|
| 85 |
+
ctx.shadowBlur = 0
|
| 86 |
+
const cap = captionAt(t)
|
| 87 |
+
if (cap) caption(ctx, W, H, cap.text, t - cap.start, cap.end - cap.start, s.P)
|
| 88 |
+
|
| 89 |
+
const pp = postParams(t, a)
|
| 90 |
+
if (this.post) {
|
| 91 |
+
this.post.render(this.scene, pp)
|
| 92 |
+
} else if (this.out2d) {
|
| 93 |
+
this.out2d.globalAlpha = 1
|
| 94 |
+
this.out2d.drawImage(this.scene, 0, 0)
|
| 95 |
+
if (pp.flash > 0.01) {
|
| 96 |
+
this.out2d.fillStyle = `rgba(255,255,255,${pp.flash})`
|
| 97 |
+
this.out2d.fillRect(0, 0, W, H)
|
| 98 |
+
}
|
| 99 |
+
if (pp.black > 0) {
|
| 100 |
+
this.out2d.fillStyle = `rgba(0,0,0,${pp.black})`
|
| 101 |
+
this.out2d.fillRect(0, 0, W, H)
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
export function postParams(t: number, a: AudioFrame): PostParams {
|
| 108 |
+
let flash = 0
|
| 109 |
+
let glitch = 0
|
| 110 |
+
for (const c of CUTS) {
|
| 111 |
+
const d = t - c
|
| 112 |
+
if (d >= 0 && d < 0.6) {
|
| 113 |
+
const big = Math.abs(c - DROP1) < 0.01 || Math.abs(c - DROP2) < 0.01
|
| 114 |
+
flash = Math.max(flash, Math.exp(-d * (big ? 5 : 11)) * (big ? 1 : 0.55))
|
| 115 |
+
if (d < 0.14) glitch = Math.max(glitch, big ? 0.9 : 0.5)
|
| 116 |
+
}
|
| 117 |
+
if (d < 0 && d > -0.06) glitch = Math.max(glitch, 0.35)
|
| 118 |
+
}
|
| 119 |
+
// white-out build into Drop 1
|
| 120 |
+
if (t < DROP1 && t > DROP1 - 0.7) flash = Math.max(flash, smoothstep(DROP1 - 0.7, DROP1, t) * 0.9)
|
| 121 |
+
if (a.drop && hash(a.beat * 5.1) > 0.78 && a.beatPhase < 0.16) glitch = Math.max(glitch, 0.65)
|
| 122 |
+
// tension glitches right before Drop 2
|
| 123 |
+
if (t > DROP2 - 2.3 && t < DROP2) glitch = Math.max(glitch, hash(Math.floor(t * 14)) > 0.6 ? 0.45 : 0)
|
| 124 |
+
const k = a.drop ? a.kick : 0
|
| 125 |
+
return {
|
| 126 |
+
time: t,
|
| 127 |
+
flash: clamp(flash),
|
| 128 |
+
flashColor: [1, 0.97, 0.94],
|
| 129 |
+
aberr: 0.0012 + (a.drop ? k * 0.006 : a.high * 0.0014),
|
| 130 |
+
glitch,
|
| 131 |
+
zoom: 1 + k * 0.04,
|
| 132 |
+
shake: [noise1(t * 37, 1) * 0.005 * k, noise1(t * 41, 2) * 0.005 * k],
|
| 133 |
+
bloom: 0.85 + k * 0.35,
|
| 134 |
+
grain: 0.065,
|
| 135 |
+
vignette: 0.55,
|
| 136 |
+
scan: 0.05,
|
| 137 |
+
black: t >= 144.22 ? 1 : 1 - smoothstep(0, 0.8, t),
|
| 138 |
+
seed: Math.floor(t * 24) % 97,
|
| 139 |
+
}
|
| 140 |
+
}
|
src/mv/engine/scenesA.ts
ADDED
|
@@ -0,0 +1,703 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { BAR, BEAT, DROP1, bandAt, beatTime } from './audio'
|
| 2 |
+
import {
|
| 3 |
+
figureBack,
|
| 4 |
+
fogBand,
|
| 5 |
+
glowBlob,
|
| 6 |
+
halftone,
|
| 7 |
+
lightCone,
|
| 8 |
+
marquee,
|
| 9 |
+
neonSign,
|
| 10 |
+
neonText,
|
| 11 |
+
rain,
|
| 12 |
+
skyline,
|
| 13 |
+
speedLines,
|
| 14 |
+
splashes,
|
| 15 |
+
splitText,
|
| 16 |
+
streetLamp,
|
| 17 |
+
vGradient,
|
| 18 |
+
walker,
|
| 19 |
+
wetReflection,
|
| 20 |
+
} from './draw'
|
| 21 |
+
import { camera, resetCam, type SceneCtx } from './types'
|
| 22 |
+
import {
|
| 23 |
+
FONT,
|
| 24 |
+
PALETTE,
|
| 25 |
+
clamp,
|
| 26 |
+
easeInOutCubic,
|
| 27 |
+
easeOutBack,
|
| 28 |
+
easeOutCubic,
|
| 29 |
+
easeOutExpo,
|
| 30 |
+
fbm,
|
| 31 |
+
flicker,
|
| 32 |
+
fract,
|
| 33 |
+
hash,
|
| 34 |
+
hash2,
|
| 35 |
+
lerp,
|
| 36 |
+
noise1,
|
| 37 |
+
rgba,
|
| 38 |
+
smoothstep,
|
| 39 |
+
} from './util'
|
| 40 |
+
|
| 41 |
+
const SIGN_WORDS = ['旅馆', '当铺', '通宵', '麻将', '烧腊', '冰室', '粥', '按摩', '影院', '理发', '茶餐厅', '桌球', '夜宵', '酒', '当', '典当', '药房', '电玩']
|
| 42 |
+
const SIGN_COLORS = [PALETTE.red, PALETTE.cyan, PALETTE.sodium, PALETTE.violet, PALETTE.teal, '#ff5fa2']
|
| 43 |
+
|
| 44 |
+
const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
|
| 45 |
+
|
| 46 |
+
// =====================================================================
|
| 47 |
+
// S1 — 开场·霓虹点亮 (0 – 9s)
|
| 48 |
+
// =====================================================================
|
| 49 |
+
export function sIgnite(s: SceneCtx) {
|
| 50 |
+
const { ctx, W, H, P, lt, u, t } = s
|
| 51 |
+
// wet brick wall
|
| 52 |
+
vGradient(ctx, 0, 0, W, H, [
|
| 53 |
+
[0, '#040509'],
|
| 54 |
+
[0.6, '#080a10'],
|
| 55 |
+
[1, '#030406'],
|
| 56 |
+
])
|
| 57 |
+
ctx.fillStyle = 'rgba(160,180,210,0.025)'
|
| 58 |
+
const bh = u * 34
|
| 59 |
+
for (let r = 0; r * bh < H; r++) {
|
| 60 |
+
ctx.fillRect(0, r * bh, W, Math.max(1, u * 1.5))
|
| 61 |
+
const off = r % 2 ? 0 : u * 60
|
| 62 |
+
for (let x = off; x < W; x += u * 120) ctx.fillRect(x, r * bh, Math.max(1, u * 1.5), bh)
|
| 63 |
+
}
|
| 64 |
+
const groundY = P ? H * 0.74 : H * 0.76
|
| 65 |
+
const zoom = 1 + lt * 0.014
|
| 66 |
+
camera(s, zoom, W / 2, H * 0.47)
|
| 67 |
+
|
| 68 |
+
const size = P ? Math.min(W * 0.46, H * 0.21) : Math.min(W * 0.27, H * 0.42)
|
| 69 |
+
const cy = P ? H * 0.4 : H * 0.42
|
| 70 |
+
const pos: [number, number][] = P
|
| 71 |
+
? [
|
| 72 |
+
[W / 2, cy - size * 0.55],
|
| 73 |
+
[W / 2, cy + size * 0.55],
|
| 74 |
+
]
|
| 75 |
+
: [
|
| 76 |
+
[W / 2 - size * 0.56, cy],
|
| 77 |
+
[W / 2 + size * 0.56, cy],
|
| 78 |
+
]
|
| 79 |
+
const buzz = 0.9 + 0.1 * hash(Math.floor(t * 40))
|
| 80 |
+
const lit = (start: number, end: number, seed: number) => {
|
| 81 |
+
if (lt < start) return 0
|
| 82 |
+
if (lt < end) return flicker(lt, seed, 16) * smoothstep(start, end, lt + 0.3)
|
| 83 |
+
return buzz
|
| 84 |
+
}
|
| 85 |
+
let on1 = lit(1.0, 2.1, 1)
|
| 86 |
+
let on2 = lit(2.6, 3.5, 2)
|
| 87 |
+
if (lt > 8.2) {
|
| 88 |
+
const f = flicker(lt, 9, 20)
|
| 89 |
+
on1 *= f
|
| 90 |
+
on2 *= f
|
| 91 |
+
}
|
| 92 |
+
// mounting plate
|
| 93 |
+
ctx.fillStyle = 'rgba(12,10,14,0.9)'
|
| 94 |
+
const plateW = P ? size * 1.45 : size * 2.5
|
| 95 |
+
const plateH = P ? size * 2.5 : size * 1.4
|
| 96 |
+
ctx.fillRect(W / 2 - plateW / 2, cy - plateH / 2, plateW, plateH)
|
| 97 |
+
ctx.strokeStyle = 'rgba(80,70,80,0.35)'
|
| 98 |
+
ctx.lineWidth = u * 2
|
| 99 |
+
ctx.strokeRect(W / 2 - plateW / 2, cy - plateH / 2, plateW, plateH)
|
| 100 |
+
glowBlob(ctx, W / 2, cy, size * 2.6, PALETTE.red, 0.22 * Math.max(on1, on2))
|
| 101 |
+
neonText(ctx, '黑', pos[0][0], pos[0][1], size, PALETTE.red, on1, { tube: true, blur: 0.4 })
|
| 102 |
+
neonText(ctx, '街', pos[1][0], pos[1][1], size, PALETTE.red, on2, { tube: true, blur: 0.4 })
|
| 103 |
+
|
| 104 |
+
// BLACK STREET typed on
|
| 105 |
+
const sub = 'BLACK STREET'
|
| 106 |
+
const typed = Math.floor(clamp((lt - 4.2) / 1.4) * sub.length)
|
| 107 |
+
if (typed > 0) {
|
| 108 |
+
const sy = P ? cy + size * 1.55 : cy + size * 0.95
|
| 109 |
+
const fs = P ? size * 0.26 : size * 0.22
|
| 110 |
+
ctx.save()
|
| 111 |
+
ctx.font = `${fs}px ${FONT.latin}`
|
| 112 |
+
const full = ctx.measureText(sub.split('').join(' ')).width
|
| 113 |
+
ctx.restore()
|
| 114 |
+
const str = sub.slice(0, typed).split('').join(' ')
|
| 115 |
+
neonText(ctx, str, W / 2 - full / 2, sy, fs, PALETTE.cyan, lt > 8.2 ? on1 : buzz, { font: FONT.latin, align: 'left', blur: 0.5 })
|
| 116 |
+
}
|
| 117 |
+
// credit line
|
| 118 |
+
if (lt > 5.8) {
|
| 119 |
+
const a = smoothstep(5.8, 6.8, lt) * (1 - smoothstep(8.4, 9, lt))
|
| 120 |
+
ctx.save()
|
| 121 |
+
ctx.globalAlpha = a
|
| 122 |
+
ctx.font = `${(P ? W : H) * 0.022}px ${FONT.black}`
|
| 123 |
+
ctx.textAlign = 'center'
|
| 124 |
+
ctx.fillStyle = PALETTE.bone
|
| 125 |
+
ctx.fillText('DJ鐘董 ·《黑街》DJ葱姜蒜进行曲', W / 2, P ? cy + size * 1.95 : cy + size * 1.25)
|
| 126 |
+
ctx.restore()
|
| 127 |
+
}
|
| 128 |
+
// dripping pipe on the left + small sign
|
| 129 |
+
ctx.fillStyle = '#0b0c10'
|
| 130 |
+
ctx.fillRect(W * 0.08, 0, u * 16, groundY)
|
| 131 |
+
neonSign(ctx, W * (P ? 0.78 : 0.86), H * 0.18, u * 60, u * 170, '旅馆', PALETTE.cyan, lt > 3.8 ? flicker(t, 4, 6) : 0, true)
|
| 132 |
+
// ground
|
| 133 |
+
resetCam(s)
|
| 134 |
+
ctx.fillStyle = '#050608'
|
| 135 |
+
ctx.fillRect(0, groundY, W, H - groundY)
|
| 136 |
+
wetReflection(ctx, s.scratch, W, H, groundY, t, 0.5, u * 4)
|
| 137 |
+
splashes(ctx, W, groundY + u * 10, H, t, Math.floor(40 * area(s)) + 10, '#9fb6c8', 0.25, u)
|
| 138 |
+
rain(ctx, W, H, t, { count: Math.floor(240 * area(s)) + 60, speed: H * 1.6, len: u * 60, slant: 0.1, color: '#a9c2d6', alpha: 0.22, width: Math.max(1, u * 1.4) })
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// =====================================================================
|
| 142 |
+
// S2 — 雨夜长街 (9 – 24s)
|
| 143 |
+
// =====================================================================
|
| 144 |
+
export function sStreet(s: SceneCtx) {
|
| 145 |
+
const { ctx, W, H, P, lt, u, t, a } = s
|
| 146 |
+
const groundY = P ? H * 0.8 : H * 0.78
|
| 147 |
+
const v = u * (P ? 70 : 95)
|
| 148 |
+
const scroll = lt * v
|
| 149 |
+
// camera shots
|
| 150 |
+
let zoom = 1
|
| 151 |
+
let cx = W / 2
|
| 152 |
+
let cy = H / 2
|
| 153 |
+
const wx = P ? W * 0.5 : W * 0.42
|
| 154 |
+
const wh = P ? H * 0.2 : H * 0.3
|
| 155 |
+
if (lt >= 7.5 && lt < 11.4) {
|
| 156 |
+
const k = easeOutCubic((lt - 7.5) / 0.6)
|
| 157 |
+
zoom = lerp(1, P ? 1.6 : 1.75, k) + (lt - 7.5) * 0.02
|
| 158 |
+
cx = lerp(W / 2, wx + wh * 0.1, k)
|
| 159 |
+
cy = lerp(H / 2, groundY - wh * 0.62, k)
|
| 160 |
+
} else if (lt >= 11.4) {
|
| 161 |
+
const k = easeInOutCubic((lt - 11.4) / 3.6)
|
| 162 |
+
zoom = 1.05
|
| 163 |
+
cx = W / 2
|
| 164 |
+
cy = H / 2 - k * H * 0.22
|
| 165 |
+
}
|
| 166 |
+
cx += fbm(t * 0.4, 1) * u * 6
|
| 167 |
+
cy += fbm(t * 0.5, 2) * u * 5
|
| 168 |
+
|
| 169 |
+
resetCam(s)
|
| 170 |
+
vGradient(ctx, 0, 0, W, H, [
|
| 171 |
+
[0, '#060a12'],
|
| 172 |
+
[0.5, '#14243a'],
|
| 173 |
+
[0.8, '#2c3e52'],
|
| 174 |
+
[1, '#1a2430'],
|
| 175 |
+
])
|
| 176 |
+
camera(s, zoom, cx, cy)
|
| 177 |
+
const ext = W * 0.5
|
| 178 |
+
// sky glow & far skyline
|
| 179 |
+
glowBlob(ctx, W * 0.7, groundY - H * 0.25, W * 0.8, PALETTE.amber, 0.16)
|
| 180 |
+
glowBlob(ctx, W * 0.2, groundY - H * 0.35, W * 0.6, PALETTE.cyan, 0.08)
|
| 181 |
+
skyline(ctx, { W: W + ext, seed: 11, baseY: groundY - H * 0.12, scroll: scroll * 0.12, cell: u * 70, minH: H * 0.18, maxH: H * (P ? 0.6 : 0.48), color: '#0c1622', t, density: 0.1, winAlpha: 0.4 })
|
| 182 |
+
fogBand(ctx, W + ext, groundY - H * 0.14, H * 0.1, PALETTE.steel, 0.5)
|
| 183 |
+
// mid layer with vertical neon signs
|
| 184 |
+
const midCell = u * 150
|
| 185 |
+
const midScroll = scroll * 0.42
|
| 186 |
+
skyline(ctx, { W: W + ext, seed: 23, baseY: groundY - H * 0.02, scroll: midScroll, cell: midCell, minH: H * 0.3, maxH: H * (P ? 0.75 : 0.62), color: '#080c13', t, density: 0.22, winAlpha: 0.6 })
|
| 187 |
+
const k0 = Math.floor(midScroll / midCell) - 1
|
| 188 |
+
for (let k = k0; k < k0 + Math.ceil((W + ext) / midCell) + 2; k++) {
|
| 189 |
+
if (hash(k * 5.7) < 0.4) continue
|
| 190 |
+
const word = SIGN_WORDS[Math.floor(hash(k * 2.3) * SIGN_WORDS.length)]
|
| 191 |
+
const col = SIGN_COLORS[Math.floor(hash(k * 8.1) * SIGN_COLORS.length)]
|
| 192 |
+
const n = Array.from(word).length
|
| 193 |
+
const sw = u * 50
|
| 194 |
+
const sh = sw * n * 1.05 + sw * 0.4
|
| 195 |
+
const x = k * midCell - midScroll + midCell * (0.55 + 0.3 * hash(k))
|
| 196 |
+
const y = groundY - H * (0.3 + 0.22 * hash(k * 3.9)) - sh * 0.5
|
| 197 |
+
const on = hash(k * 4.4) > 0.8 ? flicker(t, k, 10) : 0.85 + 0.15 * a.mid
|
| 198 |
+
neonSign(ctx, x, y, sw, sh, word, col, on, true)
|
| 199 |
+
}
|
| 200 |
+
// near shopfronts
|
| 201 |
+
const nearCell = u * 270
|
| 202 |
+
const kk0 = Math.floor(scroll / nearCell) - 1
|
| 203 |
+
for (let k = kk0; k < kk0 + Math.ceil((W + ext) / nearCell) + 2; k++) {
|
| 204 |
+
const x = k * nearCell - scroll
|
| 205 |
+
const top = groundY - u * 300
|
| 206 |
+
ctx.fillStyle = '#06080c'
|
| 207 |
+
ctx.fillRect(x, top, nearCell + 1, groundY - top)
|
| 208 |
+
const type = hash(k * 1.9)
|
| 209 |
+
const doorX = x + nearCell * 0.1
|
| 210 |
+
const doorW = nearCell * 0.8
|
| 211 |
+
const doorTop = groundY - u * 175
|
| 212 |
+
if (type < 0.45) {
|
| 213 |
+
// rolling shutter
|
| 214 |
+
ctx.fillStyle = '#0f1218'
|
| 215 |
+
ctx.fillRect(doorX, doorTop, doorW, groundY - doorTop)
|
| 216 |
+
ctx.fillStyle = 'rgba(120,140,160,0.08)'
|
| 217 |
+
for (let y = doorTop; y < groundY; y += u * 7) ctx.fillRect(doorX, y, doorW, Math.max(1, u * 1.5))
|
| 218 |
+
// graffiti tag
|
| 219 |
+
if (type < 0.2) {
|
| 220 |
+
ctx.save()
|
| 221 |
+
ctx.font = `${u * 46}px ${FONT.neon}`
|
| 222 |
+
ctx.fillStyle = rgba(PALETTE.red, 0.35)
|
| 223 |
+
ctx.textAlign = 'center'
|
| 224 |
+
ctx.fillText('黑街', doorX + doorW / 2, doorTop + u * 90)
|
| 225 |
+
ctx.restore()
|
| 226 |
+
}
|
| 227 |
+
} else {
|
| 228 |
+
// lit shop window
|
| 229 |
+
const g = ctx.createLinearGradient(0, doorTop, 0, groundY)
|
| 230 |
+
const warm = type > 0.75
|
| 231 |
+
g.addColorStop(0, warm ? '#7a4520' : '#1a5560')
|
| 232 |
+
g.addColorStop(1, warm ? '#f0a050' : '#45c0c8')
|
| 233 |
+
ctx.fillStyle = g
|
| 234 |
+
ctx.globalAlpha = 0.8 + 0.2 * flicker(t, k + 50, 3)
|
| 235 |
+
ctx.fillRect(doorX, doorTop, doorW, groundY - doorTop)
|
| 236 |
+
ctx.globalAlpha = 1
|
| 237 |
+
glowBlob(ctx, doorX + doorW / 2, groundY, doorW * 0.9, warm ? PALETTE.sodium : PALETTE.cyan, 0.3)
|
| 238 |
+
ctx.fillStyle = '#06080c'
|
| 239 |
+
ctx.fillRect(doorX + doorW * 0.48, doorTop, u * 4, groundY - doorTop)
|
| 240 |
+
ctx.fillRect(doorX, doorTop + (groundY - doorTop) * 0.45, doorW, u * 3)
|
| 241 |
+
}
|
| 242 |
+
// horizontal sign
|
| 243 |
+
const word = SIGN_WORDS[Math.floor(hash(k * 6.3 + 1) * SIGN_WORDS.length)]
|
| 244 |
+
const col = SIGN_COLORS[Math.floor(hash(k * 3.7 + 2) * SIGN_COLORS.length)]
|
| 245 |
+
neonSign(ctx, x + nearCell * 0.12, top + u * 26, nearCell * 0.76, u * 60, word, col, hash(k * 9.1) > 0.85 ? flicker(t, k, 8) : 1, false)
|
| 246 |
+
// AC unit
|
| 247 |
+
ctx.fillStyle = '#10131a'
|
| 248 |
+
ctx.fillRect(x + nearCell * 0.7, top - u * 40, u * 50, u * 36)
|
| 249 |
+
if (k % 3 === 0) streetLamp(ctx, x + nearCell * 0.05, groundY, u * 330, 0.85 + 0.15 * flicker(t, k + 99, 5))
|
| 250 |
+
}
|
| 251 |
+
// walker
|
| 252 |
+
const phase = (s.a.beatPos / 2) % 1
|
| 253 |
+
walker(ctx, wx, groundY + u * 2, wh, fract(phase), { rim: PALETTE.cyan, rimSide: -1, coat: 0.7 })
|
| 254 |
+
// ground
|
| 255 |
+
ctx.fillStyle = '#05070a'
|
| 256 |
+
ctx.fillRect(-ext, groundY, W + ext * 3, H)
|
| 257 |
+
resetCam(s)
|
| 258 |
+
const gy = (groundY - cy) * zoom + H / 2
|
| 259 |
+
if (gy < H - 2) wetReflection(ctx, s.scratch, W, H, gy, t, 0.55, u * 3)
|
| 260 |
+
if (gy < H) splashes(ctx, W, gy + u * 6, H, t, Math.floor(50 * area(s)) + 10, '#9fb6c8', 0.25, u)
|
| 261 |
+
// foreground poles
|
| 262 |
+
const poleCell = u * 1100
|
| 263 |
+
const ps = scroll * 2.2
|
| 264 |
+
for (let k = Math.floor(ps / poleCell) - 1; k < Math.floor(ps / poleCell) + 3; k++) {
|
| 265 |
+
const x = k * poleCell - ps + poleCell * 0.3
|
| 266 |
+
ctx.fillStyle = '#020203'
|
| 267 |
+
ctx.fillRect(x, 0, u * 46, H)
|
| 268 |
+
}
|
| 269 |
+
rain(ctx, W, H, t, { count: Math.floor(420 * area(s)) + 80, speed: H * 1.7, len: u * 70, slant: 0.14, color: '#a9c2d6', alpha: 0.28, width: Math.max(1, u * 1.5) })
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
// =====================================================================
|
| 273 |
+
// S3 — 蓄力·隧道 (24 – 38.15s)
|
| 274 |
+
// =====================================================================
|
| 275 |
+
export function sTunnel(s: SceneCtx) {
|
| 276 |
+
const { ctx, W, H, P, lt, u, t, a, dur } = s
|
| 277 |
+
const p = lt / dur
|
| 278 |
+
const travel = 1.4 * lt + 0.028 * lt * lt * lt
|
| 279 |
+
const vx = W / 2 + Math.sin(lt * 0.55) * W * 0.04
|
| 280 |
+
const vy = H * 0.47 + Math.cos(lt * 0.4) * H * 0.02
|
| 281 |
+
{
|
| 282 |
+
const R = Math.max(W, H) * 0.85
|
| 283 |
+
const g = ctx.createRadialGradient(vx, vy, 0, vx, vy, R)
|
| 284 |
+
g.addColorStop(0, p > 0.75 ? '#c9a27a' : '#6a4626')
|
| 285 |
+
g.addColorStop(0.18, '#2a2230')
|
| 286 |
+
g.addColorStop(0.55, '#121826')
|
| 287 |
+
g.addColorStop(1, '#05070c')
|
| 288 |
+
ctx.fillStyle = g
|
| 289 |
+
ctx.fillRect(0, 0, W, H)
|
| 290 |
+
}
|
| 291 |
+
const N = 26
|
| 292 |
+
const baseW = P ? W * 0.62 : W * 0.5
|
| 293 |
+
const baseH = P ? H * 0.42 : H * 0.6
|
| 294 |
+
const fr = fract(travel)
|
| 295 |
+
const ringBase = Math.floor(travel)
|
| 296 |
+
glowBlob(ctx, vx, vy, Math.min(W, H) * (0.25 + p * 0.5), p > 0.7 ? '#ffffff' : PALETTE.sodium, 0.18 + p * 0.5)
|
| 297 |
+
for (let i = N; i >= 1; i--) {
|
| 298 |
+
const z = i - fr
|
| 299 |
+
if (z <= 0.15) continue
|
| 300 |
+
const sc = 1.6 / z
|
| 301 |
+
const hw = baseW * sc
|
| 302 |
+
const hh = baseH * sc
|
| 303 |
+
const ri = ringBase + i
|
| 304 |
+
const fade = clamp(1 - z / N) * clamp(z / 0.6)
|
| 305 |
+
const isRed = ri % 6 === 0
|
| 306 |
+
const isLamp = ri % 2 === 0
|
| 307 |
+
// tunnel segment walls
|
| 308 |
+
ctx.globalAlpha = fade
|
| 309 |
+
ctx.strokeStyle = isRed ? PALETTE.red : rgba('#8fa3c0', 0.75)
|
| 310 |
+
ctx.lineWidth = Math.max(1, (isRed ? 7 : 3) * u * sc)
|
| 311 |
+
if (isRed) {
|
| 312 |
+
ctx.shadowColor = PALETTE.red
|
| 313 |
+
ctx.shadowBlur = u * 30 * sc
|
| 314 |
+
}
|
| 315 |
+
ctx.strokeRect(vx - hw, vy - hh, hw * 2, hh * 2)
|
| 316 |
+
ctx.shadowBlur = 0
|
| 317 |
+
if (isLamp) {
|
| 318 |
+
ctx.fillStyle = PALETTE.sodium
|
| 319 |
+
const lw = hw * 0.18
|
| 320 |
+
ctx.fillRect(vx - lw, vy - hh - u * 2 * sc, lw * 2, Math.max(1, u * 6 * sc))
|
| 321 |
+
ctx.fillRect(vx - hw - u * 2 * sc, vy - hh * 0.2, Math.max(1, u * 5 * sc), hh * 0.4)
|
| 322 |
+
ctx.fillRect(vx + hw - u * 3 * sc, vy - hh * 0.2, Math.max(1, u * 5 * sc), hh * 0.4)
|
| 323 |
+
if (z < 9) {
|
| 324 |
+
glowBlob(ctx, vx, vy - hh, hw * 0.35, PALETTE.sodium, 0.35 * fade)
|
| 325 |
+
glowBlob(ctx, vx - hw, vy, hh * 0.3, PALETTE.sodium, 0.25 * fade)
|
| 326 |
+
glowBlob(ctx, vx + hw, vy, hh * 0.3, PALETTE.sodium, 0.25 * fade)
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
// floor dashes
|
| 330 |
+
ctx.fillStyle = rgba(PALETTE.bone, 0.6)
|
| 331 |
+
ctx.fillRect(vx - u * 4 * sc, vy + hh - u * 2 * sc, u * 8 * sc, Math.max(1, u * 3 * sc))
|
| 332 |
+
}
|
| 333 |
+
ctx.globalAlpha = 1
|
| 334 |
+
// perspective rails
|
| 335 |
+
ctx.strokeStyle = 'rgba(120,140,170,0.18)'
|
| 336 |
+
ctx.lineWidth = Math.max(1, u * 2)
|
| 337 |
+
ctx.beginPath()
|
| 338 |
+
for (const [dx, dy] of [
|
| 339 |
+
[-1, -1],
|
| 340 |
+
[1, -1],
|
| 341 |
+
[-1, 1],
|
| 342 |
+
[1, 1],
|
| 343 |
+
]) {
|
| 344 |
+
ctx.moveTo(vx, vy)
|
| 345 |
+
ctx.lineTo(vx + dx * baseW * 8, vy + dy * baseH * 8)
|
| 346 |
+
}
|
| 347 |
+
ctx.stroke()
|
| 348 |
+
speedLines(ctx, vx, vy, Math.max(W, H) * 0.8, t, 90, '#ffffff', 0.04 + p * p * 0.25, 0.25)
|
| 349 |
+
// figure
|
| 350 |
+
const fh = P ? H * 0.26 : H * 0.42
|
| 351 |
+
figureBack(ctx, W / 2, H * 1.02, fh, Math.sin(lt * 2.2), { rim: rgba(PALETTE.sodium, 0.8) })
|
| 352 |
+
// countdown on the last beats before the drop
|
| 353 |
+
const bp = (t - DROP1) / BEAT
|
| 354 |
+
if (bp >= -3 && bp < 0) {
|
| 355 |
+
const n = Math.ceil(-bp)
|
| 356 |
+
const ph = fract(bp)
|
| 357 |
+
const size = Math.min(W, H) * (0.5 + 0.25 * (1 - ph))
|
| 358 |
+
ctx.save()
|
| 359 |
+
ctx.globalAlpha = 1 - ph * 0.6
|
| 360 |
+
splitText(ctx, String(n), W / 2, H * 0.46, size, FONT.latin, '#ffffff', u * 10 * (1 - ph))
|
| 361 |
+
ctx.restore()
|
| 362 |
+
}
|
| 363 |
+
void a
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
// =====================================================================
|
| 367 |
+
// S4 — Drop1·霓虹爆裂 (38.15 – 56.35s), 8 shots × 1 bar
|
| 368 |
+
// =====================================================================
|
| 369 |
+
const POSTER_WORDS: string[][] = [
|
| 370 |
+
['黑', '街', '黑街', 'BLACK STREET'],
|
| 371 |
+
['夜', '行', '夜行者', 'NIGHT WALKER'],
|
| 372 |
+
]
|
| 373 |
+
const GRID_CHARS = ['黑', '街', '夜', '行', '王', '灯', '雨', '火', '醒', '狂', '燃', '跳', '闪', '冲', '霓', '虹']
|
| 374 |
+
|
| 375 |
+
export function sDrop1(s: SceneCtx) {
|
| 376 |
+
const { lt } = s
|
| 377 |
+
const shot = Math.min(7, Math.floor(lt / BAR))
|
| 378 |
+
const variant = shot >= 4 ? 1 : 0
|
| 379 |
+
const kind = shot % 4
|
| 380 |
+
if (kind === 0) posterShot(s, variant)
|
| 381 |
+
else if (kind === 1) eqShot(s, variant)
|
| 382 |
+
else if (kind === 2) runnerShot(s, variant)
|
| 383 |
+
else gridShot(s, variant)
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function posterShot(s: SceneCtx, variant: number) {
|
| 387 |
+
const { ctx, W, H, P, u, t, a } = s
|
| 388 |
+
const bi = ((a.beat % 4) + 4) % 4
|
| 389 |
+
const red = bi % 2 === 0
|
| 390 |
+
const bg = red ? '#d0102e' : '#050608'
|
| 391 |
+
const fg = red ? '#050608' : '#f4ece0'
|
| 392 |
+
ctx.fillStyle = bg
|
| 393 |
+
ctx.fillRect(0, 0, W, H)
|
| 394 |
+
// halftone shading
|
| 395 |
+
halftone(ctx, W, H, u * 26, red ? 'rgba(0,0,0,0.22)' : 'rgba(255,45,85,0.22)', (x, y) => clamp(1.2 - Math.hypot(x - 0.5, (y - 0.5) * (H / W)) * 2.2))
|
| 396 |
+
const words = POSTER_WORDS[variant]
|
| 397 |
+
const word = words[bi]
|
| 398 |
+
const pop = easeOutBack(clamp(a.beatPhase / 0.25))
|
| 399 |
+
const jx = (hash(a.beat * 3.3) - 0.5) * u * 24 * a.kick
|
| 400 |
+
const jy = (hash(a.beat * 7.7) - 0.5) * u * 24 * a.kick
|
| 401 |
+
const isLatin = /[A-Z]/.test(word)
|
| 402 |
+
ctx.save()
|
| 403 |
+
ctx.translate(W / 2 + jx, H / 2 + jy)
|
| 404 |
+
ctx.scale(lerp(1.25, 1, pop), lerp(1.25, 1, pop))
|
| 405 |
+
if (isLatin) {
|
| 406 |
+
const parts = word.split(' ')
|
| 407 |
+
const size = P ? W * 0.3 : H * 0.36
|
| 408 |
+
parts.forEach((p, i) => splitText(ctx, p, 0, (i - (parts.length - 1) / 2) * size * 0.95, size, FONT.latin, fg, u * 10 * a.kick))
|
| 409 |
+
} else {
|
| 410 |
+
const chars = Array.from(word)
|
| 411 |
+
if (P && chars.length > 1) {
|
| 412 |
+
const size = Math.min(W * 0.62, (H * 0.8) / chars.length)
|
| 413 |
+
chars.forEach((c, i) => splitText(ctx, c, 0, (i - (chars.length - 1) / 2) * size * 1.02, size, FONT.black, fg, u * 12 * a.kick))
|
| 414 |
+
} else {
|
| 415 |
+
const size = chars.length === 1 ? Math.min(W, H) * 0.85 : Math.min((W * 0.86) / chars.length, H * 0.7)
|
| 416 |
+
splitText(ctx, word, 0, 0, size, FONT.black, fg, u * 12 * a.kick)
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
ctx.restore()
|
| 420 |
+
// marquees
|
| 421 |
+
const ms = (P ? W : H) * 0.05
|
| 422 |
+
marquee(ctx, 'BLACK STREET · 黑街 · 105.5 BPM · ', ms * 0.9, W, ms, t * u * 400, fg)
|
| 423 |
+
marquee(ctx, 'NIGHT WALKER · 夜行者 · DJ葱姜蒜进行曲 · ', H - ms * 0.9, W, ms, -t * u * 400, fg)
|
| 424 |
+
// corner badges
|
| 425 |
+
ctx.save()
|
| 426 |
+
ctx.font = `${ms * 0.55}px ${FONT.latin}`
|
| 427 |
+
ctx.fillStyle = fg
|
| 428 |
+
ctx.textAlign = 'left'
|
| 429 |
+
ctx.fillText(`DROP 01 / ${String(s.t.toFixed(2)).padStart(6, '0')}`, ms * 0.6, ms * 2.4)
|
| 430 |
+
ctx.textAlign = 'right'
|
| 431 |
+
ctx.fillText('黑街 ● REC', W - ms * 0.6, ms * 2.4)
|
| 432 |
+
ctx.restore()
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
function eqShot(s: SceneCtx, variant: number) {
|
| 436 |
+
const { ctx, W, H, P, u, t, a, lt } = s
|
| 437 |
+
const horizon = P ? H * 0.66 : H * 0.7
|
| 438 |
+
vGradient(ctx, 0, 0, W, horizon, [
|
| 439 |
+
[0, '#05030a'],
|
| 440 |
+
[0.6, variant ? '#1a0b30' : '#2a0814'],
|
| 441 |
+
[1, variant ? '#5a1f6a' : '#8a1426'],
|
| 442 |
+
])
|
| 443 |
+
// striped sun
|
| 444 |
+
const sx = W / 2
|
| 445 |
+
const sy = horizon - Math.min(W, H) * 0.05
|
| 446 |
+
const R = Math.min(W, H) * (P ? 0.36 : 0.3) * (1 + a.kick * 0.04)
|
| 447 |
+
ctx.save()
|
| 448 |
+
ctx.beginPath()
|
| 449 |
+
ctx.arc(sx, sy, R, 0, Math.PI * 2)
|
| 450 |
+
ctx.clip()
|
| 451 |
+
vGradient(ctx, sx - R, sy - R, R * 2, R * 2, [
|
| 452 |
+
[0, '#ffd27a'],
|
| 453 |
+
[0.5, '#ff5a3c'],
|
| 454 |
+
[1, '#c4142f'],
|
| 455 |
+
])
|
| 456 |
+
ctx.fillStyle = '#05030a'
|
| 457 |
+
for (let i = 0; i < 9; i++) {
|
| 458 |
+
const yy = sy + R * (0.05 + i * 0.12) + ((lt * u * 40) % (R * 0.12))
|
| 459 |
+
ctx.fillRect(sx - R, yy, R * 2, R * 0.012 * (i + 1))
|
| 460 |
+
}
|
| 461 |
+
ctx.restore()
|
| 462 |
+
glowBlob(ctx, sx, sy, R * 2, PALETTE.red, 0.35)
|
| 463 |
+
// equalizer skyline
|
| 464 |
+
const bands: ('low' | 'mid' | 'high')[] = ['low', 'mid', 'high']
|
| 465 |
+
skyline(ctx, {
|
| 466 |
+
W,
|
| 467 |
+
seed: 41 + variant * 13,
|
| 468 |
+
baseY: horizon,
|
| 469 |
+
scroll: lt * u * 30,
|
| 470 |
+
cell: u * (P ? 70 : 85),
|
| 471 |
+
minH: H * 0.12,
|
| 472 |
+
maxH: H * 0.4,
|
| 473 |
+
color: '#040408',
|
| 474 |
+
t,
|
| 475 |
+
density: 0.18,
|
| 476 |
+
winAlpha: 0.7,
|
| 477 |
+
hMod: (k) => {
|
| 478 |
+
const b = bands[((k % 3) + 3) % 3]
|
| 479 |
+
return 0.45 + 1.1 * bandAt(t - (((k % 5) + 5) % 5) * 0.025, b)
|
| 480 |
+
},
|
| 481 |
+
litMod: (k, row, rows) => {
|
| 482 |
+
const lvl = a.kick
|
| 483 |
+
return 1 - row / rows < lvl * (0.6 + 0.4 * hash(k)) ? 0.9 : 0
|
| 484 |
+
},
|
| 485 |
+
})
|
| 486 |
+
// water
|
| 487 |
+
ctx.fillStyle = '#030306'
|
| 488 |
+
ctx.fillRect(0, horizon, W, H - horizon)
|
| 489 |
+
wetReflection(ctx, s.scratch, W, H, horizon, t, 0.6, u * 6)
|
| 490 |
+
// lightning on some beats
|
| 491 |
+
if (hash(a.beat * 1.7 + variant) > 0.72 && a.beatPhase < 0.12) {
|
| 492 |
+
ctx.fillStyle = 'rgba(220,230,255,0.35)'
|
| 493 |
+
ctx.fillRect(0, 0, W, horizon)
|
| 494 |
+
}
|
| 495 |
+
rain(ctx, W, H, t, { count: Math.floor(200 * area(s)) + 40, speed: H * 2, len: u * 80, slant: 0.2, color: '#ffc0c8', alpha: 0.18, width: Math.max(1, u * 1.4) })
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
function runnerShot(s: SceneCtx, variant: number) {
|
| 499 |
+
const { ctx, W, H, P, u, t, a } = s
|
| 500 |
+
const alt = ((a.beat % 2) + 2) % 2 === 0
|
| 501 |
+
const bgc = variant ? (alt ? '#f2a01c' : '#d0102e') : alt ? '#d0102e' : '#12a6bf'
|
| 502 |
+
const cx = W / 2
|
| 503 |
+
const cy = H * 0.5
|
| 504 |
+
{
|
| 505 |
+
const g = ctx.createRadialGradient(cx, cy, 0, cx, cy, Math.max(W, H) * 0.7)
|
| 506 |
+
g.addColorStop(0, '#fff2e0')
|
| 507 |
+
g.addColorStop(0.25, bgc)
|
| 508 |
+
g.addColorStop(1, '#0a0508')
|
| 509 |
+
ctx.fillStyle = g
|
| 510 |
+
ctx.fillRect(0, 0, W, H)
|
| 511 |
+
}
|
| 512 |
+
halftone(ctx, W, H, u * 22, 'rgba(10,4,8,0.55)', (x, y) => clamp(Math.hypot(x - 0.5, (y - 0.5) * (H / W)) * 2.2 - 0.25) * (0.7 + 0.3 * a.kick))
|
| 513 |
+
speedLines(ctx, cx, cy, Math.max(W, H) * 0.8, t, 120, '#0a0508', 0.35, 0.4)
|
| 514 |
+
// ground streak
|
| 515 |
+
const gy = P ? H * 0.68 : H * 0.8
|
| 516 |
+
ctx.fillStyle = 'rgba(255,255,255,0.12)'
|
| 517 |
+
for (let i = 0; i < 14; i++) {
|
| 518 |
+
const x = fract(hash(i * 3.1) - t * (1.5 + hash(i))) * W * 1.4 - W * 0.2
|
| 519 |
+
ctx.fillRect(x, gy + hash(i) * u * 40, u * (80 + hash(i * 2) * 200), Math.max(1, u * 3))
|
| 520 |
+
}
|
| 521 |
+
const h = P ? H * 0.42 : H * 0.66
|
| 522 |
+
const facing = variant ? -1 : 1
|
| 523 |
+
walker(ctx, cx, gy, h, fract(a.beatPos * 0.5), { run: 1, rim: variant ? PALETTE.red : PALETTE.cyan, rimSide: -facing, facing, coat: 1 })
|
| 524 |
+
// vertical type
|
| 525 |
+
const vs = P ? W * 0.11 : H * 0.12
|
| 526 |
+
const word = variant ? '不回头' : '夜行者'
|
| 527 |
+
Array.from(word).forEach((c, i) => {
|
| 528 |
+
splitText(ctx, c, P ? W * 0.12 : W * 0.86, H * 0.25 + i * vs * 1.1, vs, FONT.black, PALETTE.bone, u * 6 * a.kick)
|
| 529 |
+
})
|
| 530 |
+
ctx.save()
|
| 531 |
+
ctx.translate(P ? W * 0.9 : W * 0.12, H / 2)
|
| 532 |
+
ctx.rotate(-Math.PI / 2)
|
| 533 |
+
ctx.font = `${vs * 0.55}px ${FONT.latin}`
|
| 534 |
+
ctx.textAlign = 'center'
|
| 535 |
+
ctx.fillStyle = rgba(PALETTE.bone, 0.75)
|
| 536 |
+
ctx.fillText(variant ? 'NO LOOKING BACK' : 'NIGHT WALKER', 0, 0)
|
| 537 |
+
ctx.restore()
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
function gridShot(s: SceneCtx, variant: number) {
|
| 541 |
+
const { ctx, W, H, P, u, a } = s
|
| 542 |
+
ctx.fillStyle = '#040408'
|
| 543 |
+
ctx.fillRect(0, 0, W, H)
|
| 544 |
+
const cols = P ? 3 : 5
|
| 545 |
+
const rows = P ? 5 : 3
|
| 546 |
+
const cw = W / cols
|
| 547 |
+
const ch = H / rows
|
| 548 |
+
for (let r = 0; r < rows; r++) {
|
| 549 |
+
for (let c = 0; c < cols; c++) {
|
| 550 |
+
const i = r * cols + c
|
| 551 |
+
const ch0 = GRID_CHARS[(i + variant * 5) % GRID_CHARS.length]
|
| 552 |
+
const col = SIGN_COLORS[(i * 7 + variant) % SIGN_COLORS.length]
|
| 553 |
+
let on: number
|
| 554 |
+
if (variant === 0) on = hash2(i, a.beat) > 0.45 ? 1 : 0.12
|
| 555 |
+
else {
|
| 556 |
+
const d = (c + r - a.beatPos * 2) % (cols + rows)
|
| 557 |
+
on = ((d + cols + rows) % (cols + rows)) < 2 ? 1 : 0.12
|
| 558 |
+
}
|
| 559 |
+
on = clamp(on * (0.8 + 0.4 * a.pulse))
|
| 560 |
+
const pad = Math.min(cw, ch) * 0.1
|
| 561 |
+
neonSign(ctx, c * cw + pad, r * ch + pad, cw - pad * 2, ch - pad * 2, ch0, col, on, false)
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
// centre stamp
|
| 565 |
+
const size = Math.min(W, H) * 0.2
|
| 566 |
+
ctx.save()
|
| 567 |
+
ctx.fillStyle = 'rgba(4,4,8,0.85)'
|
| 568 |
+
ctx.fillRect(W / 2 - size * 1.3, H / 2 - size * 0.62, size * 2.6, size * 1.24)
|
| 569 |
+
ctx.restore()
|
| 570 |
+
neonText(ctx, '黑街', W / 2, H / 2, size, PALETTE.red, 0.85 + 0.15 * a.pulse, { tube: true, blur: 0.4 })
|
| 571 |
+
void u
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
// =====================================================================
|
| 575 |
+
// S5 — 天台·红月 (56.35 – 72.95s)
|
| 576 |
+
// =====================================================================
|
| 577 |
+
export function sRooftop(s: SceneCtx) {
|
| 578 |
+
const { ctx, W, H, P, lt, u, t, a } = s
|
| 579 |
+
const shotB = lt >= BAR * 3 && lt < BAR * 5
|
| 580 |
+
const shotC = lt >= BAR * 5
|
| 581 |
+
let zoom = 1
|
| 582 |
+
let cx = W / 2
|
| 583 |
+
let cy = H / 2
|
| 584 |
+
const roofY = P ? H * 0.8 : H * 0.82
|
| 585 |
+
const figX = P ? W * 0.5 : W * 0.36
|
| 586 |
+
const figH = P ? H * 0.2 : H * 0.3
|
| 587 |
+
if (!shotB && !shotC) {
|
| 588 |
+
zoom = 1 + lt * 0.008
|
| 589 |
+
} else if (shotB) {
|
| 590 |
+
const k = lt - BAR * 3
|
| 591 |
+
zoom = (P ? 1.9 : 2.1) + k * 0.03
|
| 592 |
+
cx = figX
|
| 593 |
+
cy = roofY - figH * 0.62
|
| 594 |
+
} else {
|
| 595 |
+
const k = (lt - BAR * 5) / (s.dur - BAR * 5)
|
| 596 |
+
zoom = 1.15
|
| 597 |
+
cx = W / 2 + lerp(-W * 0.15, W * 0.15, easeInOutCubic(k))
|
| 598 |
+
cy = H / 2 + H * 0.1
|
| 599 |
+
}
|
| 600 |
+
cx += fbm(t * 0.6, 3) * u * 8 + (a.kick * (hash(a.beat) - 0.5) * u * 14)
|
| 601 |
+
cy += fbm(t * 0.7, 4) * u * 6
|
| 602 |
+
|
| 603 |
+
resetCam(s)
|
| 604 |
+
vGradient(ctx, 0, 0, W, H, [
|
| 605 |
+
[0, '#0a0307'],
|
| 606 |
+
[0.5, '#22060c'],
|
| 607 |
+
[1, '#4a0c16'],
|
| 608 |
+
])
|
| 609 |
+
camera(s, zoom, cx, cy)
|
| 610 |
+
// stars
|
| 611 |
+
ctx.fillStyle = 'rgba(255,230,230,0.6)'
|
| 612 |
+
for (let i = 0; i < 80; i++) {
|
| 613 |
+
const x = hash(i * 1.3) * W * 1.6 - W * 0.3
|
| 614 |
+
const y = hash(i * 2.9) * H * 0.5
|
| 615 |
+
const tw = 0.4 + 0.6 * Math.abs(Math.sin(t * (1 + hash(i)) + i))
|
| 616 |
+
ctx.globalAlpha = tw * 0.6
|
| 617 |
+
ctx.fillRect(x, y, u * 2, u * 2)
|
| 618 |
+
}
|
| 619 |
+
ctx.globalAlpha = 1
|
| 620 |
+
// moon
|
| 621 |
+
const mx = P ? W * 0.5 : W * 0.63
|
| 622 |
+
const my = P ? H * 0.32 : H * 0.38
|
| 623 |
+
const R = Math.min(W, H) * (P ? 0.36 : 0.3) * (1 + a.kick * 0.03)
|
| 624 |
+
glowBlob(ctx, mx, my, R * 2.6, '#ff3a2e', 0.4 + a.kick * 0.15)
|
| 625 |
+
const mg = ctx.createRadialGradient(mx - R * 0.3, my - R * 0.3, R * 0.1, mx, my, R)
|
| 626 |
+
mg.addColorStop(0, '#ffd7a8')
|
| 627 |
+
mg.addColorStop(0.45, '#ff7a4a')
|
| 628 |
+
mg.addColorStop(1, '#b3122a')
|
| 629 |
+
ctx.fillStyle = mg
|
| 630 |
+
ctx.beginPath()
|
| 631 |
+
ctx.arc(mx, my, R, 0, Math.PI * 2)
|
| 632 |
+
ctx.fill()
|
| 633 |
+
ctx.fillStyle = 'rgba(90,10,20,0.18)'
|
| 634 |
+
for (let i = 0; i < 9; i++) {
|
| 635 |
+
const ang = hash(i * 4.1) * Math.PI * 2
|
| 636 |
+
const rr = R * Math.sqrt(hash(i * 2.2)) * 0.75
|
| 637 |
+
ctx.beginPath()
|
| 638 |
+
ctx.arc(mx + Math.cos(ang) * rr, my + Math.sin(ang) * rr, R * (0.05 + hash(i) * 0.12), 0, Math.PI * 2)
|
| 639 |
+
ctx.fill()
|
| 640 |
+
}
|
| 641 |
+
// clouds across the moon
|
| 642 |
+
ctx.fillStyle = 'rgba(12,3,6,0.75)'
|
| 643 |
+
for (let i = 0; i < 6; i++) {
|
| 644 |
+
const y = my - R * 0.7 + i * R * 0.32
|
| 645 |
+
const x = fract(hash(i * 3.3) + lt * (0.01 + hash(i) * 0.015)) * (W + R * 4) - R * 2
|
| 646 |
+
ctx.beginPath()
|
| 647 |
+
ctx.ellipse(x, y, R * (0.6 + hash(i * 5) * 0.6), R * 0.05, 0, 0, Math.PI * 2)
|
| 648 |
+
ctx.fill()
|
| 649 |
+
}
|
| 650 |
+
// searchlights
|
| 651 |
+
ctx.save()
|
| 652 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 653 |
+
for (let i = 0; i < 3; i++) {
|
| 654 |
+
const bx = W * (0.15 + i * 0.35)
|
| 655 |
+
const sw = Math.sin(lt * (0.5 + i * 0.13) + i * 2) * 0.5 + (a.drop ? Math.sin(a.beatPos * Math.PI * 0.5 + i) * 0.15 : 0)
|
| 656 |
+
lightCone(ctx, bx, roofY + H * 0.05, H * 1.4, 0.05, Math.PI + sw, PALETTE.bone, 0.1 + a.mid * 0.06)
|
| 657 |
+
}
|
| 658 |
+
ctx.restore()
|
| 659 |
+
// helicopter
|
| 660 |
+
const hx = fract(lt * 0.03 + 0.2) * W * 1.4 - W * 0.2
|
| 661 |
+
const hy = H * 0.14 + Math.sin(lt) * u * 10
|
| 662 |
+
ctx.fillStyle = '#050204'
|
| 663 |
+
ctx.fillRect(hx - u * 20, hy - u * 6, u * 40, u * 12)
|
| 664 |
+
glowBlob(ctx, hx + u * 22, hy, u * 18, PALETTE.red, fract(lt * 1.5) < 0.2 ? 1 : 0.1)
|
| 665 |
+
// skyline below
|
| 666 |
+
skyline(ctx, { W: W * 1.6, seed: 77, baseY: roofY + H * 0.04, scroll: lt * u * 6 + W * 0.3, cell: u * 75, minH: H * 0.06, maxH: H * 0.26, color: '#080206', t, density: 0.22, winAlpha: 0.6, rimColor: rgba('#ff4a3c', 0.35) })
|
| 667 |
+
fogBand(ctx, W * 1.6, roofY, H * 0.05, '#ff3a2e', 0.12)
|
| 668 |
+
// rooftop slab
|
| 669 |
+
ctx.fillStyle = '#030203'
|
| 670 |
+
ctx.fillRect(-W, roofY, W * 3, H)
|
| 671 |
+
ctx.fillRect(-W, roofY - u * 14, W * 3, u * 14)
|
| 672 |
+
// water tower + antenna
|
| 673 |
+
const tx = P ? W * 0.1 : W * 0.12
|
| 674 |
+
ctx.fillRect(tx, roofY - H * 0.24, u * 120, H * 0.16)
|
| 675 |
+
ctx.beginPath()
|
| 676 |
+
ctx.moveTo(tx - u * 10, roofY - H * 0.24)
|
| 677 |
+
ctx.lineTo(tx + u * 60, roofY - H * 0.3)
|
| 678 |
+
ctx.lineTo(tx + u * 130, roofY - H * 0.24)
|
| 679 |
+
ctx.fill()
|
| 680 |
+
ctx.fillRect(tx + u * 10, roofY - H * 0.08, u * 8, H * 0.08)
|
| 681 |
+
ctx.fillRect(tx + u * 100, roofY - H * 0.08, u * 8, H * 0.08)
|
| 682 |
+
const ax = P ? W * 0.86 : W * 0.9
|
| 683 |
+
ctx.fillRect(ax, roofY - H * 0.42, u * 6, H * 0.42)
|
| 684 |
+
glowBlob(ctx, ax + u * 3, roofY - H * 0.42, u * 26, PALETTE.red, a.pulse > 0.6 || fract(lt) < 0.15 ? 1 : 0.15)
|
| 685 |
+
// figure (back to camera, looking at the moon)
|
| 686 |
+
figureBack(ctx, figX, roofY - u * 12, figH, Math.sin(lt * 1.6), { rim: rgba('#ff7a4a', 0.9) })
|
| 687 |
+
// coat tail flutter
|
| 688 |
+
ctx.fillStyle = '#030405'
|
| 689 |
+
ctx.beginPath()
|
| 690 |
+
const fl = noise1(t * 3, 2)
|
| 691 |
+
ctx.moveTo(figX + figH * 0.11, roofY - u * 12 - figH * 0.72)
|
| 692 |
+
ctx.quadraticCurveTo(figX + figH * (0.3 + fl * 0.05), roofY - figH * 0.6, figX + figH * (0.38 + fl * 0.08), roofY - figH * 0.45)
|
| 693 |
+
ctx.lineTo(figX + figH * 0.12, roofY - figH * 0.48)
|
| 694 |
+
ctx.fill()
|
| 695 |
+
resetCam(s)
|
| 696 |
+
rain(ctx, W, H, t, { count: Math.floor(200 * area(s)) + 40, speed: H * 1.6, len: u * 50, slant: -0.12, color: '#ffb0b0', alpha: 0.16, width: Math.max(1, u * 1.2) })
|
| 697 |
+
// strobe in shot C
|
| 698 |
+
if (shotC && a.beatPhase < 0.08 && a.beat % 2 === 0) {
|
| 699 |
+
ctx.fillStyle = 'rgba(255,200,190,0.18)'
|
| 700 |
+
ctx.fillRect(0, 0, W, H)
|
| 701 |
+
}
|
| 702 |
+
void beatTime
|
| 703 |
+
}
|
src/mv/engine/scenesB.ts
ADDED
|
@@ -0,0 +1,842 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 6 |
+
lantern,
|
| 7 |
+
lightCone,
|
| 8 |
+
neonSign,
|
| 9 |
+
neonText,
|
| 10 |
+
rain,
|
| 11 |
+
skyline,
|
| 12 |
+
speedLines,
|
| 13 |
+
splitText,
|
| 14 |
+
vGradient,
|
| 15 |
+
walker,
|
| 16 |
+
wetReflection,
|
| 17 |
+
} from './draw'
|
| 18 |
+
import { camera, resetCam, type SceneCtx } from './types'
|
| 19 |
+
import { FONT, PALETTE, clamp, easeInOutCubic, easeOutCubic, easeOutExpo, fbm, fract, hash, hash2, lerp, rgba, smoothstep } from './util'
|
| 20 |
+
|
| 21 |
+
const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
|
| 22 |
+
|
| 23 |
+
// =====================================================================
|
| 24 |
+
// S6 — 葱姜蒜夜市 (72.95 – 92s) calm, warm, one-point perspective dolly
|
| 25 |
+
// =====================================================================
|
| 26 |
+
const STALL_SIGNS = ['葱', '姜', '蒜', '糖水', '烧烤', '牛杂', '鱼蛋', '粥', '夜宵', '凉茶']
|
| 27 |
+
|
| 28 |
+
export function sMarket(s: SceneCtx) {
|
| 29 |
+
const { ctx, W, H, P, lt, u, t } = s
|
| 30 |
+
const hy = P ? H * 0.46 : H * 0.44
|
| 31 |
+
const f = P ? W * 1.05 : W * 0.62
|
| 32 |
+
const camZ = lt * 0.85
|
| 33 |
+
const camX = Math.sin(lt * 0.22) * 0.3
|
| 34 |
+
const camH = 1.65
|
| 35 |
+
const proj = (X: number, Y: number, Z: number) => {
|
| 36 |
+
const zr = Math.max(0.05, Z - camZ)
|
| 37 |
+
const k = f / zr
|
| 38 |
+
return { x: W / 2 + (X - camX) * k, y: hy - (Y - camH) * k, k, zr }
|
| 39 |
+
}
|
| 40 |
+
// sky slit + haze
|
| 41 |
+
vGradient(ctx, 0, 0, W, H, [
|
| 42 |
+
[0, '#05070b'],
|
| 43 |
+
[0.42, '#1b1210'],
|
| 44 |
+
[0.5, '#3a2112'],
|
| 45 |
+
[1, '#0a0705'],
|
| 46 |
+
])
|
| 47 |
+
glowBlob(ctx, W / 2, hy, Math.max(W, H) * 0.5, PALETTE.amber, 0.22)
|
| 48 |
+
// ground
|
| 49 |
+
vGradient(ctx, 0, hy, W, H - hy, [
|
| 50 |
+
[0, '#1a120c'],
|
| 51 |
+
[1, '#070504'],
|
| 52 |
+
])
|
| 53 |
+
const D = 3
|
| 54 |
+
const first = Math.floor(camZ / D)
|
| 55 |
+
const reflections: { x: number; y: number; r: number; c: string; a: number }[] = []
|
| 56 |
+
for (let n = 13; n >= 0; n--) {
|
| 57 |
+
const i = first + n
|
| 58 |
+
const Z = i * D
|
| 59 |
+
if (Z + D < camZ + 0.4) continue
|
| 60 |
+
const fogA = clamp(1.25 - (Z - camZ) / 36) * clamp((Z + D - camZ) / 1.2)
|
| 61 |
+
ctx.globalAlpha = fogA
|
| 62 |
+
for (const side of [-1, 1]) {
|
| 63 |
+
const sid = i * 2 + (side > 0 ? 1 : 0)
|
| 64 |
+
// building wall face above the stalls
|
| 65 |
+
const a0 = proj(side * 4.6, 0, Z)
|
| 66 |
+
const a1 = proj(side * 4.6, 0, Z + D)
|
| 67 |
+
const b0 = proj(side * 4.6, 10, Z)
|
| 68 |
+
const b1 = proj(side * 4.6, 10, Z + D)
|
| 69 |
+
ctx.fillStyle = hash(sid) > 0.5 ? '#0d0b0b' : '#0a0c0f'
|
| 70 |
+
ctx.beginPath()
|
| 71 |
+
ctx.moveTo(a0.x, a0.y)
|
| 72 |
+
ctx.lineTo(a1.x, a1.y)
|
| 73 |
+
ctx.lineTo(b1.x, b1.y)
|
| 74 |
+
ctx.lineTo(b0.x, b0.y)
|
| 75 |
+
ctx.closePath()
|
| 76 |
+
ctx.fill()
|
| 77 |
+
// windows
|
| 78 |
+
for (let w = 0; w < 3; w++) {
|
| 79 |
+
if (hash2(sid, w) < 0.45) continue
|
| 80 |
+
const wy = 4.8 + w * 1.7
|
| 81 |
+
const p0 = proj(side * 4.6, wy, Z + 0.7)
|
| 82 |
+
const p1 = proj(side * 4.6, wy + 0.9, Z + 1.6)
|
| 83 |
+
ctx.fillStyle = hash2(sid, w + 9) > 0.7 ? '#3f8f95' : '#c9853d'
|
| 84 |
+
ctx.fillRect(Math.min(p0.x, p1.x), Math.min(p0.y, p1.y), Math.abs(p1.x - p0.x), Math.abs(p1.y - p0.y))
|
| 85 |
+
}
|
| 86 |
+
// stall counter (side face toward the alley)
|
| 87 |
+
const c0 = proj(side * 2.0, 0, Z + 0.3)
|
| 88 |
+
const c1 = proj(side * 2.0, 0, Z + 2.7)
|
| 89 |
+
const c2 = proj(side * 2.0, 1.05, Z + 2.7)
|
| 90 |
+
const c3 = proj(side * 2.0, 1.05, Z + 0.3)
|
| 91 |
+
ctx.fillStyle = '#1e140d'
|
| 92 |
+
ctx.beginPath()
|
| 93 |
+
ctx.moveTo(c0.x, c0.y)
|
| 94 |
+
ctx.lineTo(c1.x, c1.y)
|
| 95 |
+
ctx.lineTo(c2.x, c2.y)
|
| 96 |
+
ctx.lineTo(c3.x, c3.y)
|
| 97 |
+
ctx.closePath()
|
| 98 |
+
ctx.fill()
|
| 99 |
+
// lit back of stall
|
| 100 |
+
const g0 = proj(side * 4.4, 1.05, Z + 0.3)
|
| 101 |
+
const g1 = proj(side * 4.4, 2.3, Z + 2.7)
|
| 102 |
+
ctx.fillStyle = '#6a3a17'
|
| 103 |
+
ctx.beginPath()
|
| 104 |
+
ctx.moveTo(c3.x, c3.y)
|
| 105 |
+
ctx.lineTo(c2.x, c2.y)
|
| 106 |
+
ctx.lineTo(g1.x, proj(side * 4.4, 1.05, Z + 2.7).y)
|
| 107 |
+
ctx.lineTo(g0.x, g0.y)
|
| 108 |
+
ctx.closePath()
|
| 109 |
+
ctx.fill()
|
| 110 |
+
// goods on counter
|
| 111 |
+
const kind = ((i % 10) + 10) % 10
|
| 112 |
+
for (let q = 0; q < 5; q++) {
|
| 113 |
+
const gp = proj(side * 2.15, 1.12, Z + 0.6 + q * 0.45)
|
| 114 |
+
const r = 0.13 * gp.k
|
| 115 |
+
if (r < 0.6) continue
|
| 116 |
+
if (kind === 0 || (kind > 2 && q % 3 === 0)) {
|
| 117 |
+
// scallion bundle
|
| 118 |
+
ctx.strokeStyle = q % 2 ? '#6fbf4a' : '#9ddf6a'
|
| 119 |
+
ctx.lineWidth = Math.max(1, r * 0.25)
|
| 120 |
+
ctx.beginPath()
|
| 121 |
+
for (let l = -2; l <= 2; l++) {
|
| 122 |
+
ctx.moveTo(gp.x + l * r * 0.2, gp.y)
|
| 123 |
+
ctx.lineTo(gp.x + l * r * 0.5, gp.y - r * 2.4)
|
| 124 |
+
}
|
| 125 |
+
ctx.stroke()
|
| 126 |
+
ctx.fillStyle = '#efe9dc'
|
| 127 |
+
ctx.fillRect(gp.x - r * 0.5, gp.y - r * 0.5, r, r * 0.5)
|
| 128 |
+
} else if (kind === 1) {
|
| 129 |
+
ctx.fillStyle = '#d9a446'
|
| 130 |
+
ctx.beginPath()
|
| 131 |
+
ctx.ellipse(gp.x, gp.y - r * 0.4, r * 0.9, r * 0.45, 0.3, 0, Math.PI * 2)
|
| 132 |
+
ctx.ellipse(gp.x + r * 0.5, gp.y - r * 0.8, r * 0.45, r * 0.3, -0.5, 0, Math.PI * 2)
|
| 133 |
+
ctx.fill()
|
| 134 |
+
} else {
|
| 135 |
+
ctx.fillStyle = '#efe6d6'
|
| 136 |
+
ctx.beginPath()
|
| 137 |
+
ctx.arc(gp.x, gp.y - r * 0.6, r * 0.62, 0, Math.PI * 2)
|
| 138 |
+
ctx.fill()
|
| 139 |
+
ctx.fillStyle = '#c9b9a0'
|
| 140 |
+
ctx.fillRect(gp.x - r * 0.08, gp.y - r * 1.4, r * 0.16, r * 0.4)
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
// awning
|
| 144 |
+
const w0 = proj(side * 1.5, 2.35, Z + 0.15)
|
| 145 |
+
const w1 = proj(side * 1.5, 2.35, Z + 2.85)
|
| 146 |
+
const w2 = proj(side * 4.5, 2.85, Z + 2.85)
|
| 147 |
+
const w3 = proj(side * 4.5, 2.85, Z + 0.15)
|
| 148 |
+
const red = hash(sid * 3.3) > 0.4
|
| 149 |
+
ctx.fillStyle = red ? '#8c1720' : '#174a52'
|
| 150 |
+
ctx.beginPath()
|
| 151 |
+
ctx.moveTo(w0.x, w0.y)
|
| 152 |
+
ctx.lineTo(w1.x, w1.y)
|
| 153 |
+
ctx.lineTo(w2.x, w2.y)
|
| 154 |
+
ctx.lineTo(w3.x, w3.y)
|
| 155 |
+
ctx.closePath()
|
| 156 |
+
ctx.fill()
|
| 157 |
+
// awning edge with bulb string
|
| 158 |
+
ctx.strokeStyle = '#ffcf8a'
|
| 159 |
+
ctx.lineWidth = Math.max(1, 0.03 * w0.k)
|
| 160 |
+
ctx.beginPath()
|
| 161 |
+
ctx.moveTo(w0.x, w0.y)
|
| 162 |
+
ctx.lineTo(w1.x, w1.y)
|
| 163 |
+
ctx.stroke()
|
| 164 |
+
// sign board
|
| 165 |
+
const word = STALL_SIGNS[((i * 2 + (side > 0 ? 1 : 0)) % STALL_SIGNS.length + STALL_SIGNS.length) % STALL_SIGNS.length]
|
| 166 |
+
const sp = proj(side * 1.75, 4.3, Z + 1.4)
|
| 167 |
+
const sw = 0.55 * sp.k
|
| 168 |
+
const sh = (0.5 + 0.55 * Array.from(word).length) * sp.k
|
| 169 |
+
if (sw > 3) {
|
| 170 |
+
const col = [PALETTE.sodium, PALETTE.red, '#ff5fa2', PALETTE.cyan][(i + (side > 0 ? 2 : 0)) % 4 < 0 ? 0 : (i + (side > 0 ? 2 : 0)) % 4]
|
| 171 |
+
neonSign(ctx, sp.x - sw / 2, sp.y, sw, sh, word, col, 0.9 + 0.1 * Math.sin(t * 3 + sid), true)
|
| 172 |
+
reflections.push({ x: sp.x, y: proj(side * 1.75, -4.8, Z + 1.4).y, r: sw * 0.9, c: col, a: 0.25 * fogA })
|
| 173 |
+
}
|
| 174 |
+
// lantern
|
| 175 |
+
if ((i + (side > 0 ? 1 : 0)) % 2 === 0) {
|
| 176 |
+
const lp = proj(side * 1.15, 3.25, Z + 1.5)
|
| 177 |
+
const r = 0.24 * lp.k
|
| 178 |
+
if (r > 1) {
|
| 179 |
+
lantern(ctx, lp.x, lp.y, r, Math.sin(t * 1.3 + sid) * 0.12, 1)
|
| 180 |
+
reflections.push({ x: lp.x, y: proj(side * 1.15, -3.25, Z + 1.5).y, r: r * 1.6, c: '#ff5a2e', a: 0.4 * fogA })
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
// steam
|
| 184 |
+
if (hash(sid * 7.7) > 0.45) {
|
| 185 |
+
for (let q = 0; q < 6; q++) {
|
| 186 |
+
const life = fract(t * 0.25 + q / 6 + hash(sid + q))
|
| 187 |
+
const sp2 = proj(side * (2.8 + Math.sin(q + t) * 0.2), 1.2 + life * 2.4, Z + 1.4)
|
| 188 |
+
const rr = (0.25 + life * 0.6) * sp2.k
|
| 189 |
+
ctx.fillStyle = `rgba(255,236,220,${0.07 * (1 - life)})`
|
| 190 |
+
ctx.beginPath()
|
| 191 |
+
ctx.arc(sp2.x, sp2.y, rr, 0, Math.PI * 2)
|
| 192 |
+
ctx.fill()
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
// customer silhouettes
|
| 196 |
+
if (hash(sid * 1.1) > 0.55) {
|
| 197 |
+
const pp = proj(side * 1.55, 0, Z + 1.0 + hash(sid) * 1.2)
|
| 198 |
+
figureBack(ctx, pp.x, pp.y, 1.7 * pp.k, Math.sin(t + sid), { color: '#0a0706' })
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
// string lights across the alley
|
| 202 |
+
const pts: { x: number; y: number; k: number }[] = []
|
| 203 |
+
for (let q = 0; q <= 16; q++) {
|
| 204 |
+
const xx = lerp(-4.5, 4.5, q / 16)
|
| 205 |
+
const sag = 0.7 * (1 - Math.pow(xx / 4.5, 2))
|
| 206 |
+
pts.push(proj(xx, 4.9 - sag, Z))
|
| 207 |
+
}
|
| 208 |
+
ctx.strokeStyle = '#1a120c'
|
| 209 |
+
ctx.lineWidth = Math.max(1, 0.015 * pts[0].k)
|
| 210 |
+
ctx.beginPath()
|
| 211 |
+
pts.forEach((p, q) => (q ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y)))
|
| 212 |
+
ctx.stroke()
|
| 213 |
+
for (let q = 1; q < 16; q++) {
|
| 214 |
+
const p = pts[q]
|
| 215 |
+
const r = Math.max(1, 0.06 * p.k)
|
| 216 |
+
const on = 0.75 + 0.25 * Math.sin(t * 4 + q * 1.7 + i)
|
| 217 |
+
ctx.fillStyle = q % 3 === 0 ? '#ff9a6a' : '#ffe0a0'
|
| 218 |
+
ctx.globalAlpha = fogA * on
|
| 219 |
+
ctx.beginPath()
|
| 220 |
+
ctx.arc(p.x, p.y, r, 0, Math.PI * 2)
|
| 221 |
+
ctx.fill()
|
| 222 |
+
}
|
| 223 |
+
ctx.globalAlpha = 1
|
| 224 |
+
}
|
| 225 |
+
ctx.globalAlpha = 1
|
| 226 |
+
// wet ground reflections of lights
|
| 227 |
+
ctx.save()
|
| 228 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 229 |
+
for (const r of reflections) {
|
| 230 |
+
if (r.y < hy || r.y > H * 1.3) continue
|
| 231 |
+
const g = ctx.createRadialGradient(r.x, r.y, 0, r.x, r.y, r.r * 2)
|
| 232 |
+
g.addColorStop(0, rgba(r.c, r.a))
|
| 233 |
+
g.addColorStop(1, rgba(r.c, 0))
|
| 234 |
+
ctx.fillStyle = g
|
| 235 |
+
ctx.save()
|
| 236 |
+
ctx.translate(r.x, r.y)
|
| 237 |
+
ctx.scale(0.45, 1.8)
|
| 238 |
+
ctx.translate(-r.x, -r.y)
|
| 239 |
+
ctx.fillRect(r.x - r.r * 2, r.y - r.r * 2, r.r * 4, r.r * 4)
|
| 240 |
+
ctx.restore()
|
| 241 |
+
}
|
| 242 |
+
ctx.restore()
|
| 243 |
+
// foreground walker crossing the frame
|
| 244 |
+
if (lt > 8.5 && lt < 15.5) {
|
| 245 |
+
const k = (lt - 8.5) / 7
|
| 246 |
+
const x = lerp(-W * 0.25, W * 1.25, k)
|
| 247 |
+
const h = P ? H * 0.75 : H * 1.05
|
| 248 |
+
walker(ctx, x, H * (P ? 1.12 : 1.18), h, fract(s.a.beatPos / 2), { color: '#020101', rim: rgba(PALETTE.amber, 0.7), rimSide: -1 })
|
| 249 |
+
}
|
| 250 |
+
// warm sparks / embers drifting
|
| 251 |
+
ctx.fillStyle = '#ffb35c'
|
| 252 |
+
for (let i = 0; i < 40; i++) {
|
| 253 |
+
const life = fract(t * (0.08 + hash(i) * 0.06) + hash(i * 3.3))
|
| 254 |
+
const x = hash(i * 1.9) * W + Math.sin(t + i) * u * 20
|
| 255 |
+
const y = H * (1 - life) * 0.9
|
| 256 |
+
ctx.globalAlpha = (1 - life) * 0.6
|
| 257 |
+
ctx.fillRect(x, y, u * 3, u * 3)
|
| 258 |
+
}
|
| 259 |
+
ctx.globalAlpha = 1
|
| 260 |
+
void easeOutCubic
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// =====================================================================
|
| 264 |
+
// S7 — 暗场·心跳 (92 – 109.436s)
|
| 265 |
+
// =====================================================================
|
| 266 |
+
function ecg(ph: number): number {
|
| 267 |
+
const g = (c: number, w: number, a: number) => a * Math.exp(-Math.pow((ph - c) / w, 2))
|
| 268 |
+
return g(0.1, 0.025, 0.12) + g(0.2, 0.008, -0.18) + g(0.225, 0.01, 1) + g(0.25, 0.01, -0.35) + g(0.45, 0.04, 0.25)
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
export function sHeartbeat(s: SceneCtx) {
|
| 272 |
+
const { ctx, W, H, P, lt, u, t, dur } = s
|
| 273 |
+
const hbAt = (x: number) => (50 * x + (170 * x * x * x) / (3 * dur * dur)) / 60
|
| 274 |
+
const hb = hbAt(lt)
|
| 275 |
+
const hbPhase = fract(hb)
|
| 276 |
+
const beatGlow = Math.exp(-Math.max(0, hbPhase - 0.2) * 9) * (hbPhase > 0.2 ? 1 : 0)
|
| 277 |
+
vGradient(ctx, 0, 0, W, H, [
|
| 278 |
+
[0, '#040406'],
|
| 279 |
+
[1, '#0a0608'],
|
| 280 |
+
])
|
| 281 |
+
const lx = W / 2
|
| 282 |
+
const ly = H * 0.1
|
| 283 |
+
const floorY = P ? H * 0.8 : H * 0.84
|
| 284 |
+
let on = 0.85 + 0.15 * fbm(t * 3, 5)
|
| 285 |
+
if (hash(Math.floor(t * 9)) > 0.92) on = 0.25
|
| 286 |
+
on *= 0.8 + 0.4 * beatGlow
|
| 287 |
+
// lamp
|
| 288 |
+
ctx.fillStyle = '#0d0d10'
|
| 289 |
+
ctx.fillRect(lx - u * 2, 0, u * 4, ly)
|
| 290 |
+
ctx.beginPath()
|
| 291 |
+
ctx.moveTo(lx - u * 50, ly + u * 18)
|
| 292 |
+
ctx.lineTo(lx + u * 50, ly + u * 18)
|
| 293 |
+
ctx.lineTo(lx + u * 20, ly - u * 4)
|
| 294 |
+
ctx.lineTo(lx - u * 20, ly - u * 4)
|
| 295 |
+
ctx.fill()
|
| 296 |
+
const spread = P ? 0.32 : 0.38
|
| 297 |
+
lightCone(ctx, lx, ly + u * 16, floorY - ly, spread, 0, '#f3e2c4', 0.38 * on)
|
| 298 |
+
glowBlob(ctx, lx, ly + u * 18, u * 90, '#ffe9c4', 0.9 * on)
|
| 299 |
+
// floor pool
|
| 300 |
+
ctx.save()
|
| 301 |
+
ctx.translate(lx, floorY)
|
| 302 |
+
ctx.scale(1, 0.18)
|
| 303 |
+
glowBlob(ctx, 0, 0, (floorY - ly) * Math.tan(spread) * 1.3, '#f3e2c4', 0.6 * on)
|
| 304 |
+
ctx.restore()
|
| 305 |
+
// ECG trace across the frame
|
| 306 |
+
const baseY = P ? H * 0.56 : H * 0.55
|
| 307 |
+
const span = 3.2
|
| 308 |
+
ctx.save()
|
| 309 |
+
ctx.strokeStyle = PALETTE.red
|
| 310 |
+
ctx.shadowColor = PALETTE.red
|
| 311 |
+
ctx.shadowBlur = u * 18
|
| 312 |
+
ctx.lineWidth = Math.max(2, u * 5)
|
| 313 |
+
ctx.lineJoin = 'round'
|
| 314 |
+
ctx.beginPath()
|
| 315 |
+
const steps = 220
|
| 316 |
+
for (let i = 0; i <= steps; i++) {
|
| 317 |
+
const x = (i / steps) * W
|
| 318 |
+
const tau = lt - (1 - i / steps) * span
|
| 319 |
+
const v = tau < 0 ? 0 : ecg(fract(hbAt(tau)))
|
| 320 |
+
const y = baseY - v * H * 0.16
|
| 321 |
+
if (i === 0) ctx.moveTo(x, y)
|
| 322 |
+
else ctx.lineTo(x, y)
|
| 323 |
+
}
|
| 324 |
+
ctx.globalAlpha = 0.85
|
| 325 |
+
ctx.stroke()
|
| 326 |
+
ctx.restore()
|
| 327 |
+
glowBlob(ctx, W - u * 4, baseY - ecg(hbPhase) * H * 0.16, u * 40, PALETTE.red, 0.9)
|
| 328 |
+
// rain only inside the light cone
|
| 329 |
+
ctx.save()
|
| 330 |
+
ctx.beginPath()
|
| 331 |
+
ctx.moveTo(lx, ly)
|
| 332 |
+
ctx.lineTo(lx + Math.tan(spread) * (floorY - ly), floorY)
|
| 333 |
+
ctx.lineTo(lx - Math.tan(spread) * (floorY - ly), floorY)
|
| 334 |
+
ctx.closePath()
|
| 335 |
+
ctx.clip()
|
| 336 |
+
rain(ctx, W, H, t, { count: Math.floor(260 * area(s)) + 60, speed: H * 1.5, len: u * 50, slant: 0.04, color: '#f3e2c4', alpha: 0.35 * on, width: Math.max(1, u * 1.4) })
|
| 337 |
+
ctx.restore()
|
| 338 |
+
// figure
|
| 339 |
+
const fh = P ? H * 0.26 : H * 0.36
|
| 340 |
+
figureBack(ctx, lx, floorY, fh, Math.sin(lt * 0.9) * 0.5, { rim: rgba('#f3e2c4', 0.55 * on) })
|
| 341 |
+
// heartbeat red pulse vignette
|
| 342 |
+
const pulse = beatGlow * (0.15 + 0.35 * (lt / dur))
|
| 343 |
+
if (pulse > 0.01) {
|
| 344 |
+
const g = ctx.createRadialGradient(W / 2, H / 2, Math.min(W, H) * 0.3, W / 2, H / 2, Math.max(W, H) * 0.75)
|
| 345 |
+
g.addColorStop(0, 'rgba(155,21,48,0)')
|
| 346 |
+
g.addColorStop(1, `rgba(155,21,48,${pulse})`)
|
| 347 |
+
ctx.fillStyle = g
|
| 348 |
+
ctx.fillRect(0, 0, W, H)
|
| 349 |
+
}
|
| 350 |
+
// last 4 beats: 再 · 来 · 一 · 次
|
| 351 |
+
const bp = (t - DROP2) / BEAT
|
| 352 |
+
if (bp >= -4 && bp < 0) {
|
| 353 |
+
const words = ['再', '来', '一', '次']
|
| 354 |
+
const idx = Math.floor(bp + 4)
|
| 355 |
+
const ph = fract(bp)
|
| 356 |
+
const size = Math.min(W, H) * (0.42 + 0.12 * (1 - easeOutExpo(ph)))
|
| 357 |
+
splitText(ctx, words[idx], W / 2, H * 0.42, size, FONT.black, PALETTE.bone, u * 14 * (1 - ph))
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
// =====================================================================
|
| 362 |
+
// S8 — Drop2·飙车光轨 (109.436 – 127.64s)
|
| 363 |
+
// =====================================================================
|
| 364 |
+
const PUNCH = ['油门到底', '别回头', '冲', '黑街之王']
|
| 365 |
+
|
| 366 |
+
export function sHighway(s: SceneCtx) {
|
| 367 |
+
const shot = Math.floor(s.lt / (BAR * 2))
|
| 368 |
+
if (shot === 2) sideShot(s)
|
| 369 |
+
else chaseShot(s, shot)
|
| 370 |
+
// punch word on the first beat of each 2-bar shot
|
| 371 |
+
const inShot = s.lt - shot * BAR * 2
|
| 372 |
+
if (inShot < BEAT * 0.9) {
|
| 373 |
+
const { ctx, W, H, u, P } = s
|
| 374 |
+
const k = inShot / (BEAT * 0.9)
|
| 375 |
+
const word = PUNCH[Math.min(3, shot)]
|
| 376 |
+
const size = Math.min((W * 0.82) / Array.from(word).length, P ? H * 0.2 : H * 0.42)
|
| 377 |
+
ctx.save()
|
| 378 |
+
ctx.globalAlpha = 1 - easeInOutCubic(k)
|
| 379 |
+
splitText(ctx, word, W / 2, H * 0.45, size * (1 + k * 0.15), FONT.black, '#ffffff', u * 16)
|
| 380 |
+
ctx.restore()
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
function chaseShot(s: SceneCtx, shot: number) {
|
| 385 |
+
const { ctx, W, H, P, lt, u, t, a } = s
|
| 386 |
+
const hy = P ? H * 0.42 : H * 0.42
|
| 387 |
+
const f = P ? W * 1.0 : W * 0.62
|
| 388 |
+
const curve = Math.sin(lt * 0.55 + shot)
|
| 389 |
+
const camX = curve * 0.8
|
| 390 |
+
const camH = 1.25
|
| 391 |
+
const camZ = lt * 34
|
| 392 |
+
const lean = -curve * 0.1
|
| 393 |
+
const proj = (X: number, Y: number, Z: number) => {
|
| 394 |
+
const zr = Math.max(0.3, Z - camZ)
|
| 395 |
+
const k = f / zr
|
| 396 |
+
// road curvature: bend lateral position by depth
|
| 397 |
+
const bend = curve * zr * zr * 0.0009
|
| 398 |
+
return { x: W / 2 + (X - camX + bend) * k, y: hy - (Y - camH) * k, k, zr }
|
| 399 |
+
}
|
| 400 |
+
resetCam(s)
|
| 401 |
+
vGradient(ctx, 0, 0, W, H, [
|
| 402 |
+
[0, '#060818'],
|
| 403 |
+
[0.3, '#1a2050'],
|
| 404 |
+
[0.42, '#8a2a5a'],
|
| 405 |
+
[0.46, '#16101a'],
|
| 406 |
+
[1, '#0a0a10'],
|
| 407 |
+
])
|
| 408 |
+
camera(s, 1 + a.kick * 0.02, W / 2, H / 2, lean)
|
| 409 |
+
glowBlob(ctx, W / 2 + curve * W * 0.1, hy, Math.max(W, H) * 0.55, '#ff4a6a', 0.38)
|
| 410 |
+
skyline(ctx, { W: W * 1.4, seed: 91, baseY: hy + u * 4, scroll: W * 0.2 + curve * u * 80, cell: u * 40, minH: H * 0.02, maxH: H * 0.14, color: '#06060c', t, density: 0.25, winAlpha: 0.7 })
|
| 411 |
+
// road surface
|
| 412 |
+
const r0 = proj(-8, 0, camZ + 1.5)
|
| 413 |
+
const r1 = proj(8, 0, camZ + 1.5)
|
| 414 |
+
ctx.fillStyle = '#07080b'
|
| 415 |
+
ctx.beginPath()
|
| 416 |
+
ctx.moveTo(r0.x, r0.y)
|
| 417 |
+
for (let z = 2; z <= 400; z *= 1.25) ctx.lineTo(proj(-8, 0, camZ + z).x, proj(-8, 0, camZ + z).y)
|
| 418 |
+
for (let z = 400; z >= 1.5; z /= 1.25) ctx.lineTo(proj(8, 0, camZ + z).x, proj(8, 0, camZ + z).y)
|
| 419 |
+
ctx.lineTo(r1.x, r1.y)
|
| 420 |
+
ctx.closePath()
|
| 421 |
+
ctx.fill()
|
| 422 |
+
// far → near objects
|
| 423 |
+
const zStart = Math.floor(camZ / 20) * 20
|
| 424 |
+
for (let Z = zStart + 300; Z >= zStart; Z -= 20) {
|
| 425 |
+
const zr = Z - camZ
|
| 426 |
+
if (zr < 0.5) continue
|
| 427 |
+
const fogA = clamp(1.3 - zr / 280)
|
| 428 |
+
ctx.globalAlpha = fogA
|
| 429 |
+
const zi = Z / 20
|
| 430 |
+
// buildings side faces
|
| 431 |
+
for (const side of [-1, 1]) {
|
| 432 |
+
const bh = 14 + 34 * hash(zi * 2 + side)
|
| 433 |
+
const q0 = proj(side * 13, 0, Z)
|
| 434 |
+
const q1 = proj(side * 13, 0, Z + 17)
|
| 435 |
+
const q2 = proj(side * 13, bh, Z + 17)
|
| 436 |
+
const q3 = proj(side * 13, bh, Z)
|
| 437 |
+
ctx.fillStyle = '#05060a'
|
| 438 |
+
ctx.beginPath()
|
| 439 |
+
ctx.moveTo(q0.x, q0.y)
|
| 440 |
+
ctx.lineTo(q1.x, q1.y)
|
| 441 |
+
ctx.lineTo(q2.x, q2.y)
|
| 442 |
+
ctx.lineTo(q3.x, q3.y)
|
| 443 |
+
ctx.closePath()
|
| 444 |
+
ctx.fill()
|
| 445 |
+
ctx.strokeStyle = hash(zi + side * 3) > 0.5 ? PALETTE.cyan : PALETTE.sodium
|
| 446 |
+
ctx.lineWidth = Math.max(1.5, 0.45 * q0.k)
|
| 447 |
+
ctx.beginPath()
|
| 448 |
+
for (let l = 1; l < 5; l++) {
|
| 449 |
+
const yy = (bh * l) / 5
|
| 450 |
+
if (hash2(zi + side, l) < 0.4) continue
|
| 451 |
+
const p0 = proj(side * 13, yy, Z + 1)
|
| 452 |
+
const p1 = proj(side * 13, yy, Z + 16)
|
| 453 |
+
ctx.moveTo(p0.x, p0.y)
|
| 454 |
+
ctx.lineTo(p1.x, p1.y)
|
| 455 |
+
}
|
| 456 |
+
ctx.stroke()
|
| 457 |
+
// street lamps
|
| 458 |
+
const lp = proj(side * 8.5, 0, Z)
|
| 459 |
+
const lt2 = proj(side * 8.5, 7.5, Z)
|
| 460 |
+
const lh = proj(side * 6.3, 7.5, Z)
|
| 461 |
+
ctx.strokeStyle = '#0c0d12'
|
| 462 |
+
ctx.lineWidth = Math.max(1, 0.18 * lp.k)
|
| 463 |
+
ctx.beginPath()
|
| 464 |
+
ctx.moveTo(lp.x, lp.y)
|
| 465 |
+
ctx.lineTo(lt2.x, lt2.y)
|
| 466 |
+
ctx.lineTo(lh.x, lh.y)
|
| 467 |
+
ctx.stroke()
|
| 468 |
+
glowBlob(ctx, lh.x, lh.y, Math.max(3, 2.2 * lh.k), PALETTE.sodium, 1)
|
| 469 |
+
const pool = proj(side * 6.3, 0, Z)
|
| 470 |
+
ctx.save()
|
| 471 |
+
ctx.translate(pool.x, pool.y)
|
| 472 |
+
ctx.scale(1, 0.3)
|
| 473 |
+
glowBlob(ctx, 0, 0, Math.max(4, 6 * pool.k), PALETTE.sodium, 0.35)
|
| 474 |
+
ctx.restore()
|
| 475 |
+
}
|
| 476 |
+
// lane dashes
|
| 477 |
+
ctx.fillStyle = rgba(PALETTE.bone, 0.95)
|
| 478 |
+
for (const X of [-2.6, 2.6]) {
|
| 479 |
+
for (let d = 0; d < 2; d++) {
|
| 480 |
+
const dz = Z + d * 10
|
| 481 |
+
const d0 = proj(X - 0.14, 0, dz)
|
| 482 |
+
const d1 = proj(X + 0.14, 0, dz)
|
| 483 |
+
const d2 = proj(X + 0.14, 0, dz + 4)
|
| 484 |
+
const d3 = proj(X - 0.14, 0, dz + 4)
|
| 485 |
+
if (d0.zr < 0.5) continue
|
| 486 |
+
ctx.beginPath()
|
| 487 |
+
ctx.moveTo(d0.x, d0.y)
|
| 488 |
+
ctx.lineTo(d1.x, d1.y)
|
| 489 |
+
ctx.lineTo(d2.x, d2.y)
|
| 490 |
+
ctx.lineTo(d3.x, d3.y)
|
| 491 |
+
ctx.closePath()
|
| 492 |
+
ctx.fill()
|
| 493 |
+
}
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
ctx.globalAlpha = 1
|
| 497 |
+
// cars ahead (tail lights) and oncoming (headlights)
|
| 498 |
+
ctx.save()
|
| 499 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 500 |
+
for (let j = 0; j < 6; j++) {
|
| 501 |
+
const X = j % 2 ? 1.3 : 4.0
|
| 502 |
+
const zr = 16 + j * 22 + Math.sin(lt * 0.4 + j) * 6
|
| 503 |
+
const c = proj(X, 0.8, camZ + zr)
|
| 504 |
+
const sp = 0.7 * c.k
|
| 505 |
+
glowBlob(ctx, c.x - sp, c.y, Math.max(3, 0.9 * c.k), PALETTE.red, 0.9)
|
| 506 |
+
glowBlob(ctx, c.x + sp, c.y, Math.max(3, 0.9 * c.k), PALETTE.red, 0.9)
|
| 507 |
+
// light trail streak on the road
|
| 508 |
+
const g = ctx.createLinearGradient(0, c.y, 0, c.y + 3 * c.k)
|
| 509 |
+
g.addColorStop(0, 'rgba(255,45,85,0.35)')
|
| 510 |
+
g.addColorStop(1, 'rgba(255,45,85,0)')
|
| 511 |
+
ctx.fillStyle = g
|
| 512 |
+
ctx.fillRect(c.x - sp * 1.2, c.y, sp * 2.4, 3 * c.k)
|
| 513 |
+
}
|
| 514 |
+
for (let j = 0; j < 5; j++) {
|
| 515 |
+
const zr = fract(-lt * 0.9 + hash(j * 2.7)) * 180 + 2
|
| 516 |
+
const X = j % 2 ? -1.4 : -4.2
|
| 517 |
+
const c = proj(X, 0.7, camZ + zr)
|
| 518 |
+
const sp = 0.6 * c.k
|
| 519 |
+
glowBlob(ctx, c.x - sp, c.y, Math.max(3, 1.3 * c.k), '#eaf4ff', 0.95)
|
| 520 |
+
glowBlob(ctx, c.x + sp, c.y, Math.max(3, 1.3 * c.k), '#eaf4ff', 0.95)
|
| 521 |
+
const c2 = proj(X, 0.7, camZ + zr + 14)
|
| 522 |
+
ctx.strokeStyle = 'rgba(220,235,255,0.35)'
|
| 523 |
+
ctx.lineWidth = Math.max(1, 0.25 * c.k)
|
| 524 |
+
ctx.beginPath()
|
| 525 |
+
ctx.moveTo(c.x - sp, c.y)
|
| 526 |
+
ctx.lineTo(c2.x - sp * (c2.k / c.k), c2.y)
|
| 527 |
+
ctx.moveTo(c.x + sp, c.y)
|
| 528 |
+
ctx.lineTo(c2.x + sp * (c2.k / c.k), c2.y)
|
| 529 |
+
ctx.stroke()
|
| 530 |
+
}
|
| 531 |
+
ctx.restore()
|
| 532 |
+
resetCam(s)
|
| 533 |
+
speedLines(ctx, W / 2, hy, Math.max(W, H) * 0.9, t, 100, '#ffffff', 0.05 + a.kick * 0.12, 0.3)
|
| 534 |
+
// rider (rear view) at bottom centre
|
| 535 |
+
const rs = P ? W * 0.5 : H * 0.55
|
| 536 |
+
const bx = W / 2
|
| 537 |
+
const by = H * 1.0 + a.kick * u * 6
|
| 538 |
+
ctx.save()
|
| 539 |
+
ctx.translate(bx, by)
|
| 540 |
+
ctx.rotate(-curve * 0.14)
|
| 541 |
+
ctx.fillStyle = '#030305'
|
| 542 |
+
// tire
|
| 543 |
+
ctx.beginPath()
|
| 544 |
+
ctx.ellipse(0, -rs * 0.08, rs * 0.07, rs * 0.16, 0, 0, Math.PI * 2)
|
| 545 |
+
ctx.fill()
|
| 546 |
+
// body / seat
|
| 547 |
+
ctx.beginPath()
|
| 548 |
+
ctx.moveTo(-rs * 0.17, -rs * 0.22)
|
| 549 |
+
ctx.lineTo(rs * 0.17, -rs * 0.22)
|
| 550 |
+
ctx.lineTo(rs * 0.12, -rs * 0.38)
|
| 551 |
+
ctx.lineTo(-rs * 0.12, -rs * 0.38)
|
| 552 |
+
ctx.closePath()
|
| 553 |
+
ctx.fill()
|
| 554 |
+
// rider torso & helmet
|
| 555 |
+
ctx.beginPath()
|
| 556 |
+
ctx.moveTo(-rs * 0.2, -rs * 0.34)
|
| 557 |
+
ctx.quadraticCurveTo(-rs * 0.24, -rs * 0.6, -rs * 0.1, -rs * 0.72)
|
| 558 |
+
ctx.lineTo(rs * 0.1, -rs * 0.72)
|
| 559 |
+
ctx.quadraticCurveTo(rs * 0.24, -rs * 0.6, rs * 0.2, -rs * 0.34)
|
| 560 |
+
ctx.closePath()
|
| 561 |
+
ctx.fill()
|
| 562 |
+
ctx.beginPath()
|
| 563 |
+
ctx.ellipse(0, -rs * 0.8, rs * 0.085, rs * 0.095, 0, 0, Math.PI * 2)
|
| 564 |
+
ctx.fill()
|
| 565 |
+
// arms to handlebars
|
| 566 |
+
ctx.strokeStyle = '#030305'
|
| 567 |
+
ctx.lineCap = 'round'
|
| 568 |
+
ctx.lineWidth = rs * 0.05
|
| 569 |
+
ctx.beginPath()
|
| 570 |
+
ctx.moveTo(-rs * 0.17, -rs * 0.62)
|
| 571 |
+
ctx.lineTo(-rs * 0.3, -rs * 0.46)
|
| 572 |
+
ctx.moveTo(rs * 0.17, -rs * 0.62)
|
| 573 |
+
ctx.lineTo(rs * 0.3, -rs * 0.46)
|
| 574 |
+
ctx.stroke()
|
| 575 |
+
// rim light
|
| 576 |
+
ctx.strokeStyle = rgba(PALETTE.cyan, 0.6)
|
| 577 |
+
ctx.lineWidth = Math.max(1, rs * 0.006)
|
| 578 |
+
ctx.beginPath()
|
| 579 |
+
ctx.ellipse(0, -rs * 0.8, rs * 0.085, rs * 0.095, 0, Math.PI * 1.1, Math.PI * 1.7)
|
| 580 |
+
ctx.stroke()
|
| 581 |
+
// tail light
|
| 582 |
+
glowBlob(ctx, 0, -rs * 0.25, rs * 0.12, PALETTE.red, 0.95)
|
| 583 |
+
ctx.fillStyle = '#ff6a80'
|
| 584 |
+
ctx.fillRect(-rs * 0.06, -rs * 0.265, rs * 0.12, rs * 0.025)
|
| 585 |
+
ctx.restore()
|
| 586 |
+
rain(ctx, W, H, t, { count: Math.floor(160 * area(s)) + 40, speed: H * 3, len: u * 120, slant: 0.0, color: '#d0e0ff', alpha: 0.14, width: Math.max(1, u * 1.2) })
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
function sideShot(s: SceneCtx) {
|
| 590 |
+
const { ctx, W, H, P, lt, u, t, a } = s
|
| 591 |
+
const gy = P ? H * 0.64 : H * 0.72
|
| 592 |
+
vGradient(ctx, 0, 0, W, gy, [
|
| 593 |
+
[0, '#0a0818'],
|
| 594 |
+
[0.6, '#3a1440'],
|
| 595 |
+
[1, '#a0305a'],
|
| 596 |
+
])
|
| 597 |
+
glowBlob(ctx, W * 0.5, gy - H * 0.2, Math.max(W, H) * 0.5, '#ff6a8a', 0.3)
|
| 598 |
+
skyline(ctx, { W, seed: 13, baseY: gy - H * 0.06, scroll: lt * u * 120, cell: u * 60, minH: H * 0.1, maxH: H * 0.4, color: '#0a0812', t, density: 0.2, winAlpha: 0.5 })
|
| 599 |
+
// fast mid layer → motion blurred streak lights
|
| 600 |
+
ctx.save()
|
| 601 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 602 |
+
for (let i = 0; i < 110; i++) {
|
| 603 |
+
const y = gy - H * (0.05 + 0.5 * hash(i * 1.7))
|
| 604 |
+
const len = u * (120 + 380 * hash(i * 3.1))
|
| 605 |
+
const x = fract(hash(i * 2.3) - lt * (1.4 + hash(i) * 1.2)) * (W + len * 2) - len
|
| 606 |
+
const col = [PALETTE.sodium, PALETTE.cyan, PALETTE.red, '#ff5fa2'][i % 4]
|
| 607 |
+
const g = ctx.createLinearGradient(x, 0, x + len, 0)
|
| 608 |
+
g.addColorStop(0, rgba(col, 0))
|
| 609 |
+
g.addColorStop(0.7, rgba(col, 0.5))
|
| 610 |
+
g.addColorStop(1, rgba(col, 0.9))
|
| 611 |
+
ctx.fillStyle = g
|
| 612 |
+
ctx.fillRect(x, y, len, Math.max(1.5, u * (3 + 6 * hash(i * 5))))
|
| 613 |
+
}
|
| 614 |
+
ctx.restore()
|
| 615 |
+
// road
|
| 616 |
+
ctx.fillStyle = '#050507'
|
| 617 |
+
ctx.fillRect(0, gy, W, H - gy)
|
| 618 |
+
ctx.fillStyle = rgba(PALETTE.bone, 0.6)
|
| 619 |
+
for (let i = 0; i < 8; i++) {
|
| 620 |
+
const x = fract(i / 8 - lt * 3) * (W + u * 300) - u * 300
|
| 621 |
+
ctx.fillRect(x, gy + (H - gy) * 0.45, u * 200, u * 6)
|
| 622 |
+
}
|
| 623 |
+
wetReflection(ctx, s.scratch, W, H, gy, t, 0.35, u * 2)
|
| 624 |
+
// bike side view
|
| 625 |
+
const bx = W * 0.5 + Math.sin(lt * 1.3) * u * 20
|
| 626 |
+
const bs = P ? W * 0.42 : H * 0.36
|
| 627 |
+
const by = gy - bs * 0.03 + a.kick * u * 4
|
| 628 |
+
const rw = bs * 0.2
|
| 629 |
+
// tail light streak
|
| 630 |
+
const tg = ctx.createLinearGradient(bx - bs * 2.5, 0, bx - bs * 0.5, 0)
|
| 631 |
+
tg.addColorStop(0, 'rgba(255,45,85,0)')
|
| 632 |
+
tg.addColorStop(1, 'rgba(255,45,85,0.85)')
|
| 633 |
+
ctx.fillStyle = tg
|
| 634 |
+
ctx.fillRect(bx - bs * 2.5, by - bs * 0.42, bs * 2, Math.max(2, bs * 0.03))
|
| 635 |
+
// headlight beam
|
| 636 |
+
lightCone(ctx, bx + bs * 0.55, by - bs * 0.45, W * 0.6, 0.12, -Math.PI / 2, '#eaf4ff', 0.18)
|
| 637 |
+
ctx.fillStyle = '#030305'
|
| 638 |
+
ctx.strokeStyle = '#030305'
|
| 639 |
+
for (const wx of [bx - bs * 0.45, bx + bs * 0.45]) {
|
| 640 |
+
ctx.lineWidth = rw * 0.35
|
| 641 |
+
ctx.beginPath()
|
| 642 |
+
ctx.arc(wx, by - rw, rw * 0.83, 0, Math.PI * 2)
|
| 643 |
+
ctx.stroke()
|
| 644 |
+
// spokes blur
|
| 645 |
+
ctx.save()
|
| 646 |
+
ctx.strokeStyle = 'rgba(200,210,230,0.25)'
|
| 647 |
+
ctx.lineWidth = Math.max(1, u * 1.5)
|
| 648 |
+
ctx.beginPath()
|
| 649 |
+
for (let k = 0; k < 6; k++) {
|
| 650 |
+
const ang = k * (Math.PI / 3) + lt * 40
|
| 651 |
+
ctx.moveTo(wx, by - rw)
|
| 652 |
+
ctx.lineTo(wx + Math.cos(ang) * rw * 0.7, by - rw + Math.sin(ang) * rw * 0.7)
|
| 653 |
+
}
|
| 654 |
+
ctx.stroke()
|
| 655 |
+
ctx.restore()
|
| 656 |
+
}
|
| 657 |
+
ctx.beginPath()
|
| 658 |
+
ctx.moveTo(bx - bs * 0.55, by - rw * 1.6)
|
| 659 |
+
ctx.lineTo(bx - bs * 0.2, by - bs * 0.5)
|
| 660 |
+
ctx.lineTo(bx + bs * 0.3, by - bs * 0.52)
|
| 661 |
+
ctx.lineTo(bx + bs * 0.55, by - bs * 0.42)
|
| 662 |
+
ctx.lineTo(bx + bs * 0.45, by - rw)
|
| 663 |
+
ctx.lineTo(bx - bs * 0.1, by - rw * 0.9)
|
| 664 |
+
ctx.closePath()
|
| 665 |
+
ctx.fill()
|
| 666 |
+
// rider crouched
|
| 667 |
+
ctx.beginPath()
|
| 668 |
+
ctx.moveTo(bx - bs * 0.25, by - bs * 0.5)
|
| 669 |
+
ctx.quadraticCurveTo(bx - bs * 0.05, by - bs * 0.92, bx + bs * 0.28, by - bs * 0.82)
|
| 670 |
+
ctx.lineTo(bx + bs * 0.32, by - bs * 0.7)
|
| 671 |
+
ctx.lineTo(bx + bs * 0.05, by - bs * 0.55)
|
| 672 |
+
ctx.closePath()
|
| 673 |
+
ctx.fill()
|
| 674 |
+
ctx.beginPath()
|
| 675 |
+
ctx.arc(bx + bs * 0.33, by - bs * 0.88, bs * 0.075, 0, Math.PI * 2)
|
| 676 |
+
ctx.fill()
|
| 677 |
+
ctx.lineWidth = bs * 0.05
|
| 678 |
+
ctx.lineCap = 'round'
|
| 679 |
+
ctx.beginPath()
|
| 680 |
+
ctx.moveTo(bx + bs * 0.2, by - bs * 0.78)
|
| 681 |
+
ctx.lineTo(bx + bs * 0.42, by - bs * 0.6)
|
| 682 |
+
ctx.moveTo(bx - bs * 0.1, by - bs * 0.55)
|
| 683 |
+
ctx.lineTo(bx + bs * 0.05, by - bs * 0.3)
|
| 684 |
+
ctx.lineTo(bx + bs * 0.12, by - bs * 0.22)
|
| 685 |
+
ctx.stroke()
|
| 686 |
+
// rim light along the top
|
| 687 |
+
ctx.strokeStyle = rgba(PALETTE.cyan, 0.7)
|
| 688 |
+
ctx.lineWidth = Math.max(1, u * 2)
|
| 689 |
+
ctx.beginPath()
|
| 690 |
+
ctx.moveTo(bx - bs * 0.25, by - bs * 0.52)
|
| 691 |
+
ctx.quadraticCurveTo(bx - bs * 0.05, by - bs * 0.94, bx + bs * 0.28, by - bs * 0.84)
|
| 692 |
+
ctx.stroke()
|
| 693 |
+
glowBlob(ctx, bx - bs * 0.5, by - bs * 0.42, bs * 0.1, PALETTE.red, 1)
|
| 694 |
+
glowBlob(ctx, bx + bs * 0.56, by - bs * 0.45, bs * 0.1, '#ffffff', 1)
|
| 695 |
+
// horizontal speed lines
|
| 696 |
+
ctx.fillStyle = 'rgba(255,255,255,0.18)'
|
| 697 |
+
for (let i = 0; i < 30; i++) {
|
| 698 |
+
const y = hash(i * 7.7) * H
|
| 699 |
+
const x = fract(hash(i) - lt * 4) * W * 1.5 - W * 0.25
|
| 700 |
+
ctx.fillRect(x, y, u * (200 + 300 * hash(i * 2)), Math.max(1, u * 1.5))
|
| 701 |
+
}
|
| 702 |
+
void fogBand
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
// =====================================================================
|
| 706 |
+
// S9 — 终章·黑街之王 (127.64 – 144.3s)
|
| 707 |
+
// =====================================================================
|
| 708 |
+
function titlePoints(s: SceneCtx): { x: number; y: number }[] {
|
| 709 |
+
const key = `pts:${s.W}x${s.H}`
|
| 710 |
+
const cached = s.cache.get(key) as { x: number; y: number }[] | undefined
|
| 711 |
+
if (cached) return cached
|
| 712 |
+
const sc = 0.25
|
| 713 |
+
const c = document.createElement('canvas')
|
| 714 |
+
c.width = Math.max(4, Math.round(s.W * sc))
|
| 715 |
+
c.height = Math.max(4, Math.round(s.H * sc))
|
| 716 |
+
const g = c.getContext('2d')!
|
| 717 |
+
const L = titleLayout(s)
|
| 718 |
+
g.fillStyle = '#fff'
|
| 719 |
+
g.textAlign = 'center'
|
| 720 |
+
g.textBaseline = 'middle'
|
| 721 |
+
g.font = `${L.size * sc}px ${FONT.neon}`
|
| 722 |
+
for (const p of L.chars) g.fillText(p.c, p.x * sc, p.y * sc)
|
| 723 |
+
const img = g.getImageData(0, 0, c.width, c.height).data
|
| 724 |
+
const pts: { x: number; y: number }[] = []
|
| 725 |
+
const step = Math.max(1, Math.round(Math.min(c.width, c.height) / 140))
|
| 726 |
+
for (let y = 0; y < c.height; y += step) {
|
| 727 |
+
for (let x = 0; x < c.width; x += step) {
|
| 728 |
+
if (img[(y * c.width + x) * 4 + 3] > 128) pts.push({ x: x / sc, y: y / sc })
|
| 729 |
+
}
|
| 730 |
+
}
|
| 731 |
+
s.cache.set(key, pts)
|
| 732 |
+
return pts
|
| 733 |
+
}
|
| 734 |
+
|
| 735 |
+
function titleLayout(s: SceneCtx) {
|
| 736 |
+
const { W, H, P } = s
|
| 737 |
+
const size = P ? Math.min(W * 0.5, H * 0.22) : Math.min(W * 0.26, H * 0.42)
|
| 738 |
+
const cy = P ? H * 0.4 : H * 0.42
|
| 739 |
+
const chars = P
|
| 740 |
+
? [
|
| 741 |
+
{ c: '黑', x: W / 2, y: cy - size * 0.55 },
|
| 742 |
+
{ c: '街', x: W / 2, y: cy + size * 0.55 },
|
| 743 |
+
]
|
| 744 |
+
: [
|
| 745 |
+
{ c: '黑', x: W / 2 - size * 0.56, y: cy },
|
| 746 |
+
{ c: '街', x: W / 2 + size * 0.56, y: cy },
|
| 747 |
+
]
|
| 748 |
+
return { size, cy, chars }
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
export function sFinale(s: SceneCtx) {
|
| 752 |
+
const { ctx, W, H, P, lt, u, t, a } = s
|
| 753 |
+
if (t >= 144.22) {
|
| 754 |
+
ctx.fillStyle = '#000'
|
| 755 |
+
ctx.fillRect(0, 0, W, H)
|
| 756 |
+
return
|
| 757 |
+
}
|
| 758 |
+
// aerial city
|
| 759 |
+
vGradient(ctx, 0, 0, W, H, [
|
| 760 |
+
[0, '#05081a'],
|
| 761 |
+
[0.55, '#16234a'],
|
| 762 |
+
[1, '#4a1a3a'],
|
| 763 |
+
])
|
| 764 |
+
const rise = easeInOutCubic(clamp(lt / 7))
|
| 765 |
+
const baseY = H * (0.95 + 0.25 * rise)
|
| 766 |
+
skyline(ctx, { W, seed: 5, baseY: baseY - H * 0.16, scroll: lt * u * 10, cell: u * 50, minH: H * 0.1, maxH: H * 0.35, color: '#070a14', t, density: 0.25, winAlpha: 0.5 })
|
| 767 |
+
skyline(ctx, { W, seed: 6, baseY, scroll: lt * u * 24, cell: u * 90, minH: H * 0.15, maxH: H * 0.5, color: '#04050a', t, density: 0.3, winAlpha: 0.8, litMod: (_k, row, rows) => (1 - row / rows < a.kick * 0.8 ? 0.6 : 0) })
|
| 768 |
+
// neon bursts on kicks
|
| 769 |
+
ctx.save()
|
| 770 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 771 |
+
const b = a.beat
|
| 772 |
+
for (let k = 0; k < 3; k++) {
|
| 773 |
+
const bi = b - k
|
| 774 |
+
const age = a.beatPos - bi
|
| 775 |
+
if (age < 0 || age > 2.5) continue
|
| 776 |
+
const bx = W * (0.15 + 0.7 * hash(bi * 1.3))
|
| 777 |
+
const byy = H * (0.15 + 0.3 * hash(bi * 2.1))
|
| 778 |
+
const col = [PALETTE.red, PALETTE.cyan, PALETTE.sodium, PALETTE.violet][((bi % 4) + 4) % 4]
|
| 779 |
+
const R = Math.min(W, H) * 0.22 * easeOutExpo(age / 1.2)
|
| 780 |
+
ctx.fillStyle = rgba(col, clamp(1 - age / 2.5))
|
| 781 |
+
for (let p = 0; p < 36; p++) {
|
| 782 |
+
const ang = (p / 36) * Math.PI * 2 + hash(bi)
|
| 783 |
+
const rr = R * (0.85 + 0.15 * hash2(p, bi))
|
| 784 |
+
ctx.fillRect(bx + Math.cos(ang) * rr, byy + Math.sin(ang) * rr + age * age * u * 20, u * 4, u * 4)
|
| 785 |
+
}
|
| 786 |
+
}
|
| 787 |
+
ctx.restore()
|
| 788 |
+
// particles converge into the title
|
| 789 |
+
const pts = titlePoints(s)
|
| 790 |
+
const L = titleLayout(s)
|
| 791 |
+
const conv = clamp((lt - 5) / 4.5)
|
| 792 |
+
ctx.save()
|
| 793 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 794 |
+
const n = pts.length
|
| 795 |
+
for (let i = 0; i < n; i++) {
|
| 796 |
+
const p = pts[i]
|
| 797 |
+
const d = hash(i * 0.37)
|
| 798 |
+
const k = easeInOutCubic(clamp((conv - d * 0.4) / 0.6))
|
| 799 |
+
if (k <= 0 && lt < 4) continue
|
| 800 |
+
const ang = hash(i * 1.9) * Math.PI * 2 + lt * 0.4
|
| 801 |
+
const rad = Math.max(W, H) * (0.3 + 0.6 * hash(i * 2.9))
|
| 802 |
+
const sx = W / 2 + Math.cos(ang) * rad
|
| 803 |
+
const sy = H / 2 + Math.sin(ang) * rad * 0.6
|
| 804 |
+
const jit = a.kick * u * 6 * (hash2(i, a.beat) - 0.5)
|
| 805 |
+
const x = lerp(sx, p.x, k) + jit
|
| 806 |
+
const y = lerp(sy, p.y, k) + jit
|
| 807 |
+
ctx.fillStyle = i % 5 === 0 ? PALETTE.cyan : i % 7 === 0 ? PALETTE.sodium : PALETTE.red
|
| 808 |
+
ctx.globalAlpha = clamp((lt - 3.5) / 1.5) * (1 - smoothstep(9.5, 11, lt) * 0.7)
|
| 809 |
+
const sz = u * (3 + 3 * hash(i))
|
| 810 |
+
ctx.fillRect(x - sz / 2, y - sz / 2, sz, sz)
|
| 811 |
+
}
|
| 812 |
+
ctx.restore()
|
| 813 |
+
// solid neon title
|
| 814 |
+
const titleOn = smoothstep(9.2, 10.2, lt)
|
| 815 |
+
if (titleOn > 0) {
|
| 816 |
+
const fl = a.drop && hash(a.beat * 3.1) > 0.8 && a.beatPhase < 0.1 ? 0.3 : 1
|
| 817 |
+
glowBlob(ctx, W / 2, L.cy, L.size * 2.4, PALETTE.red, 0.3 * titleOn)
|
| 818 |
+
for (const c of L.chars) neonText(ctx, c.c, c.x, c.y, L.size, PALETTE.red, titleOn * fl, { tube: true, blur: 0.45 })
|
| 819 |
+
const fs = L.size * (P ? 0.24 : 0.2)
|
| 820 |
+
const sy = P ? L.cy + L.size * 1.45 : L.cy + L.size * 0.85
|
| 821 |
+
neonText(ctx, 'B L A C K S T R E E T', W / 2, sy, fs, PALETTE.cyan, titleOn, { font: FONT.latin, blur: 0.5 })
|
| 822 |
+
}
|
| 823 |
+
// credits
|
| 824 |
+
const cr = smoothstep(11, 12, lt)
|
| 825 |
+
if (cr > 0) {
|
| 826 |
+
ctx.save()
|
| 827 |
+
ctx.globalAlpha = cr
|
| 828 |
+
ctx.textAlign = 'center'
|
| 829 |
+
ctx.fillStyle = PALETTE.bone
|
| 830 |
+
const fs = (P ? W * 0.034 : H * 0.03)
|
| 831 |
+
ctx.font = `${fs}px ${FONT.black}`
|
| 832 |
+
const y0 = P ? H * 0.72 : H * 0.8
|
| 833 |
+
ctx.fillText('音乐 |《黑街》DJ葱姜蒜进行曲 — DJ鐘董', W / 2, y0)
|
| 834 |
+
ctx.globalAlpha = cr * 0.7
|
| 835 |
+
ctx.font = `${fs * 0.75}px ${FONT.black}`
|
| 836 |
+
ctx.fillText('画面 | 原创程序化动画 · 浏览器实时渲染', W / 2, y0 + fs * 1.6)
|
| 837 |
+
ctx.restore()
|
| 838 |
+
}
|
| 839 |
+
rain(ctx, W, H, t, { count: Math.floor(200 * area(s)) + 40, speed: H * 1.6, len: u * 60, slant: 0.1, color: '#a9c2d6', alpha: 0.2, width: Math.max(1, u * 1.3) })
|
| 840 |
+
void camera
|
| 841 |
+
void fbm
|
| 842 |
+
}
|
src/mv/engine/timeline.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { BAR, BEAT, BREAK, DROP1, DROP2, DURATION } from './audio'
|
| 2 |
+
import { sDrop1, sIgnite, sRooftop, sStreet, sTunnel } from './scenesA'
|
| 3 |
+
import { sFinale, sHeartbeat, sHighway, sMarket } from './scenesB'
|
| 4 |
+
import type { SceneFn } from './types'
|
| 5 |
+
|
| 6 |
+
export interface SceneDef {
|
| 7 |
+
id: string
|
| 8 |
+
name: string
|
| 9 |
+
start: number
|
| 10 |
+
end: number
|
| 11 |
+
fn: SceneFn
|
| 12 |
+
color: string
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
const b1 = (k: number) => DROP1 + k * BEAT
|
| 16 |
+
const b2 = (k: number) => DROP2 + k * BEAT
|
| 17 |
+
|
| 18 |
+
export const SCENES: SceneDef[] = [
|
| 19 |
+
{ id: 'ignite', name: '开场·霓虹点亮', start: 0, end: b1(-51), fn: sIgnite, color: '#ff2d55' },
|
| 20 |
+
{ id: 'street', name: '雨夜长街', start: b1(-51), end: b1(-25), fn: sStreet, color: '#3de0ff' },
|
| 21 |
+
{ id: 'tunnel', name: '蓄力·隧道', start: b1(-25), end: DROP1, fn: sTunnel, color: '#ffb35c' },
|
| 22 |
+
{ id: 'drop1', name: 'Drop1·霓虹爆裂', start: DROP1, end: DROP1 + 8 * BAR, fn: sDrop1, color: '#ff2d55' },
|
| 23 |
+
{ id: 'rooftop', name: '天台·红月', start: DROP1 + 8 * BAR, end: BREAK, fn: sRooftop, color: '#ff7a4a' },
|
| 24 |
+
{ id: 'market', name: '葱姜蒜夜市', start: BREAK, end: b2(-32), fn: sMarket, color: '#ffb35c' },
|
| 25 |
+
{ id: 'heart', name: '暗场·心跳', start: b2(-32), end: DROP2, fn: sHeartbeat, color: '#9b1530' },
|
| 26 |
+
{ id: 'highway', name: 'Drop2·飙车光轨', start: DROP2, end: DROP2 + 8 * BAR, fn: sHighway, color: '#3de0ff' },
|
| 27 |
+
{ id: 'finale', name: '终章·黑街之王', start: DROP2 + 8 * BAR, end: DURATION, fn: sFinale, color: '#ff2d55' },
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
export function sceneAt(t: number): SceneDef {
|
| 31 |
+
for (const s of SCENES) if (t < s.end) return s
|
| 32 |
+
return SCENES[SCENES.length - 1]
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
export interface Caption {
|
| 36 |
+
start: number
|
| 37 |
+
end: number
|
| 38 |
+
text: string
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Original subtitle lines (not the song lyrics).
|
| 42 |
+
export const CAPTIONS: Caption[] = [
|
| 43 |
+
{ start: 10.4, end: 13.9, text: '凌晨两点,雨还没有停' },
|
| 44 |
+
{ start: 14.4, end: 18.0, text: '霓虹替我记住每一条路' },
|
| 45 |
+
{ start: 18.6, end: 23.2, text: '这条街,从不问你的来处' },
|
| 46 |
+
{ start: 25.0, end: 28.6, text: '只问你——' },
|
| 47 |
+
{ start: 29.0, end: 34.6, text: '敢不敢,走到尽头' },
|
| 48 |
+
{ start: 57.0, end: 60.8, text: '城市睡了,红月醒着' },
|
| 49 |
+
{ start: 61.5, end: 65.5, text: '风把影子吹得很长' },
|
| 50 |
+
{ start: 66.0, end: 71.6, text: '灯海在脚下翻涌' },
|
| 51 |
+
{ start: 74.5, end: 78.6, text: '穿过夜市的烟火' },
|
| 52 |
+
{ start: 79.2, end: 83.4, text: '葱、姜、蒜,香气还热着' },
|
| 53 |
+
{ start: 84.0, end: 89.5, text: '人间,就藏在这一碗里' },
|
| 54 |
+
{ start: 92.4, end: 96.4, text: '灯,灭了' },
|
| 55 |
+
{ start: 97.0, end: 101.0, text: '只剩心跳' },
|
| 56 |
+
{ start: 101.6, end: 106.6, text: '听——它在加速' },
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
export function captionAt(t: number): Caption | null {
|
| 60 |
+
for (const c of CAPTIONS) if (t >= c.start && t < c.end) return c
|
| 61 |
+
return null
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/** Hard cuts that get a flash + glitch accent. */
|
| 65 |
+
export const CUTS: number[] = (() => {
|
| 66 |
+
const cuts = SCENES.slice(1).map((s) => s.start)
|
| 67 |
+
for (let k = 1; k < 8; k++) cuts.push(DROP1 + k * BAR)
|
| 68 |
+
for (let k = 1; k < 4; k++) cuts.push(DROP2 + k * 2 * BAR)
|
| 69 |
+
return cuts.sort((a, b) => a - b)
|
| 70 |
+
})()
|
src/mv/engine/types.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { AudioFrame } from './audio'
|
| 2 |
+
|
| 3 |
+
export interface SceneCtx {
|
| 4 |
+
ctx: CanvasRenderingContext2D
|
| 5 |
+
W: number
|
| 6 |
+
H: number
|
| 7 |
+
/** portrait (H > W) */
|
| 8 |
+
P: boolean
|
| 9 |
+
/** unit: min(W,H)/1000 */
|
| 10 |
+
u: number
|
| 11 |
+
/** global time */
|
| 12 |
+
t: number
|
| 13 |
+
/** local time in scene */
|
| 14 |
+
lt: number
|
| 15 |
+
dur: number
|
| 16 |
+
a: AudioFrame
|
| 17 |
+
scratch: HTMLCanvasElement
|
| 18 |
+
cache: Map<string, unknown>
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export type SceneFn = (s: SceneCtx) => void
|
| 22 |
+
|
| 23 |
+
/** Apply a camera: world point (cx,cy) appears at screen centre, scaled by zoom. */
|
| 24 |
+
export function camera(s: SceneCtx, zoom: number, cx: number, cy: number, rot = 0) {
|
| 25 |
+
const { ctx, W, H } = s
|
| 26 |
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
| 27 |
+
ctx.translate(W / 2, H / 2)
|
| 28 |
+
if (rot) ctx.rotate(rot)
|
| 29 |
+
ctx.scale(zoom, zoom)
|
| 30 |
+
ctx.translate(-cx, -cy)
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export function resetCam(s: SceneCtx) {
|
| 34 |
+
s.ctx.setTransform(1, 0, 0, 1, 0, 0)
|
| 35 |
+
}
|
src/mv/engine/util.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Deterministic helpers — no Math.random anywhere in the render path so that
|
| 2 |
+
// preview, covers and MP4 export produce identical frames for the same time t.
|
| 3 |
+
|
| 4 |
+
export const clamp = (x: number, a = 0, b = 1) => (x < a ? a : x > b ? b : x)
|
| 5 |
+
export const lerp = (a: number, b: number, t: number) => a + (b - a) * t
|
| 6 |
+
export const invLerp = (a: number, b: number, x: number) => clamp((x - a) / (b - a))
|
| 7 |
+
export const smoothstep = (a: number, b: number, x: number) => {
|
| 8 |
+
const t = invLerp(a, b, x)
|
| 9 |
+
return t * t * (3 - 2 * t)
|
| 10 |
+
}
|
| 11 |
+
export const fract = (x: number) => x - Math.floor(x)
|
| 12 |
+
export const easeOutCubic = (t: number) => 1 - Math.pow(1 - clamp(t), 3)
|
| 13 |
+
export const easeInCubic = (t: number) => Math.pow(clamp(t), 3)
|
| 14 |
+
export const easeInOutCubic = (t: number) => {
|
| 15 |
+
t = clamp(t)
|
| 16 |
+
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2
|
| 17 |
+
}
|
| 18 |
+
export const easeOutExpo = (t: number) => (t >= 1 ? 1 : 1 - Math.pow(2, -10 * clamp(t)))
|
| 19 |
+
export const easeInExpo = (t: number) => (t <= 0 ? 0 : Math.pow(2, 10 * clamp(t) - 10))
|
| 20 |
+
export const easeOutBack = (t: number) => {
|
| 21 |
+
const c1 = 1.70158
|
| 22 |
+
const c3 = c1 + 1
|
| 23 |
+
t = clamp(t)
|
| 24 |
+
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2)
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/** 0..1 hash of a number */
|
| 28 |
+
export function hash(n: number): number {
|
| 29 |
+
const x = Math.sin(n * 127.1 + 311.7) * 43758.5453123
|
| 30 |
+
return x - Math.floor(x)
|
| 31 |
+
}
|
| 32 |
+
export function hash2(a: number, b: number): number {
|
| 33 |
+
const x = Math.sin(a * 127.1 + b * 311.7 + 74.7) * 43758.5453123
|
| 34 |
+
return x - Math.floor(x)
|
| 35 |
+
}
|
| 36 |
+
export function hash3(a: number, b: number, c: number): number {
|
| 37 |
+
const x = Math.sin(a * 127.1 + b * 311.7 + c * 269.5 + 17.3) * 43758.5453123
|
| 38 |
+
return x - Math.floor(x)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/** smooth 1D value noise, -1..1 */
|
| 42 |
+
export function noise1(x: number, seed = 0): number {
|
| 43 |
+
const i = Math.floor(x)
|
| 44 |
+
const f = x - i
|
| 45 |
+
const u = f * f * (3 - 2 * f)
|
| 46 |
+
return lerp(hash(i + seed * 57.3), hash(i + 1 + seed * 57.3), u) * 2 - 1
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/** fractal noise, -1..1 */
|
| 50 |
+
export function fbm(x: number, seed = 0): number {
|
| 51 |
+
return noise1(x, seed) * 0.6 + noise1(x * 2.1, seed + 3) * 0.28 + noise1(x * 4.3, seed + 7) * 0.12
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
export function hexToRgb(hex: string): [number, number, number] {
|
| 55 |
+
const h = hex.replace('#', '')
|
| 56 |
+
const n = parseInt(h.length === 3 ? h.split('').map((c) => c + c).join('') : h, 16)
|
| 57 |
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255]
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
export function rgba(hex: string, a: number): string {
|
| 61 |
+
const [r, g, b] = hexToRgb(hex)
|
| 62 |
+
return `rgba(${r},${g},${b},${clamp(a)})`
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
export function mixHex(a: string, b: string, t: number): string {
|
| 66 |
+
const A = hexToRgb(a)
|
| 67 |
+
const B = hexToRgb(b)
|
| 68 |
+
const r = Math.round(lerp(A[0], B[0], t))
|
| 69 |
+
const g = Math.round(lerp(A[1], B[1], t))
|
| 70 |
+
const bb = Math.round(lerp(A[2], B[2], t))
|
| 71 |
+
return `rgb(${r},${g},${bb})`
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/** Pulse that is 1 at the start of a period and decays. */
|
| 75 |
+
export const decay = (phase: number, k = 6) => Math.exp(-phase * k)
|
| 76 |
+
|
| 77 |
+
/** Flicker for neon: returns 0/1 noisy pattern while `amount` in 0..1 */
|
| 78 |
+
export function flicker(t: number, seed: number, rate = 24): number {
|
| 79 |
+
return hash2(Math.floor(t * rate), seed) > 0.45 ? 1 : 0.15
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
export const PALETTE = {
|
| 83 |
+
ink: '#05060a',
|
| 84 |
+
night: '#0b1420',
|
| 85 |
+
navy: '#0f1d2b',
|
| 86 |
+
steel: '#1d3342',
|
| 87 |
+
slate: '#2e363c',
|
| 88 |
+
sodium: '#ffb35c',
|
| 89 |
+
amber: '#ff8a3d',
|
| 90 |
+
skin: '#cfa783',
|
| 91 |
+
red: '#ff2d55',
|
| 92 |
+
blood: '#9b1530',
|
| 93 |
+
wine: '#3b0a10',
|
| 94 |
+
cyan: '#3de0ff',
|
| 95 |
+
teal: '#1fb5a8',
|
| 96 |
+
violet: '#8a5cff',
|
| 97 |
+
bone: '#f1e6d2',
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
export const FONT = {
|
| 101 |
+
neon: '"MV Neon", "ZCOOL QingKe HuangYou", "PingFang SC", "Microsoft YaHei", sans-serif',
|
| 102 |
+
black: '"MV Black", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
|
| 103 |
+
latin: '"MV Latin", "Anton", Impact, "Arial Narrow", sans-serif',
|
| 104 |
+
}
|
src/mv/styles.css
ADDED
|
@@ -0,0 +1,816 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.mv-root {
|
| 2 |
+
--bg: #07080c;
|
| 3 |
+
--panel: #0e1118;
|
| 4 |
+
--panel2: #141823;
|
| 5 |
+
--line: rgba(255, 255, 255, 0.08);
|
| 6 |
+
--fg: #ece6da;
|
| 7 |
+
--muted: #8b8f9c;
|
| 8 |
+
--red: #ff2d55;
|
| 9 |
+
--cyan: #3de0ff;
|
| 10 |
+
--amber: #ffb35c;
|
| 11 |
+
min-height: 100vh;
|
| 12 |
+
background:
|
| 13 |
+
radial-gradient(1200px 600px at 80% -10%, rgba(255, 45, 85, 0.12), transparent 60%),
|
| 14 |
+
radial-gradient(900px 500px at -10% 20%, rgba(61, 224, 255, 0.07), transparent 60%),
|
| 15 |
+
var(--bg);
|
| 16 |
+
color: var(--fg);
|
| 17 |
+
font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif;
|
| 18 |
+
padding: 0 0 48px;
|
| 19 |
+
-webkit-font-smoothing: antialiased;
|
| 20 |
+
}
|
| 21 |
+
.mv-root * {
|
| 22 |
+
box-sizing: border-box;
|
| 23 |
+
}
|
| 24 |
+
.mv-root button {
|
| 25 |
+
font: inherit;
|
| 26 |
+
cursor: pointer;
|
| 27 |
+
}
|
| 28 |
+
.mv-root button:disabled {
|
| 29 |
+
cursor: not-allowed;
|
| 30 |
+
opacity: 0.5;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/* header */
|
| 34 |
+
.mv-header {
|
| 35 |
+
position: sticky;
|
| 36 |
+
top: 0;
|
| 37 |
+
z-index: 20;
|
| 38 |
+
display: flex;
|
| 39 |
+
align-items: center;
|
| 40 |
+
justify-content: space-between;
|
| 41 |
+
gap: 16px;
|
| 42 |
+
padding: 14px clamp(14px, 4vw, 40px);
|
| 43 |
+
background: rgba(7, 8, 12, 0.82);
|
| 44 |
+
backdrop-filter: blur(12px);
|
| 45 |
+
-webkit-backdrop-filter: blur(12px);
|
| 46 |
+
border-bottom: 1px solid var(--line);
|
| 47 |
+
}
|
| 48 |
+
.mv-brand {
|
| 49 |
+
display: flex;
|
| 50 |
+
align-items: center;
|
| 51 |
+
gap: 12px;
|
| 52 |
+
min-width: 0;
|
| 53 |
+
}
|
| 54 |
+
.mv-logo {
|
| 55 |
+
font-family: 'MV Neon', 'ZCOOL QingKe HuangYou', sans-serif;
|
| 56 |
+
font-size: 34px;
|
| 57 |
+
line-height: 1;
|
| 58 |
+
color: #ff6b86;
|
| 59 |
+
text-shadow: 0 0 8px #ff2d55, 0 0 22px rgba(255, 45, 85, 0.7);
|
| 60 |
+
}
|
| 61 |
+
.mv-brand-en {
|
| 62 |
+
font-family: 'MV Latin', Impact, sans-serif;
|
| 63 |
+
letter-spacing: 0.18em;
|
| 64 |
+
font-size: 14px;
|
| 65 |
+
color: var(--cyan);
|
| 66 |
+
}
|
| 67 |
+
.mv-brand-sub {
|
| 68 |
+
font-size: 12px;
|
| 69 |
+
color: var(--muted);
|
| 70 |
+
white-space: nowrap;
|
| 71 |
+
overflow: hidden;
|
| 72 |
+
text-overflow: ellipsis;
|
| 73 |
+
}
|
| 74 |
+
.mv-nav {
|
| 75 |
+
display: flex;
|
| 76 |
+
gap: 4px;
|
| 77 |
+
}
|
| 78 |
+
.mv-nav a {
|
| 79 |
+
color: var(--fg);
|
| 80 |
+
text-decoration: none;
|
| 81 |
+
font-size: 14px;
|
| 82 |
+
padding: 6px 12px;
|
| 83 |
+
border-radius: 999px;
|
| 84 |
+
border: 1px solid transparent;
|
| 85 |
+
}
|
| 86 |
+
.mv-nav a:hover {
|
| 87 |
+
border-color: var(--line);
|
| 88 |
+
background: rgba(255, 255, 255, 0.04);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/* sections */
|
| 92 |
+
.mv-section {
|
| 93 |
+
max-width: 1200px;
|
| 94 |
+
margin: 0 auto;
|
| 95 |
+
padding: 28px clamp(12px, 4vw, 40px) 8px;
|
| 96 |
+
scroll-margin-top: 70px;
|
| 97 |
+
}
|
| 98 |
+
.mv-section h2 {
|
| 99 |
+
display: flex;
|
| 100 |
+
align-items: baseline;
|
| 101 |
+
flex-wrap: wrap;
|
| 102 |
+
gap: 10px;
|
| 103 |
+
margin: 0 0 14px;
|
| 104 |
+
font-family: 'MV Black', 'Noto Sans SC', sans-serif;
|
| 105 |
+
font-size: 24px;
|
| 106 |
+
letter-spacing: 0.02em;
|
| 107 |
+
}
|
| 108 |
+
.mv-section h2 small {
|
| 109 |
+
font-family: inherit;
|
| 110 |
+
font-size: 13px;
|
| 111 |
+
font-weight: 400;
|
| 112 |
+
color: var(--muted);
|
| 113 |
+
}
|
| 114 |
+
.mv-h-idx {
|
| 115 |
+
font-family: 'MV Latin', Impact, sans-serif;
|
| 116 |
+
color: var(--red);
|
| 117 |
+
font-size: 20px;
|
| 118 |
+
}
|
| 119 |
+
.mv-card {
|
| 120 |
+
background: linear-gradient(180deg, var(--panel), #0b0d13);
|
| 121 |
+
border: 1px solid var(--line);
|
| 122 |
+
border-radius: 14px;
|
| 123 |
+
padding: clamp(14px, 3vw, 24px);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/* segmented */
|
| 127 |
+
.mv-seg {
|
| 128 |
+
display: inline-flex;
|
| 129 |
+
flex-wrap: wrap;
|
| 130 |
+
gap: 4px;
|
| 131 |
+
padding: 4px;
|
| 132 |
+
background: rgba(255, 255, 255, 0.04);
|
| 133 |
+
border: 1px solid var(--line);
|
| 134 |
+
border-radius: 10px;
|
| 135 |
+
}
|
| 136 |
+
.mv-seg button {
|
| 137 |
+
border: 0;
|
| 138 |
+
background: transparent;
|
| 139 |
+
color: var(--muted);
|
| 140 |
+
padding: 7px 14px;
|
| 141 |
+
border-radius: 7px;
|
| 142 |
+
font-size: 14px;
|
| 143 |
+
}
|
| 144 |
+
.mv-seg button.on {
|
| 145 |
+
background: var(--red);
|
| 146 |
+
color: #fff;
|
| 147 |
+
box-shadow: 0 0 18px rgba(255, 45, 85, 0.45);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/* player */
|
| 151 |
+
.mv-player-head {
|
| 152 |
+
display: flex;
|
| 153 |
+
align-items: center;
|
| 154 |
+
justify-content: space-between;
|
| 155 |
+
flex-wrap: wrap;
|
| 156 |
+
gap: 10px;
|
| 157 |
+
margin-bottom: 14px;
|
| 158 |
+
}
|
| 159 |
+
.mv-player-head h2 {
|
| 160 |
+
margin: 0;
|
| 161 |
+
}
|
| 162 |
+
.mv-stage-wrap {
|
| 163 |
+
background: #000;
|
| 164 |
+
border-radius: 14px;
|
| 165 |
+
overflow: hidden;
|
| 166 |
+
border: 1px solid var(--line);
|
| 167 |
+
box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 45, 85, 0.08);
|
| 168 |
+
}
|
| 169 |
+
.mv-stage-wrap.portrait {
|
| 170 |
+
max-width: min(100%, calc((100vh - 200px) * 9 / 16 + 2px));
|
| 171 |
+
margin: 0 auto;
|
| 172 |
+
}
|
| 173 |
+
.mv-stage {
|
| 174 |
+
position: relative;
|
| 175 |
+
width: 100%;
|
| 176 |
+
aspect-ratio: 16 / 9;
|
| 177 |
+
background: #000;
|
| 178 |
+
cursor: pointer;
|
| 179 |
+
user-select: none;
|
| 180 |
+
-webkit-tap-highlight-color: transparent;
|
| 181 |
+
}
|
| 182 |
+
.mv-stage.portrait {
|
| 183 |
+
aspect-ratio: 9 / 16;
|
| 184 |
+
}
|
| 185 |
+
.mv-canvas {
|
| 186 |
+
position: absolute;
|
| 187 |
+
inset: 0;
|
| 188 |
+
width: 100%;
|
| 189 |
+
height: 100%;
|
| 190 |
+
display: block;
|
| 191 |
+
}
|
| 192 |
+
.mv-bigplay {
|
| 193 |
+
position: absolute;
|
| 194 |
+
left: 50%;
|
| 195 |
+
top: 50%;
|
| 196 |
+
transform: translate(-50%, -50%);
|
| 197 |
+
display: flex;
|
| 198 |
+
flex-direction: column;
|
| 199 |
+
align-items: center;
|
| 200 |
+
gap: 10px;
|
| 201 |
+
border: 0;
|
| 202 |
+
background: none;
|
| 203 |
+
color: #fff;
|
| 204 |
+
pointer-events: none;
|
| 205 |
+
}
|
| 206 |
+
.mv-bigplay svg {
|
| 207 |
+
width: 76px;
|
| 208 |
+
height: 76px;
|
| 209 |
+
padding: 18px;
|
| 210 |
+
border-radius: 50%;
|
| 211 |
+
background: rgba(255, 45, 85, 0.92);
|
| 212 |
+
box-shadow: 0 0 40px rgba(255, 45, 85, 0.7);
|
| 213 |
+
}
|
| 214 |
+
.mv-bigplay span {
|
| 215 |
+
font-size: 14px;
|
| 216 |
+
padding: 6px 12px;
|
| 217 |
+
border-radius: 999px;
|
| 218 |
+
background: rgba(0, 0, 0, 0.55);
|
| 219 |
+
}
|
| 220 |
+
.mv-scene-tag {
|
| 221 |
+
position: absolute;
|
| 222 |
+
left: 12px;
|
| 223 |
+
top: 12px;
|
| 224 |
+
font-size: 12px;
|
| 225 |
+
padding: 4px 10px;
|
| 226 |
+
background: rgba(0, 0, 0, 0.55);
|
| 227 |
+
border-left: 3px solid;
|
| 228 |
+
border-radius: 4px;
|
| 229 |
+
color: #fff;
|
| 230 |
+
pointer-events: none;
|
| 231 |
+
opacity: 0.85;
|
| 232 |
+
}
|
| 233 |
+
.mv-controls {
|
| 234 |
+
display: flex;
|
| 235 |
+
align-items: center;
|
| 236 |
+
gap: 10px;
|
| 237 |
+
padding: 10px 12px;
|
| 238 |
+
background: #0a0b10;
|
| 239 |
+
border-top: 1px solid var(--line);
|
| 240 |
+
}
|
| 241 |
+
.mv-ctrl {
|
| 242 |
+
border: 0;
|
| 243 |
+
background: rgba(255, 255, 255, 0.06);
|
| 244 |
+
color: #fff;
|
| 245 |
+
width: 38px;
|
| 246 |
+
height: 38px;
|
| 247 |
+
border-radius: 10px;
|
| 248 |
+
display: grid;
|
| 249 |
+
place-items: center;
|
| 250 |
+
flex: none;
|
| 251 |
+
}
|
| 252 |
+
.mv-time {
|
| 253 |
+
font-variant-numeric: tabular-nums;
|
| 254 |
+
font-size: 13px;
|
| 255 |
+
color: var(--muted);
|
| 256 |
+
flex: none;
|
| 257 |
+
}
|
| 258 |
+
.mv-fps {
|
| 259 |
+
font-size: 11px;
|
| 260 |
+
color: var(--muted);
|
| 261 |
+
width: 44px;
|
| 262 |
+
text-align: right;
|
| 263 |
+
flex: none;
|
| 264 |
+
}
|
| 265 |
+
.mv-track {
|
| 266 |
+
position: relative;
|
| 267 |
+
flex: 1;
|
| 268 |
+
height: 26px;
|
| 269 |
+
min-width: 60px;
|
| 270 |
+
}
|
| 271 |
+
.mv-track-segs {
|
| 272 |
+
position: absolute;
|
| 273 |
+
left: 0;
|
| 274 |
+
right: 0;
|
| 275 |
+
top: 10px;
|
| 276 |
+
height: 6px;
|
| 277 |
+
display: flex;
|
| 278 |
+
gap: 2px;
|
| 279 |
+
opacity: 0.35;
|
| 280 |
+
border-radius: 3px;
|
| 281 |
+
overflow: hidden;
|
| 282 |
+
}
|
| 283 |
+
.mv-track-seg {
|
| 284 |
+
height: 100%;
|
| 285 |
+
}
|
| 286 |
+
.mv-track-fill {
|
| 287 |
+
position: absolute;
|
| 288 |
+
left: 0;
|
| 289 |
+
top: 10px;
|
| 290 |
+
height: 6px;
|
| 291 |
+
background: linear-gradient(90deg, var(--red), #ff7a8f);
|
| 292 |
+
border-radius: 3px;
|
| 293 |
+
box-shadow: 0 0 10px rgba(255, 45, 85, 0.7);
|
| 294 |
+
pointer-events: none;
|
| 295 |
+
}
|
| 296 |
+
.mv-track input {
|
| 297 |
+
position: absolute;
|
| 298 |
+
inset: 0;
|
| 299 |
+
width: 100%;
|
| 300 |
+
margin: 0;
|
| 301 |
+
opacity: 0;
|
| 302 |
+
cursor: pointer;
|
| 303 |
+
}
|
| 304 |
+
.mv-stage-wrap.theater {
|
| 305 |
+
position: fixed;
|
| 306 |
+
inset: 0;
|
| 307 |
+
z-index: 100;
|
| 308 |
+
border-radius: 0;
|
| 309 |
+
max-width: none;
|
| 310 |
+
display: flex;
|
| 311 |
+
flex-direction: column;
|
| 312 |
+
justify-content: center;
|
| 313 |
+
}
|
| 314 |
+
.mv-stage-wrap.theater .mv-stage {
|
| 315 |
+
max-height: calc(100vh - 60px);
|
| 316 |
+
width: auto;
|
| 317 |
+
margin: 0 auto;
|
| 318 |
+
height: 100%;
|
| 319 |
+
}
|
| 320 |
+
.mv-stage-wrap:fullscreen {
|
| 321 |
+
display: flex;
|
| 322 |
+
flex-direction: column;
|
| 323 |
+
justify-content: center;
|
| 324 |
+
border-radius: 0;
|
| 325 |
+
max-width: none;
|
| 326 |
+
}
|
| 327 |
+
.mv-stage-wrap:fullscreen .mv-stage {
|
| 328 |
+
max-height: calc(100vh - 60px);
|
| 329 |
+
height: 100%;
|
| 330 |
+
width: auto;
|
| 331 |
+
margin: 0 auto;
|
| 332 |
+
}
|
| 333 |
+
.mv-chips {
|
| 334 |
+
display: flex;
|
| 335 |
+
gap: 8px;
|
| 336 |
+
overflow-x: auto;
|
| 337 |
+
padding: 14px 0 4px;
|
| 338 |
+
scrollbar-width: thin;
|
| 339 |
+
}
|
| 340 |
+
.mv-chip {
|
| 341 |
+
flex: none;
|
| 342 |
+
display: flex;
|
| 343 |
+
align-items: center;
|
| 344 |
+
gap: 6px;
|
| 345 |
+
background: var(--panel);
|
| 346 |
+
border: 1px solid var(--line);
|
| 347 |
+
color: var(--fg);
|
| 348 |
+
padding: 8px 12px;
|
| 349 |
+
border-radius: 10px;
|
| 350 |
+
font-size: 13px;
|
| 351 |
+
}
|
| 352 |
+
.mv-chip i {
|
| 353 |
+
width: 8px;
|
| 354 |
+
height: 8px;
|
| 355 |
+
border-radius: 50%;
|
| 356 |
+
}
|
| 357 |
+
.mv-chip b {
|
| 358 |
+
font-family: 'MV Latin', Impact, sans-serif;
|
| 359 |
+
font-weight: 400;
|
| 360 |
+
color: var(--muted);
|
| 361 |
+
}
|
| 362 |
+
.mv-chip em {
|
| 363 |
+
font-style: normal;
|
| 364 |
+
color: var(--muted);
|
| 365 |
+
font-size: 11px;
|
| 366 |
+
}
|
| 367 |
+
.mv-chip.on {
|
| 368 |
+
border-color: var(--red);
|
| 369 |
+
background: rgba(255, 45, 85, 0.1);
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
/* export */
|
| 373 |
+
.mv-export {
|
| 374 |
+
display: grid;
|
| 375 |
+
gap: 16px;
|
| 376 |
+
}
|
| 377 |
+
.mv-opt {
|
| 378 |
+
display: flex;
|
| 379 |
+
align-items: center;
|
| 380 |
+
gap: 14px;
|
| 381 |
+
flex-wrap: wrap;
|
| 382 |
+
}
|
| 383 |
+
.mv-opt label {
|
| 384 |
+
width: 70px;
|
| 385 |
+
color: var(--muted);
|
| 386 |
+
font-size: 14px;
|
| 387 |
+
}
|
| 388 |
+
.mv-export-meta {
|
| 389 |
+
font-size: 13px;
|
| 390 |
+
color: var(--muted);
|
| 391 |
+
}
|
| 392 |
+
.mv-primary {
|
| 393 |
+
display: inline-flex;
|
| 394 |
+
align-items: center;
|
| 395 |
+
justify-content: center;
|
| 396 |
+
gap: 8px;
|
| 397 |
+
border: 0;
|
| 398 |
+
border-radius: 12px;
|
| 399 |
+
padding: 14px 22px;
|
| 400 |
+
font-size: 16px;
|
| 401 |
+
font-weight: 700;
|
| 402 |
+
color: #fff;
|
| 403 |
+
text-decoration: none;
|
| 404 |
+
background: linear-gradient(135deg, #ff2d55, #c4142f);
|
| 405 |
+
box-shadow: 0 10px 30px rgba(255, 45, 85, 0.35);
|
| 406 |
+
}
|
| 407 |
+
.mv-primary.sm {
|
| 408 |
+
padding: 9px 14px;
|
| 409 |
+
font-size: 14px;
|
| 410 |
+
border-radius: 10px;
|
| 411 |
+
}
|
| 412 |
+
.mv-primary.alt {
|
| 413 |
+
background: linear-gradient(135deg, #1fb5a8, #127a8a);
|
| 414 |
+
box-shadow: 0 10px 30px rgba(31, 181, 168, 0.25);
|
| 415 |
+
}
|
| 416 |
+
.mv-ghost {
|
| 417 |
+
border: 1px solid var(--line);
|
| 418 |
+
background: rgba(255, 255, 255, 0.04);
|
| 419 |
+
color: var(--fg);
|
| 420 |
+
border-radius: 10px;
|
| 421 |
+
padding: 9px 14px;
|
| 422 |
+
font-size: 14px;
|
| 423 |
+
}
|
| 424 |
+
.mv-progress {
|
| 425 |
+
display: grid;
|
| 426 |
+
gap: 10px;
|
| 427 |
+
}
|
| 428 |
+
.mv-progress-bar {
|
| 429 |
+
height: 12px;
|
| 430 |
+
border-radius: 6px;
|
| 431 |
+
background: rgba(255, 255, 255, 0.06);
|
| 432 |
+
overflow: hidden;
|
| 433 |
+
}
|
| 434 |
+
.mv-progress-bar div {
|
| 435 |
+
height: 100%;
|
| 436 |
+
background: linear-gradient(90deg, var(--red), var(--amber));
|
| 437 |
+
box-shadow: 0 0 16px rgba(255, 45, 85, 0.6);
|
| 438 |
+
transition: width 0.2s;
|
| 439 |
+
}
|
| 440 |
+
.mv-progress-info {
|
| 441 |
+
display: flex;
|
| 442 |
+
justify-content: space-between;
|
| 443 |
+
gap: 10px;
|
| 444 |
+
font-size: 13px;
|
| 445 |
+
color: var(--muted);
|
| 446 |
+
font-variant-numeric: tabular-nums;
|
| 447 |
+
}
|
| 448 |
+
.mv-progress .mv-ghost {
|
| 449 |
+
justify-self: start;
|
| 450 |
+
}
|
| 451 |
+
.mv-hint {
|
| 452 |
+
color: var(--muted);
|
| 453 |
+
font-size: 12px;
|
| 454 |
+
margin: 6px 0;
|
| 455 |
+
}
|
| 456 |
+
.mv-warn {
|
| 457 |
+
color: #ffb3c0;
|
| 458 |
+
background: rgba(255, 45, 85, 0.08);
|
| 459 |
+
border: 1px solid rgba(255, 45, 85, 0.25);
|
| 460 |
+
padding: 10px 12px;
|
| 461 |
+
border-radius: 10px;
|
| 462 |
+
font-size: 13px;
|
| 463 |
+
margin-top: 8px;
|
| 464 |
+
}
|
| 465 |
+
.mv-result {
|
| 466 |
+
display: flex;
|
| 467 |
+
gap: 16px;
|
| 468 |
+
align-items: flex-start;
|
| 469 |
+
flex-wrap: wrap;
|
| 470 |
+
}
|
| 471 |
+
.mv-result video {
|
| 472 |
+
width: min(100%, 480px);
|
| 473 |
+
border-radius: 10px;
|
| 474 |
+
background: #000;
|
| 475 |
+
}
|
| 476 |
+
.mv-result video.portrait {
|
| 477 |
+
width: min(100%, 260px);
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
/* copy */
|
| 481 |
+
.mv-tabs {
|
| 482 |
+
display: flex;
|
| 483 |
+
gap: 6px;
|
| 484 |
+
flex-wrap: wrap;
|
| 485 |
+
margin-bottom: 12px;
|
| 486 |
+
}
|
| 487 |
+
.mv-tabs button {
|
| 488 |
+
border: 1px solid var(--line);
|
| 489 |
+
background: var(--panel);
|
| 490 |
+
color: var(--fg);
|
| 491 |
+
padding: 9px 16px;
|
| 492 |
+
border-radius: 10px;
|
| 493 |
+
font-size: 15px;
|
| 494 |
+
}
|
| 495 |
+
.mv-tabs button.on {
|
| 496 |
+
border-color: var(--pc);
|
| 497 |
+
box-shadow: inset 0 -3px 0 var(--pc);
|
| 498 |
+
background: var(--panel2);
|
| 499 |
+
}
|
| 500 |
+
.mv-copy {
|
| 501 |
+
display: grid;
|
| 502 |
+
gap: 18px;
|
| 503 |
+
border-top: 3px solid var(--pc);
|
| 504 |
+
}
|
| 505 |
+
.mv-copy-tip {
|
| 506 |
+
font-size: 13px;
|
| 507 |
+
color: var(--pc);
|
| 508 |
+
}
|
| 509 |
+
.mv-field {
|
| 510 |
+
display: grid;
|
| 511 |
+
gap: 8px;
|
| 512 |
+
}
|
| 513 |
+
.mv-field-head {
|
| 514 |
+
display: flex;
|
| 515 |
+
align-items: center;
|
| 516 |
+
gap: 10px;
|
| 517 |
+
}
|
| 518 |
+
.mv-field-head label {
|
| 519 |
+
font-weight: 700;
|
| 520 |
+
font-size: 15px;
|
| 521 |
+
}
|
| 522 |
+
.mv-field-head span {
|
| 523 |
+
font-size: 12px;
|
| 524 |
+
padding: 2px 8px;
|
| 525 |
+
border-radius: 999px;
|
| 526 |
+
font-variant-numeric: tabular-nums;
|
| 527 |
+
}
|
| 528 |
+
.mv-field-head span.good {
|
| 529 |
+
background: rgba(31, 181, 168, 0.15);
|
| 530 |
+
color: #6fe3d6;
|
| 531 |
+
}
|
| 532 |
+
.mv-field-head span.bad {
|
| 533 |
+
background: rgba(255, 45, 85, 0.18);
|
| 534 |
+
color: #ff8ea3;
|
| 535 |
+
}
|
| 536 |
+
.mv-copybtn {
|
| 537 |
+
margin-left: auto;
|
| 538 |
+
border: 1px solid var(--line);
|
| 539 |
+
background: rgba(255, 255, 255, 0.05);
|
| 540 |
+
color: var(--fg);
|
| 541 |
+
border-radius: 8px;
|
| 542 |
+
padding: 6px 12px;
|
| 543 |
+
font-size: 13px;
|
| 544 |
+
}
|
| 545 |
+
.mv-copybtn:hover {
|
| 546 |
+
border-color: var(--pc);
|
| 547 |
+
}
|
| 548 |
+
.mv-input {
|
| 549 |
+
width: 100%;
|
| 550 |
+
background: #07090e;
|
| 551 |
+
border: 1px solid var(--line);
|
| 552 |
+
border-radius: 10px;
|
| 553 |
+
color: var(--fg);
|
| 554 |
+
padding: 11px 12px;
|
| 555 |
+
font: inherit;
|
| 556 |
+
font-size: 15px;
|
| 557 |
+
line-height: 1.6;
|
| 558 |
+
resize: vertical;
|
| 559 |
+
}
|
| 560 |
+
.mv-input:focus {
|
| 561 |
+
outline: none;
|
| 562 |
+
border-color: var(--pc);
|
| 563 |
+
}
|
| 564 |
+
.mv-alts {
|
| 565 |
+
display: flex;
|
| 566 |
+
flex-wrap: wrap;
|
| 567 |
+
gap: 6px;
|
| 568 |
+
}
|
| 569 |
+
.mv-alts button {
|
| 570 |
+
border: 1px dashed var(--line);
|
| 571 |
+
background: transparent;
|
| 572 |
+
color: var(--muted);
|
| 573 |
+
padding: 6px 10px;
|
| 574 |
+
border-radius: 8px;
|
| 575 |
+
font-size: 13px;
|
| 576 |
+
text-align: left;
|
| 577 |
+
}
|
| 578 |
+
.mv-alts button.on {
|
| 579 |
+
border-style: solid;
|
| 580 |
+
border-color: var(--pc);
|
| 581 |
+
color: var(--fg);
|
| 582 |
+
}
|
| 583 |
+
.mv-alts em {
|
| 584 |
+
font-style: normal;
|
| 585 |
+
opacity: 0.6;
|
| 586 |
+
font-size: 11px;
|
| 587 |
+
}
|
| 588 |
+
.mv-tags {
|
| 589 |
+
display: flex;
|
| 590 |
+
flex-wrap: wrap;
|
| 591 |
+
gap: 6px;
|
| 592 |
+
align-items: center;
|
| 593 |
+
}
|
| 594 |
+
.mv-tags > button {
|
| 595 |
+
border: 1px solid var(--line);
|
| 596 |
+
background: transparent;
|
| 597 |
+
color: var(--muted);
|
| 598 |
+
padding: 5px 10px;
|
| 599 |
+
border-radius: 999px;
|
| 600 |
+
font-size: 13px;
|
| 601 |
+
}
|
| 602 |
+
.mv-tags > button.on {
|
| 603 |
+
background: color-mix(in srgb, var(--pc) 22%, transparent);
|
| 604 |
+
border-color: var(--pc);
|
| 605 |
+
color: #fff;
|
| 606 |
+
}
|
| 607 |
+
.mv-addtag {
|
| 608 |
+
display: inline-flex;
|
| 609 |
+
border: 1px solid var(--line);
|
| 610 |
+
border-radius: 999px;
|
| 611 |
+
overflow: hidden;
|
| 612 |
+
}
|
| 613 |
+
.mv-addtag input {
|
| 614 |
+
background: transparent;
|
| 615 |
+
border: 0;
|
| 616 |
+
color: var(--fg);
|
| 617 |
+
padding: 5px 10px;
|
| 618 |
+
width: 96px;
|
| 619 |
+
font: inherit;
|
| 620 |
+
font-size: 13px;
|
| 621 |
+
}
|
| 622 |
+
.mv-addtag input:focus {
|
| 623 |
+
outline: none;
|
| 624 |
+
}
|
| 625 |
+
.mv-addtag button {
|
| 626 |
+
border: 0;
|
| 627 |
+
background: rgba(255, 255, 255, 0.06);
|
| 628 |
+
color: var(--fg);
|
| 629 |
+
padding: 0 10px;
|
| 630 |
+
}
|
| 631 |
+
.mv-tagtext {
|
| 632 |
+
margin: 0;
|
| 633 |
+
white-space: pre-wrap;
|
| 634 |
+
word-break: break-all;
|
| 635 |
+
font-family: inherit;
|
| 636 |
+
font-size: 13px;
|
| 637 |
+
color: var(--muted);
|
| 638 |
+
background: #07090e;
|
| 639 |
+
border-radius: 8px;
|
| 640 |
+
padding: 8px 10px;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
/* covers */
|
| 644 |
+
.mv-cover-bar {
|
| 645 |
+
display: flex;
|
| 646 |
+
justify-content: space-between;
|
| 647 |
+
gap: 10px;
|
| 648 |
+
flex-wrap: wrap;
|
| 649 |
+
margin-bottom: 14px;
|
| 650 |
+
}
|
| 651 |
+
.mv-cover-actions {
|
| 652 |
+
display: flex;
|
| 653 |
+
gap: 6px;
|
| 654 |
+
flex-wrap: wrap;
|
| 655 |
+
}
|
| 656 |
+
.mv-cover-grid {
|
| 657 |
+
display: grid;
|
| 658 |
+
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
|
| 659 |
+
gap: 14px;
|
| 660 |
+
align-items: start;
|
| 661 |
+
}
|
| 662 |
+
.mv-cover {
|
| 663 |
+
position: relative;
|
| 664 |
+
border-radius: 12px;
|
| 665 |
+
overflow: hidden;
|
| 666 |
+
border: 2px solid transparent;
|
| 667 |
+
background: var(--panel);
|
| 668 |
+
cursor: pointer;
|
| 669 |
+
transition: transform 0.15s, border-color 0.15s;
|
| 670 |
+
}
|
| 671 |
+
.mv-cover:hover {
|
| 672 |
+
transform: translateY(-2px);
|
| 673 |
+
}
|
| 674 |
+
.mv-cover.on {
|
| 675 |
+
border-color: var(--red);
|
| 676 |
+
box-shadow: 0 0 24px rgba(255, 45, 85, 0.35);
|
| 677 |
+
}
|
| 678 |
+
.mv-cover img {
|
| 679 |
+
display: block;
|
| 680 |
+
width: 100%;
|
| 681 |
+
background: #000;
|
| 682 |
+
}
|
| 683 |
+
.mv-cover.r169 img {
|
| 684 |
+
aspect-ratio: 16 / 9;
|
| 685 |
+
}
|
| 686 |
+
.mv-cover.r43 img {
|
| 687 |
+
aspect-ratio: 4 / 3;
|
| 688 |
+
}
|
| 689 |
+
.mv-cover.r34 img {
|
| 690 |
+
aspect-ratio: 3 / 4;
|
| 691 |
+
}
|
| 692 |
+
.mv-cover-check {
|
| 693 |
+
position: absolute;
|
| 694 |
+
top: 8px;
|
| 695 |
+
right: 8px;
|
| 696 |
+
width: 26px;
|
| 697 |
+
height: 26px;
|
| 698 |
+
border-radius: 50%;
|
| 699 |
+
border: 2px solid #fff;
|
| 700 |
+
background: rgba(0, 0, 0, 0.4);
|
| 701 |
+
display: grid;
|
| 702 |
+
place-items: center;
|
| 703 |
+
font-weight: 700;
|
| 704 |
+
color: #fff;
|
| 705 |
+
}
|
| 706 |
+
.mv-cover.on .mv-cover-check {
|
| 707 |
+
background: var(--red);
|
| 708 |
+
border-color: var(--red);
|
| 709 |
+
}
|
| 710 |
+
.mv-cover-meta {
|
| 711 |
+
display: flex;
|
| 712 |
+
align-items: center;
|
| 713 |
+
gap: 8px;
|
| 714 |
+
padding: 8px 10px;
|
| 715 |
+
font-size: 13px;
|
| 716 |
+
}
|
| 717 |
+
.mv-cover-meta span {
|
| 718 |
+
color: var(--muted);
|
| 719 |
+
font-size: 12px;
|
| 720 |
+
}
|
| 721 |
+
.mv-cover-meta button {
|
| 722 |
+
margin-left: auto;
|
| 723 |
+
border: 1px solid var(--line);
|
| 724 |
+
background: transparent;
|
| 725 |
+
color: var(--fg);
|
| 726 |
+
border-radius: 6px;
|
| 727 |
+
padding: 3px 8px;
|
| 728 |
+
font-size: 12px;
|
| 729 |
+
}
|
| 730 |
+
.mv-lightbox {
|
| 731 |
+
position: fixed;
|
| 732 |
+
inset: 0;
|
| 733 |
+
z-index: 200;
|
| 734 |
+
background: rgba(0, 0, 0, 0.88);
|
| 735 |
+
display: flex;
|
| 736 |
+
flex-direction: column;
|
| 737 |
+
align-items: center;
|
| 738 |
+
justify-content: center;
|
| 739 |
+
gap: 14px;
|
| 740 |
+
padding: 20px;
|
| 741 |
+
}
|
| 742 |
+
.mv-lightbox img {
|
| 743 |
+
max-width: 100%;
|
| 744 |
+
max-height: calc(100vh - 110px);
|
| 745 |
+
border-radius: 8px;
|
| 746 |
+
}
|
| 747 |
+
.mv-lightbox-bar {
|
| 748 |
+
display: flex;
|
| 749 |
+
align-items: center;
|
| 750 |
+
gap: 10px;
|
| 751 |
+
flex-wrap: wrap;
|
| 752 |
+
justify-content: center;
|
| 753 |
+
font-size: 14px;
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
.mv-footer {
|
| 757 |
+
max-width: 1200px;
|
| 758 |
+
margin: 40px auto 0;
|
| 759 |
+
padding: 0 clamp(12px, 4vw, 40px);
|
| 760 |
+
color: var(--muted);
|
| 761 |
+
font-size: 12px;
|
| 762 |
+
line-height: 1.8;
|
| 763 |
+
text-align: center;
|
| 764 |
+
}
|
| 765 |
+
.mv-toast {
|
| 766 |
+
position: fixed;
|
| 767 |
+
left: 50%;
|
| 768 |
+
bottom: 28px;
|
| 769 |
+
transform: translateX(-50%);
|
| 770 |
+
z-index: 300;
|
| 771 |
+
background: rgba(20, 22, 30, 0.95);
|
| 772 |
+
border: 1px solid rgba(255, 45, 85, 0.4);
|
| 773 |
+
color: #fff;
|
| 774 |
+
padding: 10px 18px;
|
| 775 |
+
border-radius: 999px;
|
| 776 |
+
font-size: 14px;
|
| 777 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
@media (max-width: 720px) {
|
| 781 |
+
.mv-header {
|
| 782 |
+
padding: 10px 12px;
|
| 783 |
+
}
|
| 784 |
+
.mv-logo {
|
| 785 |
+
font-size: 28px;
|
| 786 |
+
}
|
| 787 |
+
.mv-brand-sub {
|
| 788 |
+
display: none;
|
| 789 |
+
}
|
| 790 |
+
.mv-nav a {
|
| 791 |
+
padding: 6px 8px;
|
| 792 |
+
font-size: 13px;
|
| 793 |
+
}
|
| 794 |
+
.mv-section h2 {
|
| 795 |
+
font-size: 20px;
|
| 796 |
+
}
|
| 797 |
+
.mv-stage-wrap.portrait {
|
| 798 |
+
max-width: min(100%, calc((100vh - 170px) * 9 / 16 + 2px));
|
| 799 |
+
}
|
| 800 |
+
.mv-fps {
|
| 801 |
+
display: none;
|
| 802 |
+
}
|
| 803 |
+
.mv-opt label {
|
| 804 |
+
width: 100%;
|
| 805 |
+
}
|
| 806 |
+
.mv-cover-grid {
|
| 807 |
+
grid-template-columns: repeat(2, 1fr);
|
| 808 |
+
gap: 10px;
|
| 809 |
+
}
|
| 810 |
+
.mv-primary {
|
| 811 |
+
width: 100%;
|
| 812 |
+
}
|
| 813 |
+
.mv-cover-actions .mv-primary {
|
| 814 |
+
width: auto;
|
| 815 |
+
}
|
| 816 |
+
}
|