Spaces:
Paused
Paused
Download src/mv/engine/scenesA.ts from Ethscriptions/video: direct link, hf CLI and curl.
- Browser
- Download file 43.2 kB
-
https://huggingface.co/spaces/Ethscriptions/video/resolve/main/src/mv/engine/scenesA.ts
- Command line
-
hf download hf://spaces/Ethscriptions/video/src/mv/engine/scenesA.ts
-
curl -L -o scenesA.ts https://huggingface.co/spaces/Ethscriptions/video/resolve/main/src/mv/engine/scenesA.ts
43.2 kB
import { BAR, BEAT, DROP1, bandAt, beatTime } from './audio'
import {
figureBack,
fogBand,
glowBlob,
halftone,
lightCone,
marquee,
neonSign,
neonText,
rain,
skyline,
speedLines,
splashes,
splitText,
streetLamp,
vGradient,
walker,
wetReflection,
} from './draw'
import { camera, resetCam, type SceneCtx } from './types'
import { bike, flame, heroRide, heroRideRear, heroSideSit } from './hero'
import { drawHighway, makeCam, poly3, proj } from './road3d'
import {
FONT,
PALETTE,
clamp,
easeInOutCubic,
easeOutBack,
easeOutCubic,
easeOutExpo,
fbm,
flicker,
fract,
hash,
hash2,
hash3,
lerp,
noise1,
rgba,
smoothstep,
} from './util'
const SIGN_WORDS = ['网吧', '桌球', '电玩城', '机车改装', '烧烤', '大排档', '卡拉OK', '士多', '冰室', '纹身', '发廊', '录像厅', '溜冰场', '夜宵', '修车', '通宵']
const SIGN_COLORS = [PALETTE.red, PALETTE.cyan, PALETTE.sodium, PALETTE.violet, PALETTE.teal, '#ff5fa2']
const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
// =====================================================================
// S1 — 开场·霓虹点亮 (0 – 9s)
// =====================================================================
export function sIgnite(s: SceneCtx) {
const { ctx, W, H, P, lt, u, t } = s
// a street corner under the moon: two buildings, utility poles, sagging wires
const groundY = P ? H * 0.74 : H * 0.76
const zoom = 1 + lt * 0.014
camera(s, zoom, W / 2, H * 0.47)
streetCorner(s, groundY)
const size = P ? Math.min(W * 0.4, H * 0.17) : Math.min(W * 0.25, H * 0.36)
const cy = P ? H * 0.31 : H * 0.36
const pos: [number, number][] = P
? [
[W / 2, cy - size * 0.55],
[W / 2, cy + size * 0.55],
]
: [
[W / 2 - size * 0.56, cy],
[W / 2 + size * 0.56, cy],
]
const buzz = 0.9 + 0.1 * hash(Math.floor(t * 40))
const lit = (start: number, end: number, seed: number) => {
if (lt < start) return 0
if (lt < end) return flicker(lt, seed, 16) * smoothstep(start, end, lt + 0.3)
return buzz
}
let on1 = lit(1.0, 2.1, 1)
let on2 = lit(2.6, 3.5, 2)
if (lt > 8.2) {
const f = flicker(lt, 9, 20)
on1 *= f
on2 *= f
}
// mounting plate
ctx.fillStyle = 'rgba(12,10,14,0.9)'
const plateW = P ? size * 1.45 : size * 2.5
const plateH = P ? size * 2.5 : size * 1.4
ctx.fillRect(W / 2 - plateW / 2, cy - plateH / 2, plateW, plateH)
ctx.strokeStyle = 'rgba(80,70,80,0.35)'
ctx.lineWidth = u * 2
ctx.strokeRect(W / 2 - plateW / 2, cy - plateH / 2, plateW, plateH)
glowBlob(ctx, W / 2, cy, size * 2.6, PALETTE.red, 0.22 * Math.max(on1, on2))
neonText(ctx, '黑', pos[0][0], pos[0][1], size, PALETTE.red, on1, { tube: true, blur: 0.4 })
neonText(ctx, '街', pos[1][0], pos[1][1], size, PALETTE.red, on2, { tube: true, blur: 0.4 })
// BLACK STREET typed on
const sub = 'BLACK STREET'
const typed = Math.floor(clamp((lt - 4.2) / 1.4) * sub.length)
if (typed > 0) {
const sy = P ? H * 0.075 : cy + size * 0.95
const fs = P ? size * 0.26 : size * 0.22
ctx.save()
ctx.font = `${fs}px ${FONT.latin}`
const full = ctx.measureText(sub.split('').join(' ')).width
ctx.restore()
const str = sub.slice(0, typed).split('').join(' ')
neonText(ctx, str, W / 2 - full / 2, sy, fs, PALETTE.cyan, lt > 8.2 ? on1 : buzz, { font: FONT.latin, align: 'left', blur: 0.5 })
}
// credit line
if (lt > 5.8) {
const a = smoothstep(5.8, 6.8, lt) * (1 - smoothstep(8.4, 9, lt))
ctx.save()
ctx.globalAlpha = a
ctx.font = `${(P ? W : H) * 0.022}px ${FONT.black}`
ctx.textAlign = 'center'
ctx.fillStyle = PALETTE.bone
ctx.fillText('陈雅雯 · 黑街', W / 2, P ? H * 0.115 : cy + size * 1.25)
ctx.restore()
}
// the singer's name in neon on the right wall
neonSign(ctx, W * (P ? 0.8 : 0.9), H * (P ? 0.5 : 0.07), u * (P ? 64 : 70), u * (P ? 200 : 220), '陈雅雯', PALETTE.cyan, lt > 3.8 ? (lt < 4.6 ? flicker(t, 4, 14) : 0.92 + 0.08 * flicker(t, 4, 3)) : 0, true)
// 阿飞 sitting side-saddle on his parked bike, watching the fire
const bs = P ? W * 0.34 : H * 0.28
const headOn = lt > 6.4 ? (lt < 7 ? flicker(lt, 12, 18) : 1) : 0
const fireX = P ? W * 0.2 : W * 0.13
const fireS = P ? W * 0.1 : H * 0.1
heroSideSit(ctx, P ? W * 0.62 : W * 0.78, groundY, bs, { facing: -1, t, light: headOn, beam: headOn > 0.5, look: -0.6, rim: rgba('#ff9a4a', 0.75) })
bonfire(ctx, fireX, groundY + u * 6, fireS, t)
// ground
resetCam(s)
ctx.fillStyle = '#050608'
ctx.fillRect(0, groundY, W, H - groundY)
wetReflection(ctx, s.scratch, W, H, groundY, t, 0.5, u * 4)
splashes(ctx, W, groundY + u * 10, H, t, Math.floor(40 * area(s)) + 10, '#9fb6c8', 0.25, u)
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) })
}
// =====================================================================
// S2 — 雨夜长街 (9 – 24s)
// =====================================================================
export function sStreet(s: SceneCtx) {
const { ctx, W, H, P, lt, u, t, a } = s
const groundY = P ? H * 0.8 : H * 0.78
const v = u * (P ? 70 : 95)
const scroll = lt * v
// camera shots
let zoom = 1
let cx = W / 2
let cy = H / 2
const wx = P ? W * 0.5 : W * 0.42
const wh = P ? H * 0.2 : H * 0.3
if (lt >= 7.5 && lt < 11.4) {
const k = easeOutCubic((lt - 7.5) / 0.6)
zoom = lerp(1, P ? 1.6 : 1.75, k) + (lt - 7.5) * 0.02
cx = lerp(W / 2, wx + wh * 0.1, k)
cy = lerp(H / 2, groundY - wh * 0.62, k)
} else if (lt >= 11.4) {
const k = easeInOutCubic((lt - 11.4) / 3.6)
zoom = 1.05
cx = W / 2
cy = H / 2 - k * H * 0.22
}
cx += fbm(t * 0.4, 1) * u * 6
cy += fbm(t * 0.5, 2) * u * 5
resetCam(s)
vGradient(ctx, 0, 0, W, H, [
[0, '#060a12'],
[0.5, '#14243a'],
[0.8, '#2c3e52'],
[1, '#1a2430'],
])
camera(s, zoom, cx, cy)
const ext = W * 0.5
// sky glow & far skyline
glowBlob(ctx, W * 0.7, groundY - H * 0.25, W * 0.8, PALETTE.amber, 0.16)
glowBlob(ctx, W * 0.2, groundY - H * 0.35, W * 0.6, PALETTE.cyan, 0.08)
skyline(ctx, { still: true, 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 })
fogBand(ctx, W + ext, groundY - H * 0.14, H * 0.1, PALETTE.steel, 0.5)
// mid layer with vertical neon signs
const midCell = u * 150
const midScroll = scroll * 0.42
skyline(ctx, { still: true, 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 })
const k0 = Math.floor(midScroll / midCell) - 1
for (let k = k0; k < k0 + Math.ceil((W + ext) / midCell) + 2; k++) {
if (hash(k * 5.7) < 0.4) continue
const word = SIGN_WORDS[(((k * 5) % SIGN_WORDS.length) + SIGN_WORDS.length) % SIGN_WORDS.length]
const col = SIGN_COLORS[((k % SIGN_COLORS.length) + SIGN_COLORS.length) % SIGN_COLORS.length]
const n = Array.from(word).length
const sw = u * 50
const sh = sw * n * 1.05 + sw * 0.4
const x = k * midCell - midScroll + midCell * (0.55 + 0.3 * hash(k))
const y = groundY - H * (0.3 + 0.22 * hash(k * 3.9)) - sh * 0.5
const on = hash(k * 4.4) > 0.8 ? flicker(t, k, 10) : 0.85 + 0.15 * a.mid
neonSign(ctx, x, y, sw, sh, word, col, on, true)
}
// near shopfronts — the places the street kids hang out
const nearCell = u * 300
const kk0 = Math.floor(scroll / nearCell) - 1
for (let k = kk0; k < kk0 + Math.ceil((W + ext) / nearCell) + 2; k++) {
const x = k * nearCell - scroll
shopfront(ctx, x, groundY, nearCell, u, t, k)
if (((k % 3) + 3) % 3 === 0) streetLamp(ctx, x + nearCell * 0.02, groundY, u * 340, 0.85 + 0.15 * flicker(t, k + 99, 5))
}
// 阿飞 pushing his motorcycle through the rain
const phase = (s.a.beatPos / 2) % 1
const bs = wh / 1.45
heroRide(ctx, wx, groundY + u * 2, bs, { facing: 1, t, spin: scroll / (bs * 0.23), light: 1, beam: true, wind: 0.45, eyes: 'open', tuck: 0.3, rim: rgba(PALETTE.cyan, 0.8) })
void phase
// ground
ctx.fillStyle = '#05070a'
ctx.fillRect(-ext, groundY, W + ext * 3, H)
resetCam(s)
const gy = (groundY - cy) * zoom + H / 2
if (gy < H - 2) wetReflection(ctx, s.scratch, W, H, gy, t, 0.55, u * 3)
if (gy < H) splashes(ctx, W, gy + u * 6, H, t, Math.floor(50 * area(s)) + 10, '#9fb6c8', 0.25, u)
// foreground poles
const poleCell = u * 1100
const ps = scroll * 2.2
for (let k = Math.floor(ps / poleCell) - 1; k < Math.floor(ps / poleCell) + 3; k++) {
const x = k * poleCell - ps + poleCell * 0.3
ctx.fillStyle = '#020203'
ctx.fillRect(x, 0, u * 46, H)
}
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) })
}
// =====================================================================
// S3 — 蓄力·隧道 (24 – 38.15s)
// =====================================================================
/** highway → tunnel mouth → into the acceleration tunnel */
const TUNNEL_IN = 2.5 * BAR
export function sTunnel(s: SceneCtx) {
if (s.lt < TUNNEL_IN) tunnelApproach(s)
else tunnelInside({ ...s, lt: s.lt - TUNNEL_IN, dur: s.dur - TUNNEL_IN })
}
function tunnelApproach(s: SceneCtx) {
const { ctx, W, H, lt, t } = s
const v = 30
const camZ = v * lt
const Zp = v * TUNNEL_IN + 3
const sway = Math.sin(lt * 0.9) * 0.4
const c = makeCam(s, 0.6 + sway, 1.7, camZ, 0, 0.03, 1)
drawHighway(s, c, { glow: '#2a1830' })
// inside the tunnel, seen through the mouth
poly3(ctx, c, s, [
[-7.6, 0, Zp + 0.2],
[7.6, 0, Zp + 0.2],
[7.6, 7.5, Zp + 0.2],
[-7.6, 7.5, Zp + 0.2],
], '#3a2414')
for (let z = Zp + 4; z < Zp + 140; z += 8) {
for (const lx of [-4.5, 4.5]) {
poly3(ctx, c, s, [
[lx - 0.5, 7.2, z],
[lx + 0.5, 7.2, z],
[lx + 0.5, 7.2, z + 2.5],
[lx - 0.5, 7.2, z + 2.5],
], '#ffcf8a')
}
}
const glow = proj(c, s, 0, 3.5, Zp + 30)
if (glow) glowBlob(ctx, glow.x, glow.y, glow.k * 14, PALETTE.sodium, 0.55)
// the mountain and the portal
const ridge: [number, number, number][] = [[-220, 0, Zp]]
for (let i = 0; i <= 24; i++) {
const x = -220 + (i / 24) * 440
ridge.push([x, 22 + 18 * fbm(i * 0.45, 4) + (Math.abs(x) < 30 ? 6 : 0), Zp])
}
ridge.push([220, 0, Zp])
poly3(ctx, c, s, ridge.map(([x, y, z]) => [x, y, z + 6] as [number, number, number]), '#070912')
poly3(ctx, c, s, [
[-220, 0, Zp],
[-7.6, 0, Zp],
[-7.6, 12, Zp],
[-220, 12, Zp],
], '#0b0e16')
poly3(ctx, c, s, [
[7.6, 0, Zp],
[220, 0, Zp],
[220, 12, Zp],
[7.6, 12, Zp],
], '#0b0e16')
poly3(ctx, c, s, [
[-7.6, 7.5, Zp],
[7.6, 7.5, Zp],
[7.6, 12, Zp],
[-7.6, 12, Zp],
], '#0b0e16')
// concrete portal frame + hazard stripes
poly3(ctx, c, s, [
[-9.5, 0, Zp - 0.1],
[-7.6, 0, Zp - 0.1],
[-7.6, 9.3, Zp - 0.1],
[-9.5, 9.3, Zp - 0.1],
], '#2c3038')
poly3(ctx, c, s, [
[7.6, 0, Zp - 0.1],
[9.5, 0, Zp - 0.1],
[9.5, 9.3, Zp - 0.1],
[7.6, 9.3, Zp - 0.1],
], '#2c3038')
poly3(ctx, c, s, [
[-9.5, 7.5, Zp - 0.1],
[9.5, 7.5, Zp - 0.1],
[9.5, 9.3, Zp - 0.1],
[-9.5, 9.3, Zp - 0.1],
], '#2c3038')
for (let i = 0; i < 10; i++) {
const x0 = -7.6 + i * 1.52
if (i % 2) continue
poly3(ctx, c, s, [
[x0, 7.5, Zp - 0.15],
[x0 + 1.52, 7.5, Zp - 0.15],
[x0 + 1.52, 8.1, Zp - 0.15],
[x0, 8.1, Zp - 0.15],
], '#d8a81c')
}
// portal lights
for (const lx of [-8.5, 8.5]) {
const p = proj(c, s, lx, 8.4, Zp - 0.3)
if (p) glowBlob(ctx, p.x, p.y, p.k * 1.8, PALETTE.sodium, 0.9)
}
// 阿飞 riding ahead of us
const rs = H * 0.52
heroRideRear(ctx, W / 2, H * 1.03, rs, Math.sin(lt * 0.9) * -0.06, t, 0.6)
// last moments: the dark swallows the frame, then the whoosh (flash cut in post)
const k = smoothstep(TUNNEL_IN - 0.5, TUNNEL_IN, lt)
if (k > 0) {
ctx.fillStyle = `rgba(20,12,6,${0.6 * k})`
ctx.fillRect(0, 0, W, H)
}
}
function tunnelInside(s: SceneCtx) {
const { ctx, W, H, P, lt, u, t, a, dur } = s
const p = lt / dur
const travel = 1.4 * lt + 0.07 * lt * lt * lt
const vx = W / 2 + Math.sin(lt * 0.55) * W * 0.04
const vy = H * 0.47 + Math.cos(lt * 0.4) * H * 0.02
{
const R = Math.max(W, H) * 0.85
const g = ctx.createRadialGradient(vx, vy, 0, vx, vy, R)
g.addColorStop(0, p > 0.75 ? '#c9a27a' : '#6a4626')
g.addColorStop(0.18, '#2a2230')
g.addColorStop(0.55, '#121826')
g.addColorStop(1, '#05070c')
ctx.fillStyle = g
ctx.fillRect(0, 0, W, H)
}
const N = 26
const baseW = P ? W * 0.62 : W * 0.5
const baseH = P ? H * 0.42 : H * 0.6
const fr = fract(travel)
const ringBase = Math.floor(travel)
glowBlob(ctx, vx, vy, Math.min(W, H) * (0.25 + p * 0.5), p > 0.7 ? '#ffffff' : PALETTE.sodium, 0.18 + p * 0.5)
for (let i = N; i >= 1; i--) {
const z = i - fr
if (z <= 0.15) continue
const sc = 1.6 / z
const hw = baseW * sc
const hh = baseH * sc
const ri = ringBase + i
const fade = clamp(1 - z / N) * clamp(z / 0.6)
const isRed = ri % 6 === 0
const isLamp = ri % 2 === 0
// tunnel segment walls
ctx.globalAlpha = fade
ctx.strokeStyle = isRed ? PALETTE.red : rgba('#8fa3c0', 0.75)
ctx.lineWidth = Math.max(1, (isRed ? 7 : 3) * u * sc)
if (isRed) {
ctx.shadowColor = PALETTE.red
ctx.shadowBlur = u * 30 * sc
}
ctx.strokeRect(vx - hw, vy - hh, hw * 2, hh * 2)
ctx.shadowBlur = 0
if (isLamp) {
ctx.fillStyle = PALETTE.sodium
const lw = hw * 0.18
ctx.fillRect(vx - lw, vy - hh - u * 2 * sc, lw * 2, Math.max(1, u * 6 * sc))
ctx.fillRect(vx - hw - u * 2 * sc, vy - hh * 0.2, Math.max(1, u * 5 * sc), hh * 0.4)
ctx.fillRect(vx + hw - u * 3 * sc, vy - hh * 0.2, Math.max(1, u * 5 * sc), hh * 0.4)
if (z < 9) {
glowBlob(ctx, vx, vy - hh, hw * 0.35, PALETTE.sodium, 0.35 * fade)
glowBlob(ctx, vx - hw, vy, hh * 0.3, PALETTE.sodium, 0.25 * fade)
glowBlob(ctx, vx + hw, vy, hh * 0.3, PALETTE.sodium, 0.25 * fade)
}
}
// floor dashes
ctx.fillStyle = rgba(PALETTE.bone, 0.6)
ctx.fillRect(vx - u * 4 * sc, vy + hh - u * 2 * sc, u * 8 * sc, Math.max(1, u * 3 * sc))
}
ctx.globalAlpha = 1
// perspective rails
ctx.strokeStyle = 'rgba(120,140,170,0.18)'
ctx.lineWidth = Math.max(1, u * 2)
ctx.beginPath()
for (const [dx, dy] of [
[-1, -1],
[1, -1],
[-1, 1],
[1, 1],
]) {
ctx.moveTo(vx, vy)
ctx.lineTo(vx + dx * baseW * 8, vy + dy * baseH * 8)
}
ctx.stroke()
speedLines(ctx, vx, vy, Math.max(W, H) * 0.8, t, 90, '#ffffff', 0.04 + p * p * 0.25, 0.25)
// figure
const rs = P ? H * 0.3 : H * 0.52
heroRideRear(ctx, W / 2 + Math.sin(lt * 0.55) * W * 0.02, H * 1.03, rs, Math.sin(lt * 0.55) * -0.06, t, 0.5 + p)
// countdown on the last beats before the drop
const bp = (t - DROP1) / BEAT
if (bp >= -3 && bp < 0) {
const n = Math.ceil(-bp)
const ph = fract(bp)
const size = Math.min(W, H) * (0.5 + 0.25 * (1 - ph))
ctx.save()
ctx.globalAlpha = 1 - ph * 0.6
splitText(ctx, String(n), W / 2, H * 0.46, size, FONT.latin, '#ffffff', u * 10 * (1 - ph))
ctx.restore()
}
void a
}
// =====================================================================
// S4 — Drop1·霓虹爆裂 (38.15 – 56.35s), 8 shots × 1 bar
// =====================================================================
const POSTER_WORDS: string[][] = [
['黑', '街', '黑街', 'BLACK STREET'],
['黑', '街', '男孩', 'BLACK STREET BOY'],
]
const GRID_CHARS = ['黑', '街', '夜', '行', '王', '灯', '雨', '火', '醒', '狂', '燃', '跳', '闪', '冲', '霓', '虹']
export function sDrop1(s: SceneCtx) {
const bi = Math.floor(s.lt / BEAT)
if (bi < 4) posterShot(s, 0)
else if (bi < 8) runnerShot(s, 0)
else gridShot(s, 0)
}
function posterShot(s: SceneCtx, variant: number) {
const { ctx, W, H, P, u, t, a } = s
const bi = ((a.beat % 4) + 4) % 4
const red = bi % 2 === 0
const bg = red ? '#d0102e' : '#050608'
const fg = red ? '#050608' : '#f4ece0'
ctx.fillStyle = bg
ctx.fillRect(0, 0, W, H)
// halftone shading
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))
const words = POSTER_WORDS[variant]
const word = words[bi]
const pop = easeOutBack(clamp(a.beatPhase / 0.25))
const jx = (hash(a.beat * 3.3) - 0.5) * u * 24 * a.kick
const jy = (hash(a.beat * 7.7) - 0.5) * u * 24 * a.kick
const isLatin = /[A-Z]/.test(word)
ctx.save()
ctx.translate(W / 2 + jx, H / 2 + jy)
ctx.scale(lerp(1.25, 1, pop), lerp(1.25, 1, pop))
if (isLatin) {
const parts = word.split(' ')
const size = P ? W * 0.3 : H * 0.36
parts.forEach((p, i) => splitText(ctx, p, 0, (i - (parts.length - 1) / 2) * size * 0.95, size, FONT.latin, fg, u * 10 * a.kick))
} else {
const chars = Array.from(word)
if (P && chars.length > 1) {
const size = Math.min(W * 0.62, (H * 0.8) / chars.length)
chars.forEach((c, i) => splitText(ctx, c, 0, (i - (chars.length - 1) / 2) * size * 1.02, size, FONT.black, fg, u * 12 * a.kick))
} else {
const size = chars.length === 1 ? Math.min(W, H) * 0.85 : Math.min((W * 0.86) / chars.length, H * 0.7)
splitText(ctx, word, 0, 0, size, FONT.black, fg, u * 12 * a.kick)
}
}
ctx.restore()
// marquees
const ms = (P ? W : H) * 0.05
marquee(ctx, 'BLACK STREET · 黑街 · 105.5 BPM · ', ms * 0.9, W, ms, t * u * 400, fg)
marquee(ctx, 'BLACK STREET BOY · 黑街男孩 · 陈雅雯 · ', H - ms * 0.9, W, ms, -t * u * 400, fg)
// corner badges
ctx.save()
ctx.font = `${ms * 0.55}px ${FONT.latin}`
ctx.fillStyle = fg
ctx.textAlign = 'left'
ctx.fillText(`DROP 01 / ${String(s.t.toFixed(2)).padStart(6, '0')}`, ms * 0.6, ms * 2.4)
ctx.textAlign = 'right'
ctx.fillText('黑街 ● REC', W - ms * 0.6, ms * 2.4)
ctx.restore()
}
function eqShot(s: SceneCtx, variant: number) {
const { ctx, W, H, P, u, t, a, lt } = s
const horizon = P ? H * 0.66 : H * 0.7
vGradient(ctx, 0, 0, W, horizon, [
[0, '#05030a'],
[0.6, variant ? '#1a0b30' : '#2a0814'],
[1, variant ? '#5a1f6a' : '#8a1426'],
])
// striped sun
const sx = W / 2
const sy = horizon - Math.min(W, H) * 0.05
const R = Math.min(W, H) * (P ? 0.36 : 0.3) * (1 + a.kick * 0.04)
ctx.save()
ctx.beginPath()
ctx.arc(sx, sy, R, 0, Math.PI * 2)
ctx.clip()
vGradient(ctx, sx - R, sy - R, R * 2, R * 2, [
[0, '#ffd27a'],
[0.5, '#ff5a3c'],
[1, '#c4142f'],
])
ctx.fillStyle = '#05030a'
for (let i = 0; i < 9; i++) {
const yy = sy + R * (0.05 + i * 0.12) + ((lt * u * 40) % (R * 0.12))
ctx.fillRect(sx - R, yy, R * 2, R * 0.012 * (i + 1))
}
ctx.restore()
glowBlob(ctx, sx, sy, R * 2, PALETTE.red, 0.35)
// equalizer skyline
const bands: ('low' | 'mid' | 'high')[] = ['low', 'mid', 'high']
skyline(ctx, {
W,
seed: 41 + variant * 13,
baseY: horizon,
scroll: lt * u * 30,
cell: u * (P ? 70 : 85),
minH: H * 0.12,
maxH: H * 0.4,
color: '#040408',
t,
density: 0.18,
winAlpha: 0.7,
hMod: (k) => {
const b = bands[((k % 3) + 3) % 3]
return 0.45 + 1.1 * bandAt(t - (((k % 5) + 5) % 5) * 0.025, b)
},
litMod: (k, row, rows) => {
const lvl = a.kick
return 1 - row / rows < lvl * (0.6 + 0.4 * hash(k)) ? 0.9 : 0
},
})
// water
ctx.fillStyle = '#030306'
ctx.fillRect(0, horizon, W, H - horizon)
wetReflection(ctx, s.scratch, W, H, horizon, t, 0.6, u * 6)
// lightning on some beats
if (hash(a.beat * 1.7 + variant) > 0.72 && a.beatPhase < 0.12) {
ctx.fillStyle = 'rgba(220,230,255,0.35)'
ctx.fillRect(0, 0, W, horizon)
}
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) })
}
function runnerShot(s: SceneCtx, variant: number) {
const { ctx, W, H, P, u, t, a } = s
const alt = ((a.beat % 2) + 2) % 2 === 0
const bgc = variant ? (alt ? '#f2a01c' : '#d0102e') : alt ? '#d0102e' : '#12a6bf'
const cx = W / 2
const cy = H * 0.5
{
const g = ctx.createRadialGradient(cx, cy, 0, cx, cy, Math.max(W, H) * 0.7)
g.addColorStop(0, '#fff2e0')
g.addColorStop(0.25, bgc)
g.addColorStop(1, '#0a0508')
ctx.fillStyle = g
ctx.fillRect(0, 0, W, H)
}
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))
speedLines(ctx, cx, cy, Math.max(W, H) * 0.8, t, 120, '#0a0508', 0.35, 0.4)
// ground streak
const gy = P ? H * 0.68 : H * 0.8
ctx.fillStyle = 'rgba(255,255,255,0.12)'
for (let i = 0; i < 14; i++) {
const x = fract(hash(i * 3.1) - t * (1.5 + hash(i))) * W * 1.4 - W * 0.2
ctx.fillRect(x, gy + hash(i) * u * 40, u * (80 + hash(i * 2) * 200), Math.max(1, u * 3))
}
const facing = variant ? -1 : 1
const bsz = P ? W * 0.5 : H * 0.45
heroRide(ctx, cx, gy + a.kick * u * 6, bsz, { facing, wind: 1, t, spin: t * 30, beam: true, eyes: 'open', tuck: 1, rim: variant ? PALETTE.red : PALETTE.cyan })
// vertical type
const vs = P ? W * 0.11 : H * 0.12
const word = variant ? '不回头' : '黑街男孩'
Array.from(word).forEach((c, i) => {
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)
})
ctx.save()
ctx.translate(P ? W * 0.9 : W * 0.12, H / 2)
ctx.rotate(-Math.PI / 2)
ctx.font = `${vs * 0.55}px ${FONT.latin}`
ctx.textAlign = 'center'
ctx.fillStyle = rgba(PALETTE.bone, 0.75)
ctx.fillText(variant ? 'NO LOOKING BACK' : 'BLACK STREET BOY', 0, 0)
ctx.restore()
}
function gridShot(s: SceneCtx, variant: number) {
const { ctx, W, H, P, u, a } = s
ctx.fillStyle = '#040408'
ctx.fillRect(0, 0, W, H)
const cols = P ? 3 : 5
const rows = P ? 5 : 3
const cw = W / cols
const ch = H / rows
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
const i = r * cols + c
const ch0 = GRID_CHARS[(i + variant * 5) % GRID_CHARS.length]
const col = SIGN_COLORS[(i * 7 + variant) % SIGN_COLORS.length]
let on: number
if (variant === 0) on = hash2(i, a.beat) > 0.45 ? 1 : 0.12
else {
const d = (c + r - a.beatPos * 2) % (cols + rows)
on = ((d + cols + rows) % (cols + rows)) < 2 ? 1 : 0.12
}
on = clamp(on * (0.8 + 0.4 * a.pulse))
const pad = Math.min(cw, ch) * 0.1
neonSign(ctx, c * cw + pad, r * ch + pad, cw - pad * 2, ch - pad * 2, ch0, col, on, false)
}
}
// centre stamp
const size = Math.min(W, H) * 0.2
ctx.save()
ctx.fillStyle = 'rgba(4,4,8,0.85)'
ctx.fillRect(W / 2 - size * 1.3, H / 2 - size * 0.62, size * 2.6, size * 1.24)
ctx.restore()
neonText(ctx, '黑街', W / 2, H / 2, size, PALETTE.red, 0.85 + 0.15 * a.pulse, { tube: true, blur: 0.4 })
void u
}
/** campfire with logs, stones and two beer bottles (from the reference footage) */
function bonfire(ctx: CanvasRenderingContext2D, x: number, y: number, sz: number, t: number) {
ctx.save()
ctx.globalCompositeOperation = 'lighter'
glowBlob(ctx, x, y - sz * 0.6, sz * 9, '#ff7a2e', 0.32 + 0.06 * Math.sin(t * 9))
ctx.restore()
// stones
for (let i = 0; i < 9; i++) {
const a = Math.PI + (i / 8) * Math.PI
ctx.fillStyle = i % 2 ? '#2a2420' : '#3a312a'
ctx.beginPath()
ctx.ellipse(x + Math.cos(a) * sz * 0.9, y + Math.sin(a) * sz * 0.18 + sz * 0.1, sz * 0.2, sz * 0.13, 0, 0, Math.PI * 2)
ctx.fill()
}
// crossed logs
ctx.lineCap = 'round'
for (const [a, c] of [
[0.35, '#4a2e1a'],
[-0.35, '#5a3820'],
[0.05, '#3a2414'],
] as [number, string][]) {
ctx.strokeStyle = c
ctx.lineWidth = sz * 0.2
ctx.beginPath()
ctx.moveTo(x - Math.cos(a) * sz * 0.8, y + Math.sin(a) * sz * 0.2)
ctx.lineTo(x + Math.cos(a) * sz * 0.8, y - Math.sin(a) * sz * 0.2 - sz * 0.05)
ctx.stroke()
}
// embers bed
glowBlob(ctx, x, y, sz * 0.9, '#ff4a1c', 0.9)
// flames
for (let i = 0; i < 5; i++) {
const fx = x + (i - 2) * sz * 0.22
flame(ctx, fx, y - sz * 0.05, sz * (0.55 + 0.35 * Math.abs(Math.sin(t * 3 + i * 1.7))) * (i === 2 ? 1.5 : 1), t + i * 0.37)
}
// sparks rising
ctx.fillStyle = '#ffcf7a'
for (let i = 0; i < 24; i++) {
const life = fract(t * (0.35 + hash(i) * 0.4) + hash(i * 3.7))
ctx.globalAlpha = 1 - life
ctx.fillRect(x + Math.sin(i * 2.3 + t * 2) * sz * (0.3 + life), y - sz * (0.6 + life * 5), Math.max(1, sz * 0.04), Math.max(1, sz * 0.04))
}
ctx.globalAlpha = 1
// two beer bottles next to the fire
for (const [dx, tilt] of [
[1.35, 0.05],
[1.6, -0.12],
] as [number, number][]) {
ctx.save()
ctx.translate(x + sz * dx, y + sz * 0.15)
ctx.rotate(tilt)
ctx.fillStyle = '#1f5a2a'
ctx.beginPath()
ctx.roundRect(-sz * 0.09, -sz * 0.5, sz * 0.18, sz * 0.5, sz * 0.04)
ctx.fill()
ctx.fillRect(-sz * 0.035, -sz * 0.72, sz * 0.07, sz * 0.24)
ctx.fillStyle = '#e8d8a8'
ctx.fillRect(-sz * 0.09, -sz * 0.36, sz * 0.18, sz * 0.12)
ctx.fillStyle = 'rgba(255,190,120,0.5)'
ctx.fillRect(sz * 0.03, -sz * 0.48, sz * 0.03, sz * 0.4)
ctx.restore()
}
}
const SHOPS = ['网吧', '桌球', '电玩城', '机车改装', '烧烤', '卡拉OK', '士多', '冰室', '纹身', '发廊']
const SHOP_COL = [PALETTE.cyan, '#5aff8a', '#ff5fa2', PALETTE.sodium, PALETTE.red, PALETTE.violet, '#9fe8ff', PALETTE.amber, PALETTE.red, '#ff8ad8']
/** one street-level shop with its interior visible: the kids' hangouts */
function shopfront(ctx: CanvasRenderingContext2D, x: number, groundY: number, cell: number, u: number, t: number, k: number) {
const type = ((k % SHOPS.length) + SHOPS.length) % SHOPS.length
const top = groundY - u * 330
ctx.fillStyle = '#07090d'
ctx.fillRect(x, top, cell + 1, groundY - top)
// pilasters
ctx.fillStyle = '#0d1016'
ctx.fillRect(x, top, cell * 0.05, groundY - top)
ctx.fillRect(x + cell * 0.95, top, cell * 0.05, groundY - top)
const wx = x + cell * 0.08
const ww = cell * 0.84
const wt = groundY - u * 215
const wh = groundY - wt
ctx.save()
ctx.beginPath()
ctx.rect(wx, wt, ww, wh)
ctx.clip()
const X = (f: number) => wx + ww * f
const Y = (f: number) => wt + wh * f
const fl = (seed: number, rate = 6) => 0.7 + 0.3 * flicker(t, k * 13 + seed, rate)
switch (type) {
case 0: {
// 网吧: rows of glowing monitors
vGradient(ctx, wx, wt, ww, wh, [
[0, '#06121e'],
[1, '#0c2236'],
])
for (let r = 0; r < 2; r++)
for (let c = 0; c < 5; c++) {
const mx = X(0.06 + c * 0.19)
const my = Y(0.32 + r * 0.3)
glowBlob(ctx, mx + ww * 0.07, my + wh * 0.06, ww * 0.12, '#3da8ff', 0.35)
ctx.fillStyle = c % 2 ? '#7fd0ff' : '#b8e6ff'
ctx.globalAlpha = fl(c + r * 5, 3)
ctx.fillRect(mx, my, ww * 0.14, wh * 0.11)
ctx.globalAlpha = 1
ctx.fillStyle = '#05080c'
ctx.fillRect(mx + ww * 0.02, my + wh * 0.13, ww * 0.1, wh * 0.14)
}
break
}
case 1: {
// 桌球: green table under a hanging lamp
vGradient(ctx, wx, wt, ww, wh, [
[0, '#06100a'],
[1, '#0c1e12'],
])
lightCone(ctx, X(0.5), Y(0.2), wh * 0.7, 0.55, 0, '#d8ffb0', 0.25)
ctx.fillStyle = '#1a3a1a'
ctx.beginPath()
ctx.moveTo(X(0.42), Y(0.12))
ctx.lineTo(X(0.58), Y(0.12))
ctx.lineTo(X(0.62), Y(0.2))
ctx.lineTo(X(0.38), Y(0.2))
ctx.fill()
ctx.fillStyle = '#4a2a14'
ctx.fillRect(X(0.15), Y(0.62), ww * 0.7, wh * 0.12)
ctx.fillStyle = '#1f8a3a'
ctx.fillRect(X(0.17), Y(0.6), ww * 0.66, wh * 0.06)
ctx.fillStyle = '#e8e2d6'
ctx.beginPath()
ctx.arc(X(0.4), Y(0.6), wh * 0.02, 0, Math.PI * 2)
ctx.arc(X(0.55), Y(0.6), wh * 0.02, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = '#c4142f'
ctx.beginPath()
ctx.arc(X(0.48), Y(0.6), wh * 0.02, 0, Math.PI * 2)
ctx.fill()
ctx.strokeStyle = '#c9a26a'
ctx.lineWidth = Math.max(1, u * 2)
ctx.beginPath()
for (let i = 0; i < 4; i++) {
ctx.moveTo(X(0.88 + i * 0.02), Y(0.25))
ctx.lineTo(X(0.88 + i * 0.02), Y(0.85))
}
ctx.stroke()
break
}
case 2: {
// 电玩城: arcade cabinets with flickering screens
vGradient(ctx, wx, wt, ww, wh, [
[0, '#14061e'],
[1, '#2a0a30'],
])
const cols = ['#ff5fa2', '#3de0ff', '#ffe04a', '#8a5cff']
for (let c = 0; c < 4; c++) {
const cx0 = X(0.06 + c * 0.235)
ctx.fillStyle = '#0a0410'
ctx.fillRect(cx0, Y(0.2), ww * 0.18, wh * 0.8)
ctx.fillStyle = cols[c]
ctx.globalAlpha = fl(c, 9)
ctx.fillRect(cx0 + ww * 0.02, Y(0.24), ww * 0.14, wh * 0.06)
ctx.fillRect(cx0 + ww * 0.025, Y(0.36), ww * 0.13, wh * 0.18)
ctx.globalAlpha = 1
glowBlob(ctx, cx0 + ww * 0.09, Y(0.45), ww * 0.14, cols[c], 0.4)
ctx.fillStyle = '#ff2d55'
ctx.beginPath()
ctx.arc(cx0 + ww * 0.06, Y(0.62), wh * 0.02, 0, Math.PI * 2)
ctx.fill()
}
break
}
case 3: {
// 机车改装: open garage, a bike on the stand, tools on the pegboard
vGradient(ctx, wx, wt, ww, wh, [
[0, '#1a140c'],
[1, '#2a2014'],
])
lightCone(ctx, X(0.5), Y(0.08), wh, 0.6, 0, '#ffe6b0', 0.22)
ctx.fillStyle = '#3a3226'
ctx.fillRect(X(0.05), Y(0.15), ww * 0.4, wh * 0.3)
ctx.fillStyle = '#9aa3ad'
for (let i = 0; i < 8; i++) ctx.fillRect(X(0.08 + (i % 4) * 0.09), Y(0.19 + Math.floor(i / 4) * 0.12), ww * 0.015, wh * 0.08)
ctx.fillStyle = '#0c0c0e'
for (let i = 0; i < 3; i++) {
ctx.beginPath()
ctx.ellipse(X(0.88), Y(0.94 - i * 0.1), ww * 0.08, wh * 0.05, 0, 0, Math.PI * 2)
ctx.fill()
}
bike(ctx, X(0.52), Y(0.98), ww * 0.42, { facing: 1, light: 0, parked: true })
// half-raised shutter
ctx.fillStyle = '#14171c'
ctx.fillRect(wx, wt, ww, wh * 0.08)
break
}
case 4: {
// 烧烤 / 大排档: glowing grill, smoke, plastic stools
vGradient(ctx, wx, wt, ww, wh, [
[0, '#1e0e06'],
[1, '#3a1a0a'],
])
ctx.fillStyle = '#1a1a1c'
ctx.fillRect(X(0.1), Y(0.55), ww * 0.45, wh * 0.08)
glowBlob(ctx, X(0.32), Y(0.55), ww * 0.3, '#ff5a1c', 0.6 + 0.2 * Math.sin(t * 7 + k))
ctx.strokeStyle = '#c9a26a'
ctx.lineWidth = Math.max(1, u * 2)
ctx.beginPath()
for (let i = 0; i < 7; i++) {
ctx.moveTo(X(0.12 + i * 0.06), Y(0.52))
ctx.lineTo(X(0.16 + i * 0.06), Y(0.57))
}
ctx.stroke()
for (let i = 0; i < 8; i++) {
const life = fract(t * 0.4 + hash(i + k))
ctx.fillStyle = `rgba(220,210,200,${0.18 * (1 - life)})`
ctx.beginPath()
ctx.arc(X(0.2 + 0.25 * hash(i)), Y(0.5 - life * 0.5), wh * (0.05 + life * 0.1), 0, Math.PI * 2)
ctx.fill()
}
for (const [fx, c] of [
[0.65, '#c4142f'],
[0.8, '#2a6ac4'],
] as [number, string][]) {
ctx.fillStyle = c
ctx.fillRect(X(fx), Y(0.8), ww * 0.08, wh * 0.04)
ctx.fillRect(X(fx + 0.01), Y(0.84), ww * 0.015, wh * 0.16)
ctx.fillRect(X(fx + 0.055), Y(0.84), ww * 0.015, wh * 0.16)
}
ctx.fillStyle = '#1f5a2a'
ctx.fillRect(X(0.72), Y(0.64), ww * 0.02, wh * 0.1)
ctx.fillRect(X(0.76), Y(0.66), ww * 0.02, wh * 0.08)
break
}
case 5: {
// 卡拉OK: disco ball and swirling spots
vGradient(ctx, wx, wt, ww, wh, [
[0, '#14062a'],
[1, '#2a0a40'],
])
const bx = X(0.5)
const by = Y(0.22)
for (let i = 0; i < 18; i++) {
const a = t * 1.2 + i * 0.7
ctx.fillStyle = ['#ff5fa2', '#3de0ff', '#ffe04a'][i % 3]
ctx.globalAlpha = 0.6
ctx.beginPath()
ctx.arc(bx + Math.cos(a) * ww * (0.15 + 0.3 * hash(i)), by + wh * 0.3 + Math.sin(a * 1.3) * wh * 0.3, wh * 0.025, 0, Math.PI * 2)
ctx.fill()
}
ctx.globalAlpha = 1
ctx.fillStyle = '#b8c0c8'
ctx.beginPath()
ctx.arc(bx, by, wh * 0.08, 0, Math.PI * 2)
ctx.fill()
glowBlob(ctx, bx, by, wh * 0.2, '#ffffff', 0.5)
ctx.strokeStyle = '#555'
ctx.beginPath()
ctx.moveTo(bx, wt)
ctx.lineTo(bx, by - wh * 0.08)
ctx.stroke()
break
}
case 6: {
// 士多 / 便利店: bright shelves + fridge
vGradient(ctx, wx, wt, ww, wh, [
[0, '#dfe8ee'],
[1, '#aebdc8'],
])
for (let r = 0; r < 4; r++)
for (let c = 0; c < 9; c++) {
ctx.fillStyle = ['#c4142f', '#2a6ac4', '#e8a01c', '#2a9a4a', '#8a3ac4'][(c + r * 2 + k) % 5]
ctx.fillRect(X(0.05 + c * 0.06), Y(0.2 + r * 0.18), ww * 0.045, wh * 0.1)
}
ctx.fillStyle = '#1a3a5a'
ctx.fillRect(X(0.66), Y(0.1), ww * 0.3, wh * 0.9)
glowBlob(ctx, X(0.8), Y(0.5), ww * 0.25, '#7fd8ff', 0.5)
ctx.fillStyle = '#9fdcff'
for (let i = 0; i < 12; i++) ctx.fillRect(X(0.68 + (i % 4) * 0.07), Y(0.2 + Math.floor(i / 4) * 0.25), ww * 0.03, wh * 0.14)
break
}
case 7: {
// 冰室: warm diner, booth + ceiling fan
vGradient(ctx, wx, wt, ww, wh, [
[0, '#3a2414'],
[1, '#5a361c'],
])
ctx.fillStyle = '#7a1e1e'
ctx.fillRect(X(0.05), Y(0.55), ww * 0.25, wh * 0.45)
ctx.fillRect(X(0.7), Y(0.55), ww * 0.25, wh * 0.45)
ctx.fillStyle = '#e8d8b8'
ctx.fillRect(X(0.35), Y(0.62), ww * 0.3, wh * 0.04)
ctx.fillRect(X(0.48), Y(0.66), ww * 0.04, wh * 0.34)
ctx.save()
ctx.translate(X(0.5), Y(0.12))
ctx.scale(1, 0.25)
ctx.rotate(t * 6)
ctx.fillStyle = '#2a1a0e'
for (let i = 0; i < 3; i++) {
ctx.rotate((Math.PI * 2) / 3)
ctx.fillRect(0, -wh * 0.02, ww * 0.2, wh * 0.04)
}
ctx.restore()
ctx.fillStyle = '#f0e0b0'
ctx.fillRect(X(0.2), Y(0.22), ww * 0.6, wh * 0.12)
ctx.fillStyle = '#5a361c'
for (let i = 0; i < 4; i++) ctx.fillRect(X(0.24 + i * 0.14), Y(0.26), ww * 0.1, wh * 0.03)
break
}
case 8: {
// 纹身: dark red, flash art on the wall
vGradient(ctx, wx, wt, ww, wh, [
[0, '#1a0608'],
[1, '#2a0a0e'],
])
for (let i = 0; i < 6; i++) {
ctx.fillStyle = '#e8e2d6'
ctx.fillRect(X(0.08 + (i % 3) * 0.14), Y(0.2 + Math.floor(i / 3) * 0.22), ww * 0.11, wh * 0.16)
ctx.fillStyle = ['#c4142f', '#1a1a1a', '#2a6ac4'][i % 3]
ctx.beginPath()
ctx.arc(X(0.135 + (i % 3) * 0.14), Y(0.28 + Math.floor(i / 3) * 0.22), wh * 0.04, 0, Math.PI * 2)
ctx.fill()
}
neonText(ctx, 'TATTOO', X(0.75), Y(0.3), wh * 0.12, PALETTE.red, fl(3, 4), { font: FONT.latin })
ctx.fillStyle = '#0a0a0c'
ctx.fillRect(X(0.62), Y(0.6), ww * 0.3, wh * 0.12)
ctx.fillRect(X(0.7), Y(0.72), ww * 0.04, wh * 0.28)
break
}
default: {
// 发廊: pink interior, mirror, barber chair
vGradient(ctx, wx, wt, ww, wh, [
[0, '#2a0a1e'],
[1, '#4a1430'],
])
ctx.fillStyle = '#6a8a9a'
ctx.fillRect(X(0.25), Y(0.15), ww * 0.4, wh * 0.4)
ctx.fillStyle = 'rgba(255,255,255,0.25)'
ctx.fillRect(X(0.28), Y(0.17), ww * 0.06, wh * 0.36)
ctx.fillStyle = '#0a0a0c'
ctx.fillRect(X(0.33), Y(0.6), ww * 0.24, wh * 0.14)
ctx.fillRect(X(0.43), Y(0.74), ww * 0.04, wh * 0.26)
glowBlob(ctx, X(0.45), Y(0.35), ww * 0.35, '#ff8ad8', 0.3)
}
}
ctx.restore()
// glass reflection + frame
ctx.fillStyle = 'rgba(255,255,255,0.05)'
ctx.beginPath()
ctx.moveTo(wx + ww * 0.1, wt)
ctx.lineTo(wx + ww * 0.25, wt)
ctx.lineTo(wx + ww * 0.05, groundY)
ctx.lineTo(wx - ww * 0.1, groundY)
ctx.fill()
ctx.strokeStyle = '#1a1d24'
ctx.lineWidth = Math.max(1, u * 4)
ctx.strokeRect(wx, wt, ww, wh)
glowBlob(ctx, wx + ww / 2, groundY, ww * 0.8, SHOP_COL[type], 0.22)
// barber pole outside the 发廊
if (type === 9) {
const px = x + cell * 0.93
ctx.fillStyle = '#f2f2f2'
ctx.fillRect(px - u * 9, groundY - u * 150, u * 18, u * 80)
ctx.save()
ctx.beginPath()
ctx.rect(px - u * 9, groundY - u * 150, u * 18, u * 80)
ctx.clip()
for (let i = -2; i < 8; i++) {
const yy = groundY - u * 150 + ((i * u * 20 + t * u * 40) % (u * 160)) - u * 20
ctx.fillStyle = i % 2 ? '#c4142f' : '#2a6ac4'
ctx.beginPath()
ctx.moveTo(px - u * 9, yy)
ctx.lineTo(px + u * 9, yy - u * 10)
ctx.lineTo(px + u * 9, yy - u * 4)
ctx.lineTo(px - u * 9, yy + u * 6)
ctx.fill()
}
ctx.restore()
}
// shop sign
neonSign(ctx, x + cell * 0.1, top + u * 24, cell * 0.8, u * 64, SHOPS[type], SHOP_COL[type], hash(k * 9.1) > 0.85 ? flicker(t, k, 8) : 1, false)
// AC unit + drip
ctx.fillStyle = '#10131a'
ctx.fillRect(x + cell * 0.7, top - u * 40, u * 50, u * 36)
}
/** 开场 backdrop: moonlit street corner with utility poles and wires */
function streetCorner(s: SceneCtx, groundY: number) {
const { ctx, W, H, u, t, P } = s
vGradient(ctx, -W * 0.2, -H * 0.2, W * 1.4, groundY + H * 0.2, [
[0, '#04060e'],
[0.7, '#0e1630'],
[1, '#1a2238'],
])
for (let i = 0; i < 70; i++) {
ctx.fillStyle = '#dfe8ff'
ctx.globalAlpha = 0.25 + 0.5 * Math.abs(Math.sin(t * (0.5 + hash(i)) + i))
ctx.fillRect(hash(i * 1.37) * W, hash(i * 2.71) * H * 0.45, u * 2, u * 2)
}
ctx.globalAlpha = 1
// the moon
const mx = W * (P ? 0.2 : 0.14)
const my = H * 0.13
const mr = Math.min(W, H) * 0.07
glowBlob(ctx, mx, my, mr * 8, '#9fb8ff', 0.25)
glowBlob(ctx, mx, my, mr * 2.5, '#e8efff', 0.45)
const mg = ctx.createRadialGradient(mx - mr * 0.3, my - mr * 0.3, mr * 0.1, mx, my, mr)
mg.addColorStop(0, '#ffffff')
mg.addColorStop(0.7, '#e8eefc')
mg.addColorStop(1, '#b8c4e0')
ctx.fillStyle = mg
ctx.beginPath()
ctx.arc(mx, my, mr, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = 'rgba(140,150,180,0.32)'
for (let i = 0; i < 5; i++) {
const a = hash(i * 4.1) * Math.PI * 2
const rr = mr * Math.sqrt(hash(i * 2.2)) * 0.7
ctx.beginPath()
ctx.arc(mx + Math.cos(a) * rr, my + Math.sin(a) * rr, mr * (0.08 + hash(i) * 0.12), 0, Math.PI * 2)
ctx.fill()
}
// distant skyline through the alley (bounces with the music)
skyline(ctx, { W: W * 1.2, seed: 3, baseY: groundY - H * 0.12, scroll: W * 0.1, cell: u * 55, minH: H * 0.08, maxH: H * 0.28, color: '#0a1020', t, density: 0.2, winAlpha: 0.5 })
const facade = (x0: number, x1: number, top: number, col: string, seed: number) => {
ctx.fillStyle = col
ctx.fillRect(x0, top, x1 - x0, groundY - top + 2)
const cw = u * 70
const rh = u * 78
for (let r = 0; top + u * 30 + r * rh < groundY - H * 0.2; r++) {
for (let c = 0; x0 + u * 24 + c * cw < x1 - u * 40; c++) {
const lit = hash3(seed, r, c) > 0.6
ctx.fillStyle = lit ? (hash3(seed + 1, r, c) > 0.75 ? '#7fc8d8' : '#e8a050') : '#06070c'
ctx.globalAlpha = lit ? 0.75 : 1
ctx.fillRect(x0 + u * 24 + c * cw, top + u * 30 + r * rh, u * 40, u * 46)
ctx.globalAlpha = 1
}
ctx.fillStyle = '#05060a'
ctx.fillRect(x0 + u * 10, top + u * 80 + r * rh, x1 - x0 - u * 20, u * 5)
}
// moonlight catching the edge
ctx.fillStyle = 'rgba(170,190,240,0.12)'
ctx.fillRect(x0, top, u * 6, groundY - top)
}
// left building + its side wall (the corner)
facade(-W * 0.05, W * 0.19, H * 0.1, '#0c0f18', 7)
ctx.fillStyle = '#080a10'
ctx.beginPath()
ctx.moveTo(W * 0.19, H * 0.1)
ctx.lineTo(W * 0.235, H * 0.17)
ctx.lineTo(W * 0.235, groundY)
ctx.lineTo(W * 0.19, groundY)
ctx.closePath()
ctx.fill()
// the corner building that carries the 黑街 sign
facade(W * 0.33, W * 1.05, -H * 0.05, '#0d1018', 11)
ctx.fillStyle = '#090b11'
ctx.beginPath()
ctx.moveTo(W * 0.33, -H * 0.05)
ctx.lineTo(W * 0.295, H * 0.03)
ctx.lineTo(W * 0.295, groundY)
ctx.lineTo(W * 0.33, groundY)
ctx.closePath()
ctx.fill()
// rolled-down shutters on the ground floor
ctx.fillStyle = '#12151c'
ctx.fillRect(W * 0.36, groundY - H * 0.17, W * 0.3, H * 0.17)
ctx.fillStyle = 'rgba(140,160,190,0.08)'
for (let y = groundY - H * 0.17; y < groundY; y += u * 7) ctx.fillRect(W * 0.36, y, W * 0.3, Math.max(1, u * 1.5))
// utility poles + wires
const pole = (x: number, top: number, w: number) => {
ctx.fillStyle = '#16100b'
ctx.fillRect(x - w / 2, top, w, groundY - top)
ctx.fillStyle = 'rgba(170,190,240,0.18)'
ctx.fillRect(x - w / 2, top, w * 0.25, groundY - top)
const arms = [top + w * 3, top + w * 7]
for (const ay of arms) {
ctx.fillStyle = '#16100b'
ctx.fillRect(x - w * 5, ay, w * 10, w * 0.8)
ctx.fillStyle = '#8a8f98'
for (const dx of [-4.3, -1.8, 1.8, 4.3]) {
ctx.beginPath()
ctx.ellipse(x + dx * w, ay - w * 0.5, w * 0.35, w * 0.55, 0, 0, Math.PI * 2)
ctx.fill()
}
}
// transformer drum + flyers
ctx.fillStyle = '#2a2e36'
ctx.beginPath()
ctx.roundRect(x + w * 0.6, top + w * 11, w * 3, w * 4.5, w * 0.5)
ctx.fill()
ctx.fillStyle = 'rgba(230,220,200,0.5)'
ctx.fillRect(x - w * 0.5, groundY - w * 14, w, w * 2)
ctx.fillStyle = 'rgba(220,60,60,0.5)'
ctx.fillRect(x - w * 0.5, groundY - w * 11, w, w * 1.6)
return arms.map((ay) => [-4.3, -1.8, 1.8, 4.3].map((dx) => ({ x: x + dx * w, y: ay - w * 0.8 })))
}
const pw = u * 16
const A = pole(W * 0.265, H * 0.03, pw)
const B = pole(W * 0.97, H * 0.12, pw * 0.75)
ctx.strokeStyle = '#05060a'
ctx.lineWidth = Math.max(1, u * 2)
for (let r = 0; r < 2; r++)
for (let k = 0; k < 4; k++) {
const a = A[r][k]
const b = B[r][k]
const sag = H * (0.05 + 0.015 * k) + Math.sin(t * 0.8 + k) * u * 2
ctx.beginPath()
ctx.moveTo(a.x, a.y)
ctx.quadraticCurveTo((a.x + b.x) / 2, (a.y + b.y) / 2 + sag, b.x, b.y)
ctx.stroke()
ctx.beginPath()
ctx.moveTo(a.x, a.y)
ctx.quadraticCurveTo(a.x - W * 0.2, a.y + sag * 0.8, -W * 0.15, a.y + H * 0.04)
ctx.stroke()
}
// a couple of birds on the wire, silhouetted against the moonlit sky
for (let i = 0; i < 3; i++) {
const a = A[0][1]
const b = B[0][1]
const q = 0.25 + i * 0.07
const bx = a.x + (b.x - a.x) * q
const by = a.y + (b.y - a.y) * q + H * 0.05 * 4 * q * (1 - q) - u * 7
ctx.fillStyle = '#05060a'
ctx.beginPath()
ctx.ellipse(bx, by, u * 7, u * 5, 0, 0, Math.PI * 2)
ctx.arc(bx + u * 6, by - u * 4, u * 3.5, 0, Math.PI * 2)
ctx.fill()
}
// moonlight washing down the street
lightCone(ctx, mx, my, H * 1.2, 0.5, -0.55, '#cfe0ff', 0.06)
}
import { BAR, BEAT, DROP1, bandAt, beatTime } from './audio'
import {
figureBack,
fogBand,
glowBlob,
halftone,
lightCone,
marquee,
neonSign,
neonText,
rain,
skyline,
speedLines,
splashes,
splitText,
streetLamp,
vGradient,
walker,
wetReflection,
} from './draw'
import { camera, resetCam, type SceneCtx } from './types'
import { bike, flame, heroRide, heroRideRear, heroSideSit } from './hero'
import { drawHighway, makeCam, poly3, proj } from './road3d'
import {
FONT,
PALETTE,
clamp,
easeInOutCubic,
easeOutBack,
easeOutCubic,
easeOutExpo,
fbm,
flicker,
fract,
hash,
hash2,
hash3,
lerp,
noise1,
rgba,
smoothstep,
} from './util'
const SIGN_WORDS = ['网吧', '桌球', '电玩城', '机车改装', '烧烤', '大排档', '卡拉OK', '士多', '冰室', '纹身', '发廊', '录像厅', '溜冰场', '夜宵', '修车', '通宵']
const SIGN_COLORS = [PALETTE.red, PALETTE.cyan, PALETTE.sodium, PALETTE.violet, PALETTE.teal, '#ff5fa2']
const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
// =====================================================================
// S1 — 开场·霓虹点亮 (0 – 9s)
// =====================================================================
export function sIgnite(s: SceneCtx) {
const { ctx, W, H, P, lt, u, t } = s
// a street corner under the moon: two buildings, utility poles, sagging wires
const groundY = P ? H * 0.74 : H * 0.76
const zoom = 1 + lt * 0.014
camera(s, zoom, W / 2, H * 0.47)
streetCorner(s, groundY)
const size = P ? Math.min(W * 0.4, H * 0.17) : Math.min(W * 0.25, H * 0.36)
const cy = P ? H * 0.31 : H * 0.36
const pos: [number, number][] = P
? [
[W / 2, cy - size * 0.55],
[W / 2, cy + size * 0.55],
]
: [
[W / 2 - size * 0.56, cy],
[W / 2 + size * 0.56, cy],
]
const buzz = 0.9 + 0.1 * hash(Math.floor(t * 40))
const lit = (start: number, end: number, seed: number) => {
if (lt < start) return 0
if (lt < end) return flicker(lt, seed, 16) * smoothstep(start, end, lt + 0.3)
return buzz
}
let on1 = lit(1.0, 2.1, 1)
let on2 = lit(2.6, 3.5, 2)
if (lt > 8.2) {
const f = flicker(lt, 9, 20)
on1 *= f
on2 *= f
}
// mounting plate
ctx.fillStyle = 'rgba(12,10,14,0.9)'
const plateW = P ? size * 1.45 : size * 2.5
const plateH = P ? size * 2.5 : size * 1.4
ctx.fillRect(W / 2 - plateW / 2, cy - plateH / 2, plateW, plateH)
ctx.strokeStyle = 'rgba(80,70,80,0.35)'
ctx.lineWidth = u * 2
ctx.strokeRect(W / 2 - plateW / 2, cy - plateH / 2, plateW, plateH)
glowBlob(ctx, W / 2, cy, size * 2.6, PALETTE.red, 0.22 * Math.max(on1, on2))
neonText(ctx, '黑', pos[0][0], pos[0][1], size, PALETTE.red, on1, { tube: true, blur: 0.4 })
neonText(ctx, '街', pos[1][0], pos[1][1], size, PALETTE.red, on2, { tube: true, blur: 0.4 })
// BLACK STREET typed on
const sub = 'BLACK STREET'
const typed = Math.floor(clamp((lt - 4.2) / 1.4) * sub.length)
if (typed > 0) {
const sy = P ? H * 0.075 : cy + size * 0.95