Spaces:
Paused
Paused
v2:重绘参考视频主角——卷发蓝毛衣少年「阿飞」和他的黑色摩托,9 个场景改为以他为主角
Browse files- README.md +35 -11
- public/mvfonts/black.woff2 +0 -0
- public/mvfonts/neon.woff2 +2 -2
- src/mv/MvApp.tsx +20 -2
- src/mv/copy/platforms.ts +17 -17
- src/mv/covers/covers.ts +25 -3
- src/mv/engine/hero.ts +959 -0
- src/mv/engine/scenesA.ts +94 -61
- src/mv/engine/scenesB.ts +194 -130
- src/mv/engine/timeline.ts +10 -10
- src/mv/export/exportMp4.ts +9 -2
README.md
CHANGED
|
@@ -33,7 +33,7 @@ pinned: false
|
|
| 33 |
| 5 | 适配**手机竖屏** | 横屏 16:9 / 竖屏 9:16 两套构图;所有场景按画布宽高自适应排版;手机端默认竖屏 |
|
| 34 |
| 6 | 导出帧率 **24 / 30 / 60** 可选 | 在导出面板中单选;第 i 帧的时间 = i / fps,保证和音频严格对齐 |
|
| 35 |
| 7 | 可复制的**标题、描述、标签** | 小红书 / 抖音 / 微信视频号 / 哔哩哔哩 四套文案,带字数和话题数校验,一键复制 |
|
| 36 |
-
| 8 | **封面**:4:3、3:4、16:9,每种比例多张,可多选 | 用 MV 关键帧渲染并叠加封面排版,每种比例
|
| 37 |
|
| 38 |
### 平台文案约束
|
| 39 |
|
|
@@ -79,25 +79,47 @@ pinned: false
|
|
| 79 |
|
| 80 |
- 主色:墨黑 `#07080c`、藏青 `#0f1d2b`、钠灯橙 `#ffb35c`、霓虹红 `#ff2d55`、冷青 `#3de0ff`
|
| 81 |
- 元素:雨丝、积水倒影、霓虹招牌(中文字)、楼宇剪影、卷帘门、电线杆、雾气、探照灯、车灯光轨
|
| 82 |
-
- 主角:
|
| 83 |
- 质感:WebGL 后期 → 辉光 + RGB 色差 + 胶片颗粒 + 扫描线 + 暗角,加上底鼓触发的闪白、震屏、故障效果
|
| 84 |
- 文字:原创动态字幕(不使用歌词原文),中文大字排版跟着节拍弹出
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
---
|
| 87 |
|
| 88 |
## 3. 分镜大纲(约 144 秒)
|
| 89 |
|
| 90 |
| 时间 | 场景 | 内容 |
|
| 91 |
|------|------|------|
|
| 92 |
-
| 0 – 9s | **S1 开场·霓虹
|
| 93 |
-
| 9 – 24s | **S2 雨夜
|
| 94 |
-
| 24 – 38.2s | **S3 蓄力·隧道** |
|
| 95 |
-
| 38.2 – 56s | **S4 Drop1·霓虹爆裂** |
|
| 96 |
-
| 56 – 73s | **S5
|
| 97 |
-
| 73 –
|
| 98 |
-
|
|
| 99 |
-
| 109.4 – 128s | **S8 Drop2·
|
| 100 |
-
| 128 – 144.4s | **S9 终章·
|
| 101 |
|
| 102 |
所有场景同时适配 16:9 和 9:16(按画布宽高比重新排版,不是简单裁切)。
|
| 103 |
|
|
@@ -118,6 +140,7 @@ pinned: false
|
|
| 118 |
├── App.tsx # 页面:播放器 / 导出 / 文案 / 封面
|
| 119 |
├── styles.css
|
| 120 |
├── engine/
|
|
|
|
| 121 |
│ ├── audioData.ts # 预计算的音频特征(60Hz)+ 节拍网格
|
| 122 |
│ ├── timeline.ts # 分镜时间轴、场景切换、转场
|
| 123 |
│ ├── scenes.ts # 各场景的绘制函数 draw(ctx, W, H, t, audio)
|
|
@@ -191,3 +214,4 @@ cp 素材/黑街.mp3 public/heijie.mp3
|
|
| 191 |
npm run dev # 开发
|
| 192 |
npm run build && npm start # 生产(http://localhost:3000)
|
| 193 |
```
|
|
|
|
|
|
| 33 |
| 5 | 适配**手机竖屏** | 横屏 16:9 / 竖屏 9:16 两套构图;所有场景按画布宽高自适应排版;手机端默认竖屏 |
|
| 34 |
| 6 | 导出帧率 **24 / 30 / 60** 可选 | 在导出面板中单选;第 i 帧的时间 = i / fps,保证和音频严格对齐 |
|
| 35 |
| 7 | 可复制的**标题、描述、标签** | 小红书 / 抖音 / 微信视频号 / 哔哩哔哩 四套文案,带字数和话题数校验,一键复制 |
|
| 36 |
+
| 8 | **封面**:4:3、3:4、16:9,每种比例多张,可多选 | 用 MV 关键帧渲染并叠加封面排版,每种比例 8 款设计,可勾选多张批量下载 PNG |
|
| 37 |
|
| 38 |
### 平台文案约束
|
| 39 |
|
|
|
|
| 79 |
|
| 80 |
- 主色:墨黑 `#07080c`、藏青 `#0f1d2b`、钠灯橙 `#ffb35c`、霓虹红 `#ff2d55`、冷青 `#3de0ff`
|
| 81 |
- 元素:雨丝、积水倒影、霓虹招牌(中文字)、楼宇剪影、卷帘门、电线杆、雾气、探照灯、车灯光轨
|
| 82 |
+
- 主角:~~穿连帽衫的剪影「夜行者」~~ → v2 改为参考视频里的卷发少年「阿飞」和他的黑色摩托(见 2.5)
|
| 83 |
- 质感:WebGL 后期 → 辉光 + RGB 色差 + 胶片颗粒 + 扫描线 + 暗角,加上底鼓触发的闪白、震屏、故障效果
|
| 84 |
- 文字:原创动态字幕(不使用歌词原文),中文大字排版跟着节拍弹出
|
| 85 |
|
| 86 |
+
### 2.5 主角重绘:卷发少年「阿飞」(v2 新增)
|
| 87 |
+
|
| 88 |
+
参考视频(`41920891009-1-192.mp4`)里有一个贯穿全片的主角,新 MV 把他重新画出来作为主角。
|
| 89 |
+
|
| 90 |
+
**怎么"看"出主角的:**
|
| 91 |
+
1. 每 3 秒抽一帧(视频 A,54 张),每 10 秒抽一帧(视频 B,65 张,隔一张取一张)
|
| 92 |
+
2. 用本地图像识别模型 Florence-2 逐帧生成详细描述;视频 A 中几十帧描述都指向同一个人:*年轻男生、黑色卷发、蓝色毛衣、黑/灰色裤子、骑一辆黑色摩托(圆形车头灯、两个圆形后视镜、红色尾灯)*,表情多为闭眼、忧伤
|
| 93 |
+
3. 用「短语定位 + 分割」框出人物和头发,在人物轮廓内测量真实颜色:头发 `#101310`,皮肤 `#b0a088`–`#dbc39c`,毛衣 `#2e3b42`(夜景下);头发框占人物框高度的 35–45%(大头、蓬松卷发、Q 版比例)
|
| 94 |
+
4. 参考里的典型桥段:雨夜砖墙小巷与路灯、推着摩托站在街上、篝火与啤酒、日落山路、夜间高速与大货车、读信后把信烧掉、星空大树下、夜里驶过的火车
|
| 95 |
+
|
| 96 |
+
**重绘的角色设定(`src/mv/engine/hero.ts`,全部程序化绘制):**
|
| 97 |
+
|
| 98 |
+
| 部位 | 设定 |
|
| 99 |
+
|------|------|
|
| 100 |
+
| 头发 | 黑色蓬松大卷发(几十个卷团 + 每个卷团上的高光弧线),风速越大越往后飘 |
|
| 101 |
+
| 脸 | 暖米色皮肤,常闭眼、粗眉、略带忧伤;特写可睁眼、浅笑、落泪 |
|
| 102 |
+
| 衣服 | 深蓝色长袖毛衣(罗纹领口和下摆),灰色长裤,黑色运动鞋白鞋底 |
|
| 103 |
+
| 摩托 | 黑色复古摩托:圆形车头灯(带光束)、两个圆后视镜、水滴油箱、镀铬排气管、辐条轮、红色尾灯 |
|
| 104 |
+
| 画法 | 侧面走路(可推车)、背影、侧面骑车、后视角骑车、坐地读信 / 烧信、正面特写,共 6 种画法 |
|
| 105 |
+
|
| 106 |
+
**校验:** 把渲染出来的画面再交给同一个识别模型描述,得到例如 *"一个穿蓝色上衣、卷发的人骑着黑色摩托,背后是巨大的红色太阳"*、*"一个人坐在摩托旁,手里拿着火光"*、*"头发是蓬松卷发、闭着眼、表情忧伤"*,和参考视频主角的描述一致。
|
| 107 |
+
|
| 108 |
---
|
| 109 |
|
| 110 |
## 3. 分镜大纲(约 144 秒)
|
| 111 |
|
| 112 |
| 时间 | 场景 | 内容 |
|
| 113 |
|------|------|------|
|
| 114 |
+
| 0 – 9s | **S1 开场·霓虹与摩托** | 雨夜路灯下停着他的黑色摩托 →「黑街」霓虹灯管逐笔点亮,摩托车头灯随之亮起 |
|
| 115 |
+
| 9 – 24s | **S2 雨夜·推车少年** | 阿飞推着摩托走过霓虹长街,积水倒影,招牌闪烁 |
|
| 116 |
+
| 24 – 38.2s | **S3 蓄力·隧道** | 阿飞骑车冲进隧道(后视角),卷发被风吹起,倒数 3·2·1 |
|
| 117 |
+
| 38.2 – 56s | **S4 Drop1·霓虹爆裂** | 海报大字 / 均衡器天际线 / 阿飞侧面飙车 / 霓虹格子,按小节快切 |
|
| 118 |
+
| 56 – 73s | **S5 山顶·红月** | 阿飞坐在摩托上望着巨大红月 → 脸部特写(睁眼、浅笑)→ 山下城市灯海 |
|
| 119 |
+
| 73 – 91s | **S6 葱姜蒜夜市** | 暖色灯笼、蒸汽、葱姜蒜摊位,阿飞从镜头前走过 |
|
| 120 |
+
| 91 – 109.4s | **S7 灯下·烧掉的信** | 路灯下,阿飞坐在摩托旁读信 → 闭眼落泪特写 → 把信烧掉,心跳加速 |
|
| 121 |
+
| 109.4 – 128s | **S8 Drop2·公路之王** | 夜间高速,大货车并行,阿飞后视角 / 侧面狂飙 |
|
| 122 |
+
| 128 – 144.4s | **S9 终章·星空与火车** | 大树、星空、弯月、远处驶过的红黄火车,阿飞坐在车上看着 → 光点汇聚成「黑街」 |
|
| 123 |
|
| 124 |
所有场景同时适配 16:9 和 9:16(按画布宽高比重新排版,不是简单裁切)。
|
| 125 |
|
|
|
|
| 140 |
├── App.tsx # 页面:播放器 / 导出 / 文案 / 封面
|
| 141 |
├── styles.css
|
| 142 |
├── engine/
|
| 143 |
+
│ ├── hero.ts # 主角「阿飞」与他的摩托(6 种画法)
|
| 144 |
│ ├── audioData.ts # 预计算的音频特征(60Hz)+ 节拍网格
|
| 145 |
│ ├── timeline.ts # 分镜时间轴、场景切换、转场
|
| 146 |
│ ├── scenes.ts # 各场景的绘制函数 draw(ctx, W, H, t, audio)
|
|
|
|
| 214 |
npm run dev # 开发
|
| 215 |
npm run build && npm start # 生产(http://localhost:3000)
|
| 216 |
```
|
| 217 |
+
- **步骤 7(v2:主角重绘)** ✅ 按要求把参考视频里的主角画出来做新主角:用本地识别模型 Florence-2 描述 119 张截图、定位并分割人物、测量发色 / 肤色 / 衣服颜色和头身比例,新建 `hero.ts` 绘制卷发蓝毛衣少年「阿飞」和他的黑色复古摩托(6 种画法);9 个场景全部改成以他为主角的情节(雨夜推车、隧道骑行、红月山顶特写、灯下读信烧信、货车并行的公路、星空大树与火车);新增「阿飞特写」「灯下烧信」两款封面(每种比例 8 款,共 24 张);文案同步加入主角。再用识别模型回看渲染画面,确认能被描述为「蓝衣卷发少年骑黑色摩托」。全时间轴横竖屏逐 0.5 秒扫描无报错。
|
public/mvfonts/black.woff2
CHANGED
|
Binary files a/public/mvfonts/black.woff2 and b/public/mvfonts/black.woff2 differ
|
|
|
public/mvfonts/neon.woff2
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a3fa76be4b851fc0b7bd9e508e237a0b705ed8ed9325460e268591c745887db5
|
| 3 |
+
size 104752
|
src/mv/MvApp.tsx
CHANGED
|
@@ -5,7 +5,7 @@ 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 |
|
|
@@ -69,7 +69,7 @@ export default function MvApp() {
|
|
| 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 =
|
| 73 |
r.setSize(w, h)
|
| 74 |
const t0 = performance.now()
|
| 75 |
r.render(t)
|
|
@@ -77,6 +77,24 @@ export default function MvApp() {
|
|
| 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">
|
|
|
|
| 5 |
import { Renderer } from './engine/renderer'
|
| 6 |
import { SCENES, sceneAt } from './engine/timeline'
|
| 7 |
import { AUDIO_URL, loadFonts } from './fonts'
|
| 8 |
+
import { exportMp4, exportRenderer, 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 |
|
|
|
|
| 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 = exportRenderer()
|
| 73 |
r.setSize(w, h)
|
| 74 |
const t0 = performance.now()
|
| 75 |
r.render(t)
|
|
|
|
| 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 |
+
;(window as unknown as { __mvSheet: unknown }).__mvSheet = async (which: string, w: number, h: number) => {
|
| 81 |
+
const H = await import('./engine/hero')
|
| 82 |
+
const c = document.createElement('canvas')
|
| 83 |
+
c.width = w
|
| 84 |
+
c.height = h
|
| 85 |
+
const g = c.getContext('2d')!
|
| 86 |
+
g.fillStyle = '#8a96a6'
|
| 87 |
+
g.fillRect(0, 0, w, h)
|
| 88 |
+
const s = Math.min(w, h)
|
| 89 |
+
if (which === 'walk') H.heroWalk(g, w / 2, h * 0.95, h * 0.9, 0.2, { t: 1 })
|
| 90 |
+
if (which === 'back') H.heroBack(g, w / 2, h * 0.95, h * 0.9, 0, { t: 1 })
|
| 91 |
+
if (which === 'bike') H.bike(g, w / 2, h * 0.9, s * 0.8, { t: 1 })
|
| 92 |
+
if (which === 'ride') H.heroRide(g, w / 2, h * 0.92, s * 0.75, { t: 1, smile: true })
|
| 93 |
+
if (which === 'rear') H.heroRideRear(g, w / 2, h * 0.98, h * 0.95, 0, 1)
|
| 94 |
+
if (which === 'sit') H.heroSit(g, w / 2, h * 0.95, h * 0.9, 1, { fire: 1 })
|
| 95 |
+
if (which === 'face') H.heroPortrait(g, w / 2, h * 0.42, h * 0.22, { t: 1, tear: 0.5 })
|
| 96 |
+
return c.toDataURL('image/png')
|
| 97 |
+
}
|
| 98 |
}, [])
|
| 99 |
return (
|
| 100 |
<div className="mv-root">
|
src/mv/copy/platforms.ts
CHANGED
|
@@ -21,10 +21,10 @@ export const PLATFORMS: PlatformCopy[] = [
|
|
| 21 |
titleLimit: 20,
|
| 22 |
tagLimit: 10,
|
| 23 |
tagStyle: 'hash',
|
| 24 |
-
titles: ['把《黑街》做成了雨夜霓虹MV🌃', '105BPM卡点|黑街雨夜动画', '听到Drop那一秒,整条街都亮了'],
|
| 25 |
desc:
|
| 26 |
'用代码一帧一帧画出来的《黑街》MV🎧\n' +
|
| 27 |
-
'雨夜
|
| 28 |
'两次 Drop 全程卡点,建议戴耳机、调大音量🔊\n\n' +
|
| 29 |
'🎵 音乐:DJ鐘董《黑街(DJ葱姜蒜进行曲)》\n' +
|
| 30 |
'你最喜欢哪一个镜头?评论区告诉我👇',
|
|
@@ -38,9 +38,9 @@ export const PLATFORMS: PlatformCopy[] = [
|
|
| 38 |
titleLimit: 30,
|
| 39 |
tagLimit: 5,
|
| 40 |
tagStyle: 'hash',
|
| 41 |
-
titles: ['凌晨两点的黑街,霓虹替我记住每一条路', '等到38秒,整条黑街一起炸开🔥', '《黑街》全程卡点,第二次Drop直接上头'],
|
| 42 |
-
desc: '原创程序化动画 × DJ鐘董《黑街》\n雨夜、
|
| 43 |
-
tags: ['黑街', 'DJ葱姜蒜进行曲', '
|
| 44 |
tip: '标题 ≤ 30 字,话题 ≤ 5 个',
|
| 45 |
},
|
| 46 |
{
|
|
@@ -50,11 +50,11 @@ export const PLATFORMS: PlatformCopy[] = [
|
|
| 50 |
titleLimit: 16,
|
| 51 |
tagLimit: null,
|
| 52 |
tagStyle: 'hash',
|
| 53 |
-
titles: ['雨夜黑街,霓虹不打烊', '这条街,从不问来处', '黑街:一首歌走完一座城'],
|
| 54 |
desc:
|
| 55 |
-
'用代码画出的一支 MV:雨夜
|
| 56 |
'音乐来自 DJ鐘董《黑街(DJ葱姜蒜进行曲)》,建议戴耳机观看。',
|
| 57 |
-
tags: ['黑街', 'DJ葱姜蒜进行曲', 'DJ鐘董', '原创MV', '音乐可视化', '霓虹', '夜景', '雨夜', '赛博朋克', '动画', '卡点', '氛围感', '城市夜色'],
|
| 58 |
tip: '标题 ≤ 16 字,话题不限',
|
| 59 |
},
|
| 60 |
{
|
|
@@ -66,24 +66,24 @@ export const PLATFORMS: PlatformCopy[] = [
|
|
| 66 |
tagStyle: 'comma',
|
| 67 |
titles: [
|
| 68 |
'【原创MV】《黑街》DJ葱姜蒜进行曲|纯代码绘制的雨夜霓虹动画,两次Drop全程卡点,支持竖屏观看',
|
| 69 |
-
'【程序化动画】
|
| 70 |
'105.5BPM卡点!用浏览器实时渲染一支《黑街》MV,每一帧都是代码画的',
|
| 71 |
],
|
| 72 |
desc:
|
| 73 |
'🎵 音乐:DJ鐘董《黑街(DJ葱姜蒜进行曲)》\n' +
|
| 74 |
-
'🎨 画面:原创程序化动画,浏览器 Canvas + WebGL 实时渲染
|
| 75 |
'⏱ 分镜\n' +
|
| 76 |
-
'00:00 开场·霓虹
|
| 77 |
-
'00:09 雨夜
|
| 78 |
'00:23 蓄力·隧道\n' +
|
| 79 |
'00:38 Drop1·霓虹爆裂\n' +
|
| 80 |
-
'00:56
|
| 81 |
'01:12 葱姜蒜夜市\n' +
|
| 82 |
-
'01:31
|
| 83 |
-
'01:49 Drop2·
|
| 84 |
-
'02:07 终章·
|
| 85 |
'喜欢的话一键三连,弹幕告诉我你最喜欢哪个镜头!',
|
| 86 |
-
tags: ['黑街', 'DJ葱姜蒜进行曲', '原创MV', '
|
| 87 |
tip: '标题 ≤ 80 字,标签 ≤ 10 个',
|
| 88 |
},
|
| 89 |
]
|
|
|
|
| 21 |
titleLimit: 20,
|
| 22 |
tagLimit: 10,
|
| 23 |
tagStyle: 'hash',
|
| 24 |
+
titles: ['卷发少年的黑街摩托夜🏍️', '把《黑街》做成了雨夜霓虹MV🌃', '105BPM卡点|黑街雨夜动画', '听到Drop那一秒,整条街都亮了'],
|
| 25 |
desc:
|
| 26 |
'用代码一帧一帧画出来的《黑街》MV🎧\n' +
|
| 27 |
+
'蓝毛衣卷发少年阿飞,和他的黑色摩托:雨夜推车、红月山顶、灯下烧信、公路狂飙……\n' +
|
| 28 |
'两次 Drop 全程卡点,建议戴耳机、调大音量🔊\n\n' +
|
| 29 |
'🎵 音乐:DJ鐘董《黑街(DJ葱姜蒜进行曲)》\n' +
|
| 30 |
'你最喜欢哪一个镜头?评论区告诉我👇',
|
|
|
|
| 38 |
titleLimit: 30,
|
| 39 |
tagLimit: 5,
|
| 40 |
tagStyle: 'hash',
|
| 41 |
+
titles: ['卷发少年和他的黑摩托,开成了公路之王', '凌晨两点的黑街,霓虹替我记住每一条路', '等到38秒,整条黑街一起炸开🔥', '《黑街》全程卡点,第二次Drop直接上头'],
|
| 42 |
+
desc: '原创程序化动画 × DJ鐘董《黑街》\n卷发少年阿飞和他的黑色摩托,雨夜、红月、烧掉的信、公路之王。\n戴上耳机,等那一声重低音。',
|
| 43 |
+
tags: ['黑街', 'DJ葱姜蒜进行曲', '公路之王', '卡点', '原创MV'],
|
| 44 |
tip: '标题 ≤ 30 字,话题 ≤ 5 个',
|
| 45 |
},
|
| 46 |
{
|
|
|
|
| 50 |
titleLimit: 16,
|
| 51 |
tagLimit: null,
|
| 52 |
tagStyle: 'hash',
|
| 53 |
+
titles: ['少年与摩托,雨夜黑街', '雨夜黑街,霓虹不打烊', '这条街,从不问来处', '黑街:一首歌走完一座城'],
|
| 54 |
desc:
|
| 55 |
+
'用代码画出的一支 MV:卷发少年阿飞骑着黑色摩托,穿过雨夜、红月山顶、葱姜蒜夜市,一路开成公路之王。\n' +
|
| 56 |
'音乐来自 DJ鐘董《黑街(DJ葱姜蒜进行曲)》,建议戴耳机观看。',
|
| 57 |
+
tags: ['黑街', 'DJ葱姜蒜进行曲', 'DJ鐘董', '原创MV', '音乐可视化', '霓虹', '夜景', '雨夜', '赛博朋克', '动画', '卡点', '氛围感', '城市夜色', '公路之王', '摩托少年'],
|
| 58 |
tip: '标题 ≤ 16 字,话题不限',
|
| 59 |
},
|
| 60 |
{
|
|
|
|
| 66 |
tagStyle: 'comma',
|
| 67 |
titles: [
|
| 68 |
'【原创MV】《黑街》DJ葱姜蒜进行曲|纯代码绘制的雨夜霓虹动画,两次Drop全程卡点,支持竖屏观看',
|
| 69 |
+
'【程序化动画】卷发少年和他的摩托:雨夜推车→红月山顶→灯下烧信→公路之王',
|
| 70 |
'105.5BPM卡点!用浏览器实时渲染一支《黑街》MV,每一帧都是代码画的',
|
| 71 |
],
|
| 72 |
desc:
|
| 73 |
'🎵 音乐:DJ鐘董《黑街(DJ葱姜蒜进行曲)》\n' +
|
| 74 |
+
'🎨 画面:原创程序化动画,浏览器 Canvas + WebGL 实时渲染;主角「阿飞」按参考视频里的蓝毛衣卷发少年重新绘制\n\n' +
|
| 75 |
'⏱ 分镜\n' +
|
| 76 |
+
'00:00 开场·霓虹与摩托\n' +
|
| 77 |
+
'00:09 雨夜·推车少年\n' +
|
| 78 |
'00:23 蓄力·隧道\n' +
|
| 79 |
'00:38 Drop1·霓虹爆裂\n' +
|
| 80 |
+
'00:56 山顶·红月\n' +
|
| 81 |
'01:12 葱姜蒜夜市\n' +
|
| 82 |
+
'01:31 灯下·烧掉的信\n' +
|
| 83 |
+
'01:49 Drop2·公路之王\n' +
|
| 84 |
+
'02:07 终章·星空与火车\n\n' +
|
| 85 |
'喜欢的话一键三连,弹幕告诉我你最喜欢哪个镜头!',
|
| 86 |
+
tags: ['黑街', 'DJ葱姜蒜进行曲', '原创MV', '公路之王', '程序化动画', '摩托', '霓虹', '卡点', '动画短片', '音乐可视化'],
|
| 87 |
tip: '标题 ≤ 80 字,标签 ≤ 10 个',
|
| 88 |
},
|
| 89 |
]
|
src/mv/covers/covers.ts
CHANGED
|
@@ -82,8 +82,8 @@ export const DESIGNS: CoverDesign[] = [
|
|
| 82 |
},
|
| 83 |
{
|
| 84 |
id: 'street',
|
| 85 |
-
name: '雨夜
|
| 86 |
-
t:
|
| 87 |
overlay(ctx, W, H) {
|
| 88 |
const u = S(W, H)
|
| 89 |
const P = H > W
|
|
@@ -99,7 +99,7 @@ export const DESIGNS: CoverDesign[] = [
|
|
| 99 |
},
|
| 100 |
{
|
| 101 |
id: 'moon',
|
| 102 |
-
name: '红月
|
| 103 |
t: 60.6,
|
| 104 |
overlay(ctx, W, H) {
|
| 105 |
const u = S(W, H)
|
|
@@ -110,6 +110,28 @@ export const DESIGNS: CoverDesign[] = [
|
|
| 110 |
textBlock(ctx, '城市睡了,红月醒着', P ? W / 2 : W * 0.62, H - u * 110, u * 56, FONT.black, PALETTE.bone, { stroke: 'rgba(0,0,0,0.7)' })
|
| 111 |
},
|
| 112 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
{
|
| 114 |
id: 'market',
|
| 115 |
name: '葱姜蒜夜市',
|
|
|
|
| 82 |
},
|
| 83 |
{
|
| 84 |
id: 'street',
|
| 85 |
+
name: '雨夜推车',
|
| 86 |
+
t: 13.2,
|
| 87 |
overlay(ctx, W, H) {
|
| 88 |
const u = S(W, H)
|
| 89 |
const P = H > W
|
|
|
|
| 99 |
},
|
| 100 |
{
|
| 101 |
id: 'moon',
|
| 102 |
+
name: '红月山顶',
|
| 103 |
t: 60.6,
|
| 104 |
overlay(ctx, W, H) {
|
| 105 |
const u = S(W, H)
|
|
|
|
| 110 |
textBlock(ctx, '城市睡了,红月醒着', P ? W / 2 : W * 0.62, H - u * 110, u * 56, FONT.black, PALETTE.bone, { stroke: 'rgba(0,0,0,0.7)' })
|
| 111 |
},
|
| 112 |
},
|
| 113 |
+
{
|
| 114 |
+
id: 'hero',
|
| 115 |
+
name: '阿飞特写',
|
| 116 |
+
t: 65.6,
|
| 117 |
+
overlay(ctx, W, H) {
|
| 118 |
+
const u = S(W, H)
|
| 119 |
+
const P = H > W
|
| 120 |
+
badge(ctx, '主角 · 阿飞', u * 50, u * 50, u * 38, PALETTE.red, '#fff')
|
| 121 |
+
textBlock(ctx, '黑街', P ? W / 2 : W * 0.8, P ? H * 0.12 : H * 0.3, P ? W * 0.2 : H * 0.2, FONT.black, '#fff', { shadow: PALETTE.red })
|
| 122 |
+
textBlock(ctx, '卷发少年和他的黑摩托', P ? W / 2 : W * 0.8, P ? H * 0.9 : H * 0.48, u * 50, FONT.black, PALETTE.bone, { stroke: 'rgba(0,0,0,0.7)' })
|
| 123 |
+
},
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
id: 'letter',
|
| 127 |
+
name: '灯下烧信',
|
| 128 |
+
t: 104.2,
|
| 129 |
+
overlay(ctx, W, H) {
|
| 130 |
+
const u = S(W, H)
|
| 131 |
+
textBlock(ctx, '烧掉它,再出发', W / 2, u * 120, u * 72, FONT.black, '#fff', { shadow: '#ff7a2e' })
|
| 132 |
+
textBlock(ctx, '黑街 BLACK STREET', W / 2, H - u * 90, u * 44, FONT.black, PALETTE.bone)
|
| 133 |
+
},
|
| 134 |
+
},
|
| 135 |
{
|
| 136 |
id: 'market',
|
| 137 |
name: '葱姜蒜夜市',
|
src/mv/engine/hero.ts
ADDED
|
@@ -0,0 +1,959 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// 主角「阿飞」— redrawn from the protagonist of the reference footage:
|
| 2 |
+
// a young man with a big mop of curly black hair, a deep-blue long-sleeve
|
| 3 |
+
// sweater, grey trousers, and his black classic motorcycle (round headlight,
|
| 4 |
+
// two round mirrors, red tail light). Mood: quiet, melancholic, eyes often closed.
|
| 5 |
+
import { glowBlob, lightCone } from './draw'
|
| 6 |
+
import { hash, rgba } from './util'
|
| 7 |
+
|
| 8 |
+
type C2D = CanvasRenderingContext2D
|
| 9 |
+
|
| 10 |
+
export const HERO = {
|
| 11 |
+
skin: '#e6caa2',
|
| 12 |
+
skinShade: '#b9997a',
|
| 13 |
+
blush: '#e89a86',
|
| 14 |
+
hair: '#121411',
|
| 15 |
+
hairHi: '#41556b',
|
| 16 |
+
sweater: '#2f4b66',
|
| 17 |
+
sweaterShade: '#213649',
|
| 18 |
+
sweaterHi: '#44698c',
|
| 19 |
+
rib: '#273f57',
|
| 20 |
+
pants: '#8c9196',
|
| 21 |
+
pantsShade: '#646a70',
|
| 22 |
+
shoe: '#1b1b1d',
|
| 23 |
+
sole: '#dcd6cb',
|
| 24 |
+
bike: '#121419',
|
| 25 |
+
bikeHi: '#3a4250',
|
| 26 |
+
chrome: '#c3cad2',
|
| 27 |
+
seat: '#201b18',
|
| 28 |
+
tire: '#09090a',
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// ------------------------------------------------------------------ hair
|
| 32 |
+
/** Curly mop: a deterministic cluster of curls around the top/back of a head. */
|
| 33 |
+
function curls(ctx: C2D, cx: number, cy: number, r: number, facing: number, wind: number, t: number, front = false) {
|
| 34 |
+
const n = front ? 30 : 32
|
| 35 |
+
const pts: { x: number; y: number; r: number }[] = []
|
| 36 |
+
for (let i = 0; i < n; i++) {
|
| 37 |
+
let a: number
|
| 38 |
+
if (front) a = Math.PI * 0.9 + (i / (n - 1)) * Math.PI * 1.2 // left → over the top → right
|
| 39 |
+
else a = -Math.PI / 2 - facing * (-0.85 + (i / (n - 1)) * 3.05) // forehead → crown → down to the nape
|
| 40 |
+
const k = 1.02 + 0.14 * hash(i * 3.7)
|
| 41 |
+
const wob = Math.sin(t * 9 + i * 1.7) * wind * 0.05
|
| 42 |
+
const back = -facing * wind * r * (0.2 + 0.4 * (1 - Math.abs(Math.sin(a))))
|
| 43 |
+
pts.push({
|
| 44 |
+
x: cx + Math.cos(a) * r * k + (front ? 0 : back) + wob * r,
|
| 45 |
+
y: cy + Math.sin(a) * r * k * (front ? 0.95 : 1) + wob * r * 0.5,
|
| 46 |
+
r: r * (0.34 + 0.16 * hash(i * 1.3)),
|
| 47 |
+
})
|
| 48 |
+
}
|
| 49 |
+
// a second, inner row of curls for volume
|
| 50 |
+
const inner = front ? 12 : 10
|
| 51 |
+
for (let i = 0; i < inner; i++) {
|
| 52 |
+
const a = front ? Math.PI * 1.05 + (i / (inner - 1)) * Math.PI * 0.9 : -Math.PI / 2 - facing * (-0.3 + (i / (inner - 1)) * 1.9)
|
| 53 |
+
pts.push({ x: cx + Math.cos(a) * r * 0.62 - (front ? 0 : facing * wind * r * 0.2), y: cy + Math.sin(a) * r * 0.62 - r * 0.05, r: r * (0.3 + 0.12 * hash(i * 7.9)) })
|
| 54 |
+
}
|
| 55 |
+
ctx.fillStyle = HERO.hair
|
| 56 |
+
ctx.beginPath()
|
| 57 |
+
for (const p of pts) {
|
| 58 |
+
ctx.moveTo(p.x + p.r, p.y)
|
| 59 |
+
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
|
| 60 |
+
}
|
| 61 |
+
// fill the crown (top & back only, the face stays visible)
|
| 62 |
+
if (front) {
|
| 63 |
+
ctx.moveTo(cx + r * 0.95, cy - r * 0.5)
|
| 64 |
+
ctx.ellipse(cx, cy - r * 0.5, r * 0.95, r * 0.5, 0, 0, Math.PI * 2)
|
| 65 |
+
} else {
|
| 66 |
+
const ccx = cx - facing * r * (0.22 + wind * 0.12)
|
| 67 |
+
ctx.moveTo(ccx + r * 0.8, cy - r * 0.3)
|
| 68 |
+
ctx.ellipse(ccx, cy - r * 0.3, r * 0.8, r * 0.62, 0, 0, Math.PI * 2)
|
| 69 |
+
// back of the skull, down to the nape
|
| 70 |
+
const bx = cx - facing * r * (0.45 + wind * 0.15)
|
| 71 |
+
ctx.moveTo(bx + r * 0.62, cy + r * 0.1)
|
| 72 |
+
ctx.ellipse(bx, cy + r * 0.1, r * 0.62, r * 0.8, 0, 0, Math.PI * 2)
|
| 73 |
+
}
|
| 74 |
+
ctx.fill()
|
| 75 |
+
// curl texture: a highlight crescent on every curl
|
| 76 |
+
ctx.strokeStyle = HERO.hairHi
|
| 77 |
+
ctx.lineWidth = Math.max(1, r * 0.075)
|
| 78 |
+
ctx.lineCap = 'round'
|
| 79 |
+
ctx.beginPath()
|
| 80 |
+
for (const p of pts) {
|
| 81 |
+
const rr = p.r * 0.62
|
| 82 |
+
ctx.moveTo(p.x + rr * Math.cos(-2.6), p.y + rr * Math.sin(-2.6))
|
| 83 |
+
ctx.arc(p.x, p.y, rr, -2.6, -0.5)
|
| 84 |
+
}
|
| 85 |
+
ctx.stroke()
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/** Side-view head with curly hair. facing 1 = looking right. */
|
| 89 |
+
export function heroHead(ctx: C2D, cx: number, cy: number, r: number, facing: number, o: { wind?: number; t?: number; eyes?: 'closed' | 'open'; smile?: boolean; rim?: string } = {}) {
|
| 90 |
+
const t = o.t ?? 0
|
| 91 |
+
const wind = o.wind ?? 0
|
| 92 |
+
// neck
|
| 93 |
+
ctx.fillStyle = HERO.skinShade
|
| 94 |
+
ctx.fillRect(cx - r * 0.22, cy + r * 0.7, r * 0.44, r * 0.5)
|
| 95 |
+
// face / skull
|
| 96 |
+
ctx.fillStyle = HERO.skin
|
| 97 |
+
ctx.beginPath()
|
| 98 |
+
ctx.ellipse(cx + facing * r * 0.06, cy + r * 0.05, r * 0.86, r * 0.92, 0, 0, Math.PI * 2)
|
| 99 |
+
ctx.fill()
|
| 100 |
+
// nose & chin profile
|
| 101 |
+
ctx.beginPath()
|
| 102 |
+
ctx.moveTo(cx + facing * r * 0.84, cy - r * 0.02)
|
| 103 |
+
ctx.quadraticCurveTo(cx + facing * r * 1.04, cy + r * 0.16, cx + facing * r * 0.84, cy + r * 0.24)
|
| 104 |
+
ctx.lineTo(cx + facing * r * 0.7, cy + r * 0.62)
|
| 105 |
+
ctx.lineTo(cx + facing * r * 0.3, cy + r * 0.86)
|
| 106 |
+
ctx.lineTo(cx, cy + r * 0.5)
|
| 107 |
+
ctx.closePath()
|
| 108 |
+
ctx.fill()
|
| 109 |
+
// ear
|
| 110 |
+
ctx.fillStyle = HERO.skinShade
|
| 111 |
+
ctx.beginPath()
|
| 112 |
+
ctx.ellipse(cx - facing * r * 0.12, cy + r * 0.12, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
|
| 113 |
+
ctx.fill()
|
| 114 |
+
// eye
|
| 115 |
+
ctx.strokeStyle = '#2a1d17'
|
| 116 |
+
ctx.lineWidth = Math.max(1, r * 0.07)
|
| 117 |
+
ctx.lineCap = 'round'
|
| 118 |
+
ctx.beginPath()
|
| 119 |
+
const ex = cx + facing * r * 0.5
|
| 120 |
+
const ey = cy + r * 0.02
|
| 121 |
+
if ((o.eyes ?? 'closed') === 'closed') {
|
| 122 |
+
ctx.arc(ex, ey - r * 0.05, r * 0.14, Math.PI * 0.15, Math.PI * 0.85)
|
| 123 |
+
} else {
|
| 124 |
+
ctx.moveTo(ex, ey)
|
| 125 |
+
ctx.arc(ex, ey, r * 0.06, 0, Math.PI * 2)
|
| 126 |
+
}
|
| 127 |
+
ctx.stroke()
|
| 128 |
+
// sad brow
|
| 129 |
+
ctx.beginPath()
|
| 130 |
+
ctx.moveTo(ex - facing * r * 0.16, ey - r * 0.2)
|
| 131 |
+
ctx.lineTo(ex + facing * r * 0.14, ey - r * 0.26)
|
| 132 |
+
ctx.stroke()
|
| 133 |
+
// mouth
|
| 134 |
+
ctx.beginPath()
|
| 135 |
+
if (o.smile) ctx.arc(cx + facing * r * 0.62, cy + r * 0.44, r * 0.1, 0.2, Math.PI - 0.2)
|
| 136 |
+
else {
|
| 137 |
+
ctx.moveTo(cx + facing * r * 0.56, cy + r * 0.5)
|
| 138 |
+
ctx.lineTo(cx + facing * r * 0.7, cy + r * 0.48)
|
| 139 |
+
}
|
| 140 |
+
ctx.stroke()
|
| 141 |
+
// blush
|
| 142 |
+
ctx.fillStyle = rgba(HERO.blush, 0.35)
|
| 143 |
+
ctx.beginPath()
|
| 144 |
+
ctx.ellipse(cx + facing * r * 0.4, cy + r * 0.3, r * 0.14, r * 0.08, 0, 0, Math.PI * 2)
|
| 145 |
+
ctx.fill()
|
| 146 |
+
curls(ctx, cx - facing * r * 0.05, cy - r * 0.12, r, facing, wind, t)
|
| 147 |
+
if (o.rim) {
|
| 148 |
+
ctx.strokeStyle = o.rim
|
| 149 |
+
ctx.lineWidth = Math.max(1, r * 0.08)
|
| 150 |
+
ctx.beginPath()
|
| 151 |
+
ctx.arc(cx - facing * r * 0.05, cy - r * 0.2, r * 1.18, facing > 0 ? Math.PI * 1.05 : -0.45, facing > 0 ? Math.PI * 1.45 : -0.05)
|
| 152 |
+
ctx.stroke()
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
// ------------------------------------------------------------------ walking
|
| 157 |
+
export interface HeroWalkOpts {
|
| 158 |
+
facing?: number
|
| 159 |
+
run?: number
|
| 160 |
+
rim?: string
|
| 161 |
+
t?: number
|
| 162 |
+
/** hand reaching forward (e.g. pushing the bike) */
|
| 163 |
+
reach?: number
|
| 164 |
+
eyes?: 'closed' | 'open'
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/** Side-view walking hero. (x,y) = feet on ground, h = total height. */
|
| 168 |
+
export function heroWalk(ctx: C2D, x: number, y: number, h: number, phase: number, o: HeroWalkOpts = {}) {
|
| 169 |
+
const f = o.facing ?? 1
|
| 170 |
+
const run = o.run ?? 0
|
| 171 |
+
const t = o.t ?? 0
|
| 172 |
+
const P = Math.PI * 2
|
| 173 |
+
const bob = Math.abs(Math.sin(phase * P * 2)) * h * (0.012 + run * 0.02)
|
| 174 |
+
const hipY = y - h * 0.4 - bob
|
| 175 |
+
const lean = 0.04 + run * 0.22
|
| 176 |
+
const shX = x + Math.sin(lean) * h * 0.24 * f
|
| 177 |
+
const shY = hipY - h * 0.25
|
| 178 |
+
const L1 = h * 0.2
|
| 179 |
+
const L2 = h * 0.19
|
| 180 |
+
ctx.lineCap = 'round'
|
| 181 |
+
ctx.lineJoin = 'round'
|
| 182 |
+
const leg = (ph: number, col: string, shoe: string) => {
|
| 183 |
+
const s = Math.sin(ph * P)
|
| 184 |
+
const th = s * (0.42 + run * 0.45)
|
| 185 |
+
const knee = Math.max(0, Math.cos(ph * P)) * (0.35 + run * 1.1) + 0.06
|
| 186 |
+
const kx = x + Math.sin(th) * L1 * f
|
| 187 |
+
const ky = hipY + Math.cos(th) * L1
|
| 188 |
+
const sa = th - knee
|
| 189 |
+
const fx = kx + Math.sin(sa) * L2 * f
|
| 190 |
+
const fy = ky + Math.cos(sa) * L2
|
| 191 |
+
ctx.strokeStyle = col
|
| 192 |
+
ctx.lineWidth = h * 0.085
|
| 193 |
+
ctx.beginPath()
|
| 194 |
+
ctx.moveTo(x, hipY)
|
| 195 |
+
ctx.lineTo(kx, ky)
|
| 196 |
+
ctx.lineTo(fx, fy)
|
| 197 |
+
ctx.stroke()
|
| 198 |
+
// sneaker
|
| 199 |
+
ctx.fillStyle = shoe
|
| 200 |
+
ctx.beginPath()
|
| 201 |
+
ctx.ellipse(fx + h * 0.03 * f, fy + h * 0.005, h * 0.055, h * 0.026, 0, 0, Math.PI * 2)
|
| 202 |
+
ctx.fill()
|
| 203 |
+
ctx.fillStyle = HERO.sole
|
| 204 |
+
ctx.fillRect(fx - h * 0.02, fy + h * 0.016, h * 0.1 * f, h * 0.012)
|
| 205 |
+
}
|
| 206 |
+
const arm = (ph: number, col: string, reach = 0) => {
|
| 207 |
+
const s = Math.sin(ph * P)
|
| 208 |
+
const a = reach > 0 ? 1.2 * reach : -s * (0.45 + run * 0.7)
|
| 209 |
+
const elbow = reach > 0 ? 0.25 : 0.25 + run * 1.2
|
| 210 |
+
const ex = shX + Math.sin(a) * h * 0.14 * f
|
| 211 |
+
const ey = shY + h * 0.02 + Math.cos(a) * h * 0.14
|
| 212 |
+
const hx = ex + Math.sin(a + elbow) * h * 0.13 * f
|
| 213 |
+
const hy = ey + Math.cos(a + elbow) * h * 0.13
|
| 214 |
+
ctx.strokeStyle = col
|
| 215 |
+
ctx.lineWidth = h * 0.07
|
| 216 |
+
ctx.beginPath()
|
| 217 |
+
ctx.moveTo(shX, shY + h * 0.02)
|
| 218 |
+
ctx.lineTo(ex, ey)
|
| 219 |
+
ctx.lineTo(hx, hy)
|
| 220 |
+
ctx.stroke()
|
| 221 |
+
ctx.fillStyle = HERO.skin
|
| 222 |
+
ctx.beginPath()
|
| 223 |
+
ctx.arc(hx, hy, h * 0.028, 0, Math.PI * 2)
|
| 224 |
+
ctx.fill()
|
| 225 |
+
}
|
| 226 |
+
leg(phase + 0.5, HERO.pantsShade, HERO.shoe)
|
| 227 |
+
arm(phase, HERO.sweaterShade)
|
| 228 |
+
// torso (sweater)
|
| 229 |
+
ctx.fillStyle = HERO.sweater
|
| 230 |
+
ctx.beginPath()
|
| 231 |
+
const tw = h * 0.085
|
| 232 |
+
ctx.moveTo(x - tw * f, hipY + h * 0.03)
|
| 233 |
+
ctx.quadraticCurveTo(x - tw * 1.25 * f, (hipY + shY) / 2, shX - tw * 1.3 * f, shY)
|
| 234 |
+
ctx.lineTo(shX + tw * 1.15 * f, shY + h * 0.01)
|
| 235 |
+
ctx.quadraticCurveTo(x + tw * 1.35 * f, (hipY + shY) / 2, x + tw * 1.0 * f, hipY + h * 0.035)
|
| 236 |
+
ctx.closePath()
|
| 237 |
+
ctx.fill()
|
| 238 |
+
// ribbed hem
|
| 239 |
+
ctx.fillStyle = HERO.rib
|
| 240 |
+
ctx.fillRect(Math.min(x - tw * f, x + tw * 1.05 * f), hipY + h * 0.005, tw * 2.05, h * 0.03)
|
| 241 |
+
// back shading
|
| 242 |
+
ctx.fillStyle = rgba(HERO.sweaterShade, 0.8)
|
| 243 |
+
ctx.beginPath()
|
| 244 |
+
ctx.moveTo(x - tw * f, hipY + h * 0.03)
|
| 245 |
+
ctx.quadraticCurveTo(x - tw * 1.2 * f, (hipY + shY) / 2, shX - tw * 1.05 * f, shY)
|
| 246 |
+
ctx.lineTo(shX - tw * 0.6 * f, shY)
|
| 247 |
+
ctx.quadraticCurveTo(x - tw * 0.7 * f, (hipY + shY) / 2, x - tw * 0.5 * f, hipY + h * 0.03)
|
| 248 |
+
ctx.closePath()
|
| 249 |
+
ctx.fill()
|
| 250 |
+
leg(phase, HERO.pants, HERO.shoe)
|
| 251 |
+
// head
|
| 252 |
+
const r = h * 0.13
|
| 253 |
+
heroHead(ctx, shX + h * 0.015 * f, shY - r * 1.05, r, f, { t, wind: run * 0.6 + 0.1, eyes: o.eyes ?? 'closed', rim: o.rim })
|
| 254 |
+
arm(phase + 0.5, HERO.sweater, o.reach ?? 0)
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
// ------------------------------------------------------------------ back view
|
| 258 |
+
export function heroBack(ctx: C2D, x: number, y: number, h: number, sway = 0, o: { rim?: string; t?: number; wind?: number } = {}) {
|
| 259 |
+
const sw = sway * h * 0.02
|
| 260 |
+
const t = o.t ?? 0
|
| 261 |
+
// legs
|
| 262 |
+
ctx.fillStyle = HERO.pantsShade
|
| 263 |
+
ctx.fillRect(x - h * 0.085, y - h * 0.4, h * 0.075, h * 0.4)
|
| 264 |
+
ctx.fillRect(x + h * 0.01, y - h * 0.4, h * 0.075, h * 0.4)
|
| 265 |
+
ctx.fillStyle = HERO.shoe
|
| 266 |
+
ctx.fillRect(x - h * 0.095, y - h * 0.03, h * 0.09, h * 0.03)
|
| 267 |
+
ctx.fillRect(x + h * 0.005, y - h * 0.03, h * 0.09, h * 0.03)
|
| 268 |
+
// sweater
|
| 269 |
+
ctx.fillStyle = HERO.sweater
|
| 270 |
+
ctx.beginPath()
|
| 271 |
+
ctx.moveTo(x - h * 0.14 + sw, y - h * 0.68)
|
| 272 |
+
ctx.quadraticCurveTo(x - h * 0.17, y - h * 0.52, x - h * 0.13, y - h * 0.36)
|
| 273 |
+
ctx.lineTo(x + h * 0.13, y - h * 0.36)
|
| 274 |
+
ctx.quadraticCurveTo(x + h * 0.17, y - h * 0.52, x + h * 0.14 + sw, y - h * 0.68)
|
| 275 |
+
ctx.closePath()
|
| 276 |
+
ctx.fill()
|
| 277 |
+
ctx.fillStyle = HERO.rib
|
| 278 |
+
ctx.fillRect(x - h * 0.13, y - h * 0.39, h * 0.26, h * 0.035)
|
| 279 |
+
// arms
|
| 280 |
+
ctx.fillStyle = HERO.sweaterShade
|
| 281 |
+
ctx.fillRect(x - h * 0.19 + sw, y - h * 0.66, h * 0.06, h * 0.3)
|
| 282 |
+
ctx.fillRect(x + h * 0.13 + sw, y - h * 0.66, h * 0.06, h * 0.3)
|
| 283 |
+
ctx.fillStyle = HERO.skin
|
| 284 |
+
ctx.fillRect(x - h * 0.185 + sw, y - h * 0.37, h * 0.05, h * 0.04)
|
| 285 |
+
ctx.fillRect(x + h * 0.135 + sw, y - h * 0.37, h * 0.05, h * 0.04)
|
| 286 |
+
// neck + head from behind: mostly hair
|
| 287 |
+
const r = h * 0.13
|
| 288 |
+
const hx = x + sw * 1.2
|
| 289 |
+
const hy = y - h * 0.68 - r * 0.95
|
| 290 |
+
ctx.fillStyle = HERO.skinShade
|
| 291 |
+
ctx.fillRect(hx - r * 0.25, hy + r * 0.6, r * 0.5, r * 0.5)
|
| 292 |
+
ctx.beginPath()
|
| 293 |
+
ctx.ellipse(hx - r * 0.95, hy + r * 0.15, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
|
| 294 |
+
ctx.ellipse(hx + r * 0.95, hy + r * 0.15, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
|
| 295 |
+
ctx.fill()
|
| 296 |
+
backCurls(ctx, hx, hy, r, o.wind ?? 0, t)
|
| 297 |
+
if (o.rim) {
|
| 298 |
+
ctx.strokeStyle = o.rim
|
| 299 |
+
ctx.lineWidth = Math.max(1, h * 0.008)
|
| 300 |
+
ctx.beginPath()
|
| 301 |
+
ctx.arc(hx, hy - r * 0.1, r * 1.22, Math.PI * 1.1, Math.PI * 1.9)
|
| 302 |
+
ctx.moveTo(x - h * 0.15, y - h * 0.66)
|
| 303 |
+
ctx.lineTo(x - h * 0.17, y - h * 0.5)
|
| 304 |
+
ctx.moveTo(x + h * 0.15, y - h * 0.66)
|
| 305 |
+
ctx.lineTo(x + h * 0.17, y - h * 0.5)
|
| 306 |
+
ctx.stroke()
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
function backCurls(ctx: C2D, hx: number, hy: number, r: number, wind: number, t: number) {
|
| 311 |
+
const pts: { x: number; y: number; r: number }[] = []
|
| 312 |
+
for (let i = 0; i < 28; i++) {
|
| 313 |
+
const a = (i / 28) * Math.PI * 2
|
| 314 |
+
if (Math.sin(a) > 0.8) continue // keep the nape a little open
|
| 315 |
+
const wob = Math.sin(t * 8 + i) * wind * 0.06
|
| 316 |
+
pts.push({
|
| 317 |
+
x: hx + Math.cos(a) * r * (1.02 + 0.14 * hash(i)) + wob * r,
|
| 318 |
+
y: hy - r * 0.05 + Math.sin(a) * r * 0.96 - wind * r * 0.18 * (1 - Math.sin(a)),
|
| 319 |
+
r: r * (0.34 + 0.16 * hash(i * 2.3)),
|
| 320 |
+
})
|
| 321 |
+
}
|
| 322 |
+
for (let i = 0; i < 9; i++) {
|
| 323 |
+
const a = (i / 9) * Math.PI * 2
|
| 324 |
+
pts.push({ x: hx + Math.cos(a) * r * 0.5, y: hy - r * 0.1 + Math.sin(a) * r * 0.5, r: r * 0.32 })
|
| 325 |
+
}
|
| 326 |
+
ctx.fillStyle = HERO.hair
|
| 327 |
+
ctx.beginPath()
|
| 328 |
+
ctx.moveTo(hx + r, hy)
|
| 329 |
+
ctx.ellipse(hx, hy - r * 0.05, r * 1.0, r * 0.95, 0, 0, Math.PI * 2)
|
| 330 |
+
for (const p of pts) {
|
| 331 |
+
ctx.moveTo(p.x + p.r, p.y)
|
| 332 |
+
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
|
| 333 |
+
}
|
| 334 |
+
ctx.fill()
|
| 335 |
+
ctx.strokeStyle = HERO.hairHi
|
| 336 |
+
ctx.lineWidth = Math.max(1, r * 0.075)
|
| 337 |
+
ctx.lineCap = 'round'
|
| 338 |
+
ctx.beginPath()
|
| 339 |
+
for (const p of pts) {
|
| 340 |
+
const rr = p.r * 0.62
|
| 341 |
+
ctx.moveTo(p.x + rr * Math.cos(-2.6), p.y + rr * Math.sin(-2.6))
|
| 342 |
+
ctx.arc(p.x, p.y, rr, -2.6, -0.5)
|
| 343 |
+
}
|
| 344 |
+
ctx.stroke()
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
// ------------------------------------------------------------------ the motorcycle
|
| 348 |
+
export interface BikeOpts {
|
| 349 |
+
facing?: number
|
| 350 |
+
light?: number
|
| 351 |
+
spin?: number
|
| 352 |
+
t?: number
|
| 353 |
+
beam?: boolean
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
/** Side-view black classic motorcycle. (x,y) = ground point under the middle, s = scale (≈ wheelbase). */
|
| 357 |
+
export function bike(ctx: C2D, x: number, y: number, s: number, o: BikeOpts = {}) {
|
| 358 |
+
const f = o.facing ?? 1
|
| 359 |
+
ctx.save()
|
| 360 |
+
ctx.translate(x, y)
|
| 361 |
+
ctx.scale(f, 1)
|
| 362 |
+
bikeLocal(ctx, s, o)
|
| 363 |
+
ctx.restore()
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
/** bike drawn at origin facing +x (ground at y=0) */
|
| 367 |
+
function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
|
| 368 |
+
const R = s * 0.22
|
| 369 |
+
const rx = -s * 0.5
|
| 370 |
+
const fx = s * 0.5
|
| 371 |
+
const wy = -R
|
| 372 |
+
const light = o.light ?? 1
|
| 373 |
+
const X = (dx: number) => dx * s
|
| 374 |
+
const Y = (dy: number) => -dy * s
|
| 375 |
+
if (o.beam && light > 0) lightCone(ctx, X(0.58), Y(0.6), s * 3, 0.16, -Math.PI / 2, '#fff1c8', 0.16 * light)
|
| 376 |
+
for (const cx of [rx, fx]) {
|
| 377 |
+
ctx.fillStyle = HERO.tire
|
| 378 |
+
ctx.beginPath()
|
| 379 |
+
ctx.arc(cx, wy, R, 0, Math.PI * 2)
|
| 380 |
+
ctx.fill()
|
| 381 |
+
ctx.fillStyle = '#1c1f24'
|
| 382 |
+
ctx.beginPath()
|
| 383 |
+
ctx.arc(cx, wy, R * 0.62, 0, Math.PI * 2)
|
| 384 |
+
ctx.fill()
|
| 385 |
+
// tyre tread highlight
|
| 386 |
+
ctx.strokeStyle = 'rgba(120,130,145,0.35)'
|
| 387 |
+
ctx.lineWidth = Math.max(1, s * 0.006)
|
| 388 |
+
ctx.beginPath()
|
| 389 |
+
ctx.arc(cx, wy, R * 0.94, Math.PI * 1.1, Math.PI * 1.6)
|
| 390 |
+
ctx.stroke()
|
| 391 |
+
ctx.strokeStyle = rgba(HERO.chrome, 0.8)
|
| 392 |
+
ctx.lineWidth = Math.max(1, s * 0.006)
|
| 393 |
+
ctx.beginPath()
|
| 394 |
+
ctx.arc(cx, wy, R * 0.6, 0, Math.PI * 2)
|
| 395 |
+
const sp = o.spin ?? 0
|
| 396 |
+
for (let k = 0; k < 12; k++) {
|
| 397 |
+
const a = (k / 12) * Math.PI * 2 + sp
|
| 398 |
+
ctx.moveTo(cx + Math.cos(a) * R * 0.12, wy + Math.sin(a) * R * 0.12)
|
| 399 |
+
ctx.lineTo(cx + Math.cos(a + 0.3) * R * 0.6, wy + Math.sin(a + 0.3) * R * 0.6)
|
| 400 |
+
}
|
| 401 |
+
ctx.stroke()
|
| 402 |
+
ctx.fillStyle = HERO.chrome
|
| 403 |
+
ctx.beginPath()
|
| 404 |
+
ctx.arc(cx, wy, R * 0.12, 0, Math.PI * 2)
|
| 405 |
+
ctx.fill()
|
| 406 |
+
}
|
| 407 |
+
ctx.lineCap = 'round'
|
| 408 |
+
ctx.lineJoin = 'round'
|
| 409 |
+
// frame
|
| 410 |
+
ctx.strokeStyle = HERO.bike
|
| 411 |
+
ctx.lineWidth = s * 0.05
|
| 412 |
+
ctx.beginPath()
|
| 413 |
+
ctx.moveTo(rx, wy)
|
| 414 |
+
ctx.lineTo(X(-0.1), Y(0.28))
|
| 415 |
+
ctx.lineTo(X(0.32), Y(0.52))
|
| 416 |
+
ctx.moveTo(rx, wy)
|
| 417 |
+
ctx.lineTo(X(-0.28), Y(0.5))
|
| 418 |
+
ctx.stroke()
|
| 419 |
+
// front fork
|
| 420 |
+
ctx.strokeStyle = HERO.chrome
|
| 421 |
+
ctx.lineWidth = s * 0.034
|
| 422 |
+
ctx.beginPath()
|
| 423 |
+
ctx.moveTo(fx, wy)
|
| 424 |
+
ctx.lineTo(X(0.36), Y(0.66))
|
| 425 |
+
ctx.stroke()
|
| 426 |
+
// fenders
|
| 427 |
+
ctx.strokeStyle = HERO.bike
|
| 428 |
+
ctx.lineWidth = s * 0.05
|
| 429 |
+
ctx.beginPath()
|
| 430 |
+
ctx.arc(fx, wy, R * 1.12, Math.PI * 1.05, Math.PI * 1.75)
|
| 431 |
+
ctx.stroke()
|
| 432 |
+
ctx.beginPath()
|
| 433 |
+
ctx.arc(rx, wy, R * 1.12, Math.PI * 1.2, Math.PI * 1.9)
|
| 434 |
+
ctx.stroke()
|
| 435 |
+
// engine block (big, chunky) + side cover under the seat
|
| 436 |
+
ctx.fillStyle = '#16181d'
|
| 437 |
+
ctx.beginPath()
|
| 438 |
+
ctx.moveTo(X(-0.16), Y(0.46))
|
| 439 |
+
ctx.lineTo(X(0.22), Y(0.48))
|
| 440 |
+
ctx.lineTo(X(0.24), Y(0.2))
|
| 441 |
+
ctx.lineTo(X(-0.12), Y(0.17))
|
| 442 |
+
ctx.closePath()
|
| 443 |
+
ctx.fill()
|
| 444 |
+
ctx.fillStyle = HERO.bike
|
| 445 |
+
ctx.fillRect(X(-0.36), Y(0.47), s * 0.2, s * 0.14)
|
| 446 |
+
ctx.fillStyle = '#2a2f38'
|
| 447 |
+
ctx.beginPath()
|
| 448 |
+
ctx.arc(X(0.03), Y(0.27), s * 0.07, 0, Math.PI * 2)
|
| 449 |
+
ctx.fill()
|
| 450 |
+
ctx.strokeStyle = HERO.chrome
|
| 451 |
+
ctx.lineWidth = Math.max(1, s * 0.01)
|
| 452 |
+
ctx.beginPath()
|
| 453 |
+
ctx.arc(X(0.03), Y(0.27), s * 0.07, 0, Math.PI * 2)
|
| 454 |
+
ctx.stroke()
|
| 455 |
+
ctx.strokeStyle = rgba(HERO.chrome, 0.7)
|
| 456 |
+
ctx.lineWidth = Math.max(1, s * 0.008)
|
| 457 |
+
ctx.beginPath()
|
| 458 |
+
for (let k = 0; k < 5; k++) {
|
| 459 |
+
ctx.moveTo(X(-0.1), Y(0.4 - k * 0.035))
|
| 460 |
+
ctx.lineTo(X(0.16), Y(0.4 - k * 0.035))
|
| 461 |
+
}
|
| 462 |
+
ctx.stroke()
|
| 463 |
+
// exhaust
|
| 464 |
+
ctx.strokeStyle = HERO.chrome
|
| 465 |
+
ctx.lineWidth = s * 0.045
|
| 466 |
+
ctx.beginPath()
|
| 467 |
+
ctx.moveTo(X(0.1), Y(0.24))
|
| 468 |
+
ctx.quadraticCurveTo(X(-0.05), Y(0.13), X(-0.62), Y(0.2))
|
| 469 |
+
ctx.stroke()
|
| 470 |
+
// tank (teardrop)
|
| 471 |
+
ctx.fillStyle = HERO.bike
|
| 472 |
+
ctx.beginPath()
|
| 473 |
+
ctx.moveTo(X(-0.1), Y(0.5))
|
| 474 |
+
ctx.quadraticCurveTo(X(0.0), Y(0.71), X(0.22), Y(0.68))
|
| 475 |
+
ctx.quadraticCurveTo(X(0.4), Y(0.62), X(0.34), Y(0.48))
|
| 476 |
+
ctx.quadraticCurveTo(X(0.12), Y(0.42), X(-0.1), Y(0.5))
|
| 477 |
+
ctx.fill()
|
| 478 |
+
ctx.strokeStyle = HERO.bikeHi
|
| 479 |
+
ctx.lineWidth = Math.max(1, s * 0.012)
|
| 480 |
+
ctx.beginPath()
|
| 481 |
+
ctx.moveTo(X(0.0), Y(0.58))
|
| 482 |
+
ctx.quadraticCurveTo(X(0.12), Y(0.635), X(0.24), Y(0.6))
|
| 483 |
+
ctx.stroke()
|
| 484 |
+
// seat
|
| 485 |
+
ctx.fillStyle = HERO.seat
|
| 486 |
+
ctx.beginPath()
|
| 487 |
+
ctx.moveTo(X(-0.44), Y(0.5))
|
| 488 |
+
ctx.quadraticCurveTo(X(-0.3), Y(0.56), X(-0.06), Y(0.53))
|
| 489 |
+
ctx.lineTo(X(-0.06), Y(0.48))
|
| 490 |
+
ctx.lineTo(X(-0.44), Y(0.46))
|
| 491 |
+
ctx.closePath()
|
| 492 |
+
ctx.fill()
|
| 493 |
+
// rear fender & tail light
|
| 494 |
+
ctx.fillStyle = HERO.bike
|
| 495 |
+
ctx.beginPath()
|
| 496 |
+
ctx.moveTo(X(-0.44), Y(0.47))
|
| 497 |
+
ctx.lineTo(X(-0.66), Y(0.44))
|
| 498 |
+
ctx.lineTo(X(-0.64), Y(0.4))
|
| 499 |
+
ctx.lineTo(X(-0.42), Y(0.42))
|
| 500 |
+
ctx.closePath()
|
| 501 |
+
ctx.fill()
|
| 502 |
+
ctx.fillStyle = '#ff3a5c'
|
| 503 |
+
ctx.fillRect(X(-0.68), Y(0.455), s * 0.04, s * 0.03)
|
| 504 |
+
glowBlob(ctx, X(-0.66), Y(0.44), s * 0.12, '#ff2d55', 0.8 * light)
|
| 505 |
+
// handlebar, mirrors
|
| 506 |
+
ctx.strokeStyle = HERO.chrome
|
| 507 |
+
ctx.lineWidth = s * 0.016
|
| 508 |
+
ctx.beginPath()
|
| 509 |
+
ctx.moveTo(X(0.36), Y(0.66))
|
| 510 |
+
ctx.lineTo(X(0.3), Y(0.74))
|
| 511 |
+
ctx.lineTo(X(0.22), Y(0.75))
|
| 512 |
+
ctx.moveTo(X(0.33), Y(0.7))
|
| 513 |
+
ctx.lineTo(X(0.3), Y(0.86))
|
| 514 |
+
ctx.stroke()
|
| 515 |
+
ctx.fillStyle = HERO.chrome
|
| 516 |
+
ctx.beginPath()
|
| 517 |
+
ctx.ellipse(X(0.3), Y(0.89), s * 0.035, s * 0.028, 0, 0, Math.PI * 2)
|
| 518 |
+
ctx.fill()
|
| 519 |
+
ctx.fillStyle = '#5a6a7a'
|
| 520 |
+
ctx.beginPath()
|
| 521 |
+
ctx.ellipse(X(0.3), Y(0.89), s * 0.024, s * 0.018, 0, 0, Math.PI * 2)
|
| 522 |
+
ctx.fill()
|
| 523 |
+
// round headlight
|
| 524 |
+
ctx.fillStyle = HERO.chrome
|
| 525 |
+
ctx.beginPath()
|
| 526 |
+
ctx.arc(X(0.44), Y(0.62), s * 0.065, 0, Math.PI * 2)
|
| 527 |
+
ctx.fill()
|
| 528 |
+
ctx.fillStyle = light > 0.1 ? '#fff6d8' : '#59606a'
|
| 529 |
+
ctx.beginPath()
|
| 530 |
+
ctx.arc(X(0.455), Y(0.62), s * 0.05, 0, Math.PI * 2)
|
| 531 |
+
ctx.fill()
|
| 532 |
+
if (light > 0.1) glowBlob(ctx, X(0.47), Y(0.62), s * 0.22, '#fff1c8', 0.9 * light)
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
// ------------------------------------------------------------------ riding (side)
|
| 536 |
+
export interface RideOpts {
|
| 537 |
+
facing?: number
|
| 538 |
+
wind?: number
|
| 539 |
+
t?: number
|
| 540 |
+
spin?: number
|
| 541 |
+
light?: number
|
| 542 |
+
beam?: boolean
|
| 543 |
+
smile?: boolean
|
| 544 |
+
eyes?: 'closed' | 'open'
|
| 545 |
+
rim?: string
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
/** Hero riding the bike, side view. (x,y) = ground under bike centre, s = bike scale. */
|
| 549 |
+
export function heroRide(ctx: C2D, x: number, y: number, s: number, o: RideOpts = {}) {
|
| 550 |
+
ctx.save()
|
| 551 |
+
ctx.translate(x, y)
|
| 552 |
+
ctx.scale(o.facing ?? 1, 1)
|
| 553 |
+
rideLocal(ctx, s, o)
|
| 554 |
+
ctx.restore()
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
function rideLocal(ctx: C2D, s: number, o: RideOpts) {
|
| 558 |
+
const f = 1
|
| 559 |
+
const t = o.t ?? 0
|
| 560 |
+
const x = 0
|
| 561 |
+
const y = 0
|
| 562 |
+
const X = (dx: number) => dx * s
|
| 563 |
+
const Y = (dy: number) => -dy * s
|
| 564 |
+
const bounce = Math.sin(t * 13) * s * 0.004
|
| 565 |
+
// far arm & leg (shade)
|
| 566 |
+
ctx.lineCap = 'round'
|
| 567 |
+
ctx.lineJoin = 'round'
|
| 568 |
+
ctx.strokeStyle = HERO.pantsShade
|
| 569 |
+
ctx.lineWidth = s * 0.075
|
| 570 |
+
ctx.beginPath()
|
| 571 |
+
ctx.moveTo(X(-0.24), Y(0.55))
|
| 572 |
+
ctx.lineTo(X(0.04), Y(0.56))
|
| 573 |
+
ctx.lineTo(X(-0.02), Y(0.3))
|
| 574 |
+
ctx.stroke()
|
| 575 |
+
bikeLocal(ctx, s, { light: o.light, spin: o.spin, beam: o.beam })
|
| 576 |
+
// near leg
|
| 577 |
+
ctx.strokeStyle = HERO.pants
|
| 578 |
+
ctx.lineWidth = s * 0.08
|
| 579 |
+
ctx.beginPath()
|
| 580 |
+
ctx.moveTo(X(-0.26), Y(0.56) + bounce)
|
| 581 |
+
ctx.lineTo(X(0.06), Y(0.58) + bounce)
|
| 582 |
+
ctx.lineTo(X(0.0), Y(0.3))
|
| 583 |
+
ctx.stroke()
|
| 584 |
+
ctx.fillStyle = HERO.shoe
|
| 585 |
+
ctx.beginPath()
|
| 586 |
+
ctx.ellipse(X(0.03), Y(0.28), s * 0.055, s * 0.026, 0, 0, Math.PI * 2)
|
| 587 |
+
ctx.fill()
|
| 588 |
+
// torso leaning forward
|
| 589 |
+
const hip = { x: X(-0.24), y: Y(0.6) + bounce }
|
| 590 |
+
const sh = { x: X(-0.06), y: Y(0.9) + bounce }
|
| 591 |
+
ctx.fillStyle = HERO.sweater
|
| 592 |
+
ctx.beginPath()
|
| 593 |
+
ctx.moveTo(hip.x - s * 0.08 * f, hip.y + s * 0.03)
|
| 594 |
+
ctx.quadraticCurveTo(hip.x - s * 0.12 * f, (hip.y + sh.y) / 2, sh.x - s * 0.08 * f, sh.y)
|
| 595 |
+
ctx.lineTo(sh.x + s * 0.08 * f, sh.y + s * 0.02)
|
| 596 |
+
ctx.quadraticCurveTo(hip.x + s * 0.14 * f, (hip.y + sh.y) / 2 + s * 0.05, hip.x + s * 0.1 * f, hip.y + s * 0.03)
|
| 597 |
+
ctx.closePath()
|
| 598 |
+
ctx.fill()
|
| 599 |
+
ctx.fillStyle = HERO.rib
|
| 600 |
+
ctx.beginPath()
|
| 601 |
+
ctx.moveTo(hip.x - s * 0.08 * f, hip.y + s * 0.03)
|
| 602 |
+
ctx.lineTo(hip.x + s * 0.1 * f, hip.y + s * 0.03)
|
| 603 |
+
ctx.lineTo(hip.x + s * 0.1 * f, hip.y - s * 0.0)
|
| 604 |
+
ctx.lineTo(hip.x - s * 0.085 * f, hip.y - s * 0.0)
|
| 605 |
+
ctx.closePath()
|
| 606 |
+
ctx.fill()
|
| 607 |
+
// head
|
| 608 |
+
const r = s * 0.13
|
| 609 |
+
heroHead(ctx, sh.x + s * 0.05 * f, sh.y - r * 1.05, r, f, { t, wind: o.wind ?? 0.6, smile: o.smile, eyes: o.eyes ?? 'open', rim: o.rim })
|
| 610 |
+
// near arm to handlebar
|
| 611 |
+
ctx.strokeStyle = HERO.sweater
|
| 612 |
+
ctx.lineWidth = s * 0.065
|
| 613 |
+
ctx.beginPath()
|
| 614 |
+
ctx.moveTo(sh.x, sh.y + s * 0.03)
|
| 615 |
+
ctx.lineTo(X(0.1), Y(0.76) + bounce)
|
| 616 |
+
ctx.lineTo(X(0.24), Y(0.75))
|
| 617 |
+
ctx.stroke()
|
| 618 |
+
ctx.fillStyle = HERO.skin
|
| 619 |
+
ctx.beginPath()
|
| 620 |
+
ctx.arc(X(0.25), Y(0.75), s * 0.028, 0, Math.PI * 2)
|
| 621 |
+
ctx.fill()
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
// ------------------------------------------------------------------ riding (rear view)
|
| 625 |
+
export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: number, t: number, wind = 0.8) {
|
| 626 |
+
ctx.save()
|
| 627 |
+
ctx.translate(x, y)
|
| 628 |
+
ctx.rotate(lean)
|
| 629 |
+
// tire
|
| 630 |
+
ctx.fillStyle = HERO.tire
|
| 631 |
+
ctx.beginPath()
|
| 632 |
+
ctx.ellipse(0, -s * 0.09, s * 0.07, s * 0.17, 0, 0, Math.PI * 2)
|
| 633 |
+
ctx.fill()
|
| 634 |
+
// fender + tail
|
| 635 |
+
ctx.fillStyle = HERO.bike
|
| 636 |
+
ctx.beginPath()
|
| 637 |
+
ctx.moveTo(-s * 0.1, -s * 0.24)
|
| 638 |
+
ctx.lineTo(s * 0.1, -s * 0.24)
|
| 639 |
+
ctx.lineTo(s * 0.08, -s * 0.36)
|
| 640 |
+
ctx.lineTo(-s * 0.08, -s * 0.36)
|
| 641 |
+
ctx.closePath()
|
| 642 |
+
ctx.fill()
|
| 643 |
+
glowBlob(ctx, 0, -s * 0.3, s * 0.14, '#ff2d55', 0.95)
|
| 644 |
+
ctx.fillStyle = '#ff6a80'
|
| 645 |
+
ctx.fillRect(-s * 0.055, -s * 0.31, s * 0.11, s * 0.03)
|
| 646 |
+
ctx.fillStyle = '#e6e2d8'
|
| 647 |
+
ctx.fillRect(-s * 0.05, -s * 0.27, s * 0.1, s * 0.035)
|
| 648 |
+
// legs to pegs
|
| 649 |
+
ctx.fillStyle = HERO.pantsShade
|
| 650 |
+
ctx.beginPath()
|
| 651 |
+
ctx.moveTo(-s * 0.16, -s * 0.42)
|
| 652 |
+
ctx.lineTo(-s * 0.22, -s * 0.2)
|
| 653 |
+
ctx.lineTo(-s * 0.15, -s * 0.18)
|
| 654 |
+
ctx.lineTo(-s * 0.08, -s * 0.38)
|
| 655 |
+
ctx.moveTo(s * 0.16, -s * 0.42)
|
| 656 |
+
ctx.lineTo(s * 0.22, -s * 0.2)
|
| 657 |
+
ctx.lineTo(s * 0.15, -s * 0.18)
|
| 658 |
+
ctx.lineTo(s * 0.08, -s * 0.38)
|
| 659 |
+
ctx.fill()
|
| 660 |
+
// seat
|
| 661 |
+
ctx.fillStyle = HERO.seat
|
| 662 |
+
ctx.fillRect(-s * 0.12, -s * 0.42, s * 0.24, s * 0.06)
|
| 663 |
+
// sweater torso
|
| 664 |
+
ctx.fillStyle = HERO.sweater
|
| 665 |
+
ctx.beginPath()
|
| 666 |
+
ctx.moveTo(-s * 0.19, -s * 0.44)
|
| 667 |
+
ctx.quadraticCurveTo(-s * 0.23, -s * 0.66, -s * 0.12, -s * 0.78)
|
| 668 |
+
ctx.lineTo(s * 0.12, -s * 0.78)
|
| 669 |
+
ctx.quadraticCurveTo(s * 0.23, -s * 0.66, s * 0.19, -s * 0.44)
|
| 670 |
+
ctx.closePath()
|
| 671 |
+
ctx.fill()
|
| 672 |
+
ctx.fillStyle = HERO.rib
|
| 673 |
+
ctx.fillRect(-s * 0.19, -s * 0.47, s * 0.38, s * 0.035)
|
| 674 |
+
ctx.fillStyle = rgba(HERO.sweaterShade, 0.8)
|
| 675 |
+
ctx.fillRect(-s * 0.02, -s * 0.76, s * 0.04, s * 0.3)
|
| 676 |
+
// arms out to bars
|
| 677 |
+
ctx.strokeStyle = HERO.sweaterShade
|
| 678 |
+
ctx.lineCap = 'round'
|
| 679 |
+
ctx.lineWidth = s * 0.055
|
| 680 |
+
ctx.beginPath()
|
| 681 |
+
ctx.moveTo(-s * 0.16, -s * 0.72)
|
| 682 |
+
ctx.lineTo(-s * 0.3, -s * 0.55)
|
| 683 |
+
ctx.moveTo(s * 0.16, -s * 0.72)
|
| 684 |
+
ctx.lineTo(s * 0.3, -s * 0.55)
|
| 685 |
+
ctx.stroke()
|
| 686 |
+
ctx.strokeStyle = HERO.chrome
|
| 687 |
+
ctx.lineWidth = s * 0.014
|
| 688 |
+
ctx.beginPath()
|
| 689 |
+
ctx.moveTo(-s * 0.34, -s * 0.56)
|
| 690 |
+
ctx.lineTo(s * 0.34, -s * 0.56)
|
| 691 |
+
ctx.moveTo(-s * 0.3, -s * 0.56)
|
| 692 |
+
ctx.lineTo(-s * 0.33, -s * 0.66)
|
| 693 |
+
ctx.moveTo(s * 0.3, -s * 0.56)
|
| 694 |
+
ctx.lineTo(s * 0.33, -s * 0.66)
|
| 695 |
+
ctx.stroke()
|
| 696 |
+
ctx.fillStyle = HERO.chrome
|
| 697 |
+
ctx.beginPath()
|
| 698 |
+
ctx.ellipse(-s * 0.335, -s * 0.68, s * 0.03, s * 0.024, 0, 0, Math.PI * 2)
|
| 699 |
+
ctx.ellipse(s * 0.335, -s * 0.68, s * 0.03, s * 0.024, 0, 0, Math.PI * 2)
|
| 700 |
+
ctx.fill()
|
| 701 |
+
// neck + hair mop (blown by the wind)
|
| 702 |
+
const r = s * 0.11
|
| 703 |
+
ctx.fillStyle = HERO.skinShade
|
| 704 |
+
ctx.fillRect(-r * 0.25, -s * 0.84, r * 0.5, s * 0.07)
|
| 705 |
+
backCurls(ctx, 0, -s * 0.84 - r * 0.8, r, wind, t)
|
| 706 |
+
ctx.restore()
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
// ------------------------------------------------------------------ sitting with the letter
|
| 710 |
+
export function heroSit(ctx: C2D, x: number, y: number, h: number, t: number, o: { facing?: number; letter?: number; fire?: number } = {}) {
|
| 711 |
+
const f = o.facing ?? 1
|
| 712 |
+
const X = (dx: number) => x + dx * h * f
|
| 713 |
+
const Y = (dy: number) => y - dy * h
|
| 714 |
+
ctx.lineCap = 'round'
|
| 715 |
+
ctx.lineJoin = 'round'
|
| 716 |
+
// legs: knees up
|
| 717 |
+
ctx.strokeStyle = HERO.pantsShade
|
| 718 |
+
ctx.lineWidth = h * 0.11
|
| 719 |
+
ctx.beginPath()
|
| 720 |
+
ctx.moveTo(X(-0.05), Y(0.05))
|
| 721 |
+
ctx.lineTo(X(0.2), Y(0.3))
|
| 722 |
+
ctx.lineTo(X(0.3), Y(0.04))
|
| 723 |
+
ctx.stroke()
|
| 724 |
+
ctx.strokeStyle = HERO.pants
|
| 725 |
+
ctx.beginPath()
|
| 726 |
+
ctx.moveTo(X(-0.02), Y(0.06))
|
| 727 |
+
ctx.lineTo(X(0.24), Y(0.32))
|
| 728 |
+
ctx.lineTo(X(0.36), Y(0.05))
|
| 729 |
+
ctx.stroke()
|
| 730 |
+
ctx.fillStyle = HERO.shoe
|
| 731 |
+
ctx.beginPath()
|
| 732 |
+
ctx.ellipse(X(0.4), Y(0.03), h * 0.07, h * 0.035, 0, 0, Math.PI * 2)
|
| 733 |
+
ctx.fill()
|
| 734 |
+
// torso hunched
|
| 735 |
+
ctx.fillStyle = HERO.sweater
|
| 736 |
+
ctx.beginPath()
|
| 737 |
+
ctx.moveTo(X(-0.14), Y(0.04))
|
| 738 |
+
ctx.quadraticCurveTo(X(-0.2), Y(0.3), X(-0.06), Y(0.5))
|
| 739 |
+
ctx.lineTo(X(0.1), Y(0.48))
|
| 740 |
+
ctx.quadraticCurveTo(X(0.08), Y(0.25), X(0.06), Y(0.06))
|
| 741 |
+
ctx.closePath()
|
| 742 |
+
ctx.fill()
|
| 743 |
+
// head bowed toward the letter
|
| 744 |
+
const r = h * 0.15
|
| 745 |
+
heroHead(ctx, X(0.06), Y(0.62), r, f, { t, eyes: 'closed', wind: 0.05 })
|
| 746 |
+
// arms holding paper
|
| 747 |
+
const px = X(0.34)
|
| 748 |
+
const py = Y(0.42)
|
| 749 |
+
ctx.strokeStyle = HERO.sweater
|
| 750 |
+
ctx.lineWidth = h * 0.075
|
| 751 |
+
ctx.beginPath()
|
| 752 |
+
ctx.moveTo(X(0.0), Y(0.45))
|
| 753 |
+
ctx.lineTo(X(0.18), Y(0.33))
|
| 754 |
+
ctx.lineTo(px - h * 0.03 * f, py + h * 0.03)
|
| 755 |
+
ctx.stroke()
|
| 756 |
+
const letter = o.letter ?? 1
|
| 757 |
+
if (letter > 0) {
|
| 758 |
+
ctx.save()
|
| 759 |
+
ctx.translate(px, py)
|
| 760 |
+
ctx.rotate(-0.25 * f)
|
| 761 |
+
ctx.globalAlpha = letter
|
| 762 |
+
ctx.fillStyle = '#f1e6cf'
|
| 763 |
+
const lw = h * 0.16
|
| 764 |
+
const lh = h * 0.2 * letter
|
| 765 |
+
ctx.fillRect(-lw / 2, -lh, lw, lh)
|
| 766 |
+
ctx.fillStyle = 'rgba(80,60,40,0.45)'
|
| 767 |
+
for (let k = 0; k < 5; k++) ctx.fillRect(-lw * 0.38, -lh + lh * (0.18 + k * 0.15), lw * 0.76 * (k === 4 ? 0.5 : 1), Math.max(1, h * 0.006))
|
| 768 |
+
ctx.restore()
|
| 769 |
+
}
|
| 770 |
+
ctx.fillStyle = HERO.skin
|
| 771 |
+
ctx.beginPath()
|
| 772 |
+
ctx.arc(px - h * 0.02 * f, py + h * 0.02, h * 0.03, 0, Math.PI * 2)
|
| 773 |
+
ctx.fill()
|
| 774 |
+
const fire = o.fire ?? 0
|
| 775 |
+
if (fire > 0) flame(ctx, px, py - h * 0.2 * letter, h * 0.18 * fire, t)
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
export function flame(ctx: C2D, x: number, y: number, size: number, t: number) {
|
| 779 |
+
glowBlob(ctx, x, y - size * 0.3, size * 3.2, '#ff8a3d', 0.55)
|
| 780 |
+
const layers: [string, number][] = [
|
| 781 |
+
['#ff4a1c', 1],
|
| 782 |
+
['#ff9a2e', 0.72],
|
| 783 |
+
['#ffe08a', 0.42],
|
| 784 |
+
]
|
| 785 |
+
for (const [c, k] of layers) {
|
| 786 |
+
ctx.fillStyle = c
|
| 787 |
+
ctx.beginPath()
|
| 788 |
+
const w = size * 0.45 * k
|
| 789 |
+
const hh = size * 1.3 * k * (0.9 + 0.15 * Math.sin(t * 17 + k * 5))
|
| 790 |
+
const sway = Math.sin(t * 11 + k * 3) * size * 0.12
|
| 791 |
+
ctx.moveTo(x - w, y)
|
| 792 |
+
ctx.quadraticCurveTo(x - w * 1.1, y - hh * 0.5, x + sway, y - hh)
|
| 793 |
+
ctx.quadraticCurveTo(x + w * 1.1, y - hh * 0.5, x + w, y)
|
| 794 |
+
ctx.quadraticCurveTo(x, y + w * 0.6, x - w, y)
|
| 795 |
+
ctx.fill()
|
| 796 |
+
}
|
| 797 |
+
// embers
|
| 798 |
+
ctx.fillStyle = '#ffcf7a'
|
| 799 |
+
for (let i = 0; i < 10; i++) {
|
| 800 |
+
const life = (t * (0.6 + hash(i) * 0.5) + hash(i * 3.3)) % 1
|
| 801 |
+
ctx.globalAlpha = 1 - life
|
| 802 |
+
ctx.fillRect(x + Math.sin(i * 2.1 + t * 3) * size * 0.6 * life, y - size * (0.6 + life * 2.4), Math.max(1, size * 0.05), Math.max(1, size * 0.05))
|
| 803 |
+
}
|
| 804 |
+
ctx.globalAlpha = 1
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
// ------------------------------------------------------------------ front portrait
|
| 808 |
+
export interface PortraitOpts {
|
| 809 |
+
t: number
|
| 810 |
+
eyes?: number // 0 closed .. 1 open
|
| 811 |
+
tear?: number
|
| 812 |
+
wind?: number
|
| 813 |
+
rim?: string
|
| 814 |
+
smile?: boolean
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
/** Front-facing bust. (cx,cy) = face centre, size = face radius. */
|
| 818 |
+
export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o: PortraitOpts) {
|
| 819 |
+
const r = size
|
| 820 |
+
const t = o.t
|
| 821 |
+
// shoulders / sweater
|
| 822 |
+
ctx.fillStyle = HERO.sweater
|
| 823 |
+
ctx.beginPath()
|
| 824 |
+
ctx.moveTo(cx - r * 2.4, cy + r * 3.2)
|
| 825 |
+
ctx.quadraticCurveTo(cx - r * 2.2, cy + r * 1.45, cx - r * 0.5, cy + r * 1.3)
|
| 826 |
+
ctx.lineTo(cx + r * 0.5, cy + r * 1.3)
|
| 827 |
+
ctx.quadraticCurveTo(cx + r * 2.2, cy + r * 1.45, cx + r * 2.4, cy + r * 3.2)
|
| 828 |
+
ctx.closePath()
|
| 829 |
+
ctx.fill()
|
| 830 |
+
ctx.fillStyle = HERO.sweaterShade
|
| 831 |
+
ctx.beginPath()
|
| 832 |
+
ctx.moveTo(cx - r * 2.4, cy + r * 3.2)
|
| 833 |
+
ctx.quadraticCurveTo(cx - r * 2.2, cy + r * 1.45, cx - r * 1.2, cy + r * 1.35)
|
| 834 |
+
ctx.quadraticCurveTo(cx - r * 1.6, cy + r * 2.2, cx - r * 1.5, cy + r * 3.2)
|
| 835 |
+
ctx.closePath()
|
| 836 |
+
ctx.fill()
|
| 837 |
+
// neck + ribbed collar
|
| 838 |
+
ctx.fillStyle = HERO.skinShade
|
| 839 |
+
ctx.fillRect(cx - r * 0.34, cy + r * 0.7, r * 0.68, r * 0.7)
|
| 840 |
+
ctx.strokeStyle = HERO.rib
|
| 841 |
+
ctx.lineWidth = r * 0.16
|
| 842 |
+
ctx.beginPath()
|
| 843 |
+
ctx.ellipse(cx, cy + r * 1.34, r * 0.52, r * 0.16, 0, 0, Math.PI)
|
| 844 |
+
ctx.stroke()
|
| 845 |
+
// back hair volume
|
| 846 |
+
ctx.fillStyle = HERO.hair
|
| 847 |
+
ctx.beginPath()
|
| 848 |
+
ctx.ellipse(cx, cy - r * 0.15, r * 1.3, r * 1.18, 0, 0, Math.PI * 2)
|
| 849 |
+
ctx.fill()
|
| 850 |
+
// face
|
| 851 |
+
ctx.fillStyle = HERO.skin
|
| 852 |
+
ctx.beginPath()
|
| 853 |
+
ctx.moveTo(cx - r * 0.94, cy - r * 0.2)
|
| 854 |
+
ctx.lineTo(cx - r * 0.9, cy + r * 0.5)
|
| 855 |
+
ctx.quadraticCurveTo(cx - r * 0.6, cy + r * 0.95, cx, cy + r * 1.0)
|
| 856 |
+
ctx.quadraticCurveTo(cx + r * 0.6, cy + r * 0.95, cx + r * 0.9, cy + r * 0.5)
|
| 857 |
+
ctx.lineTo(cx + r * 0.94, cy - r * 0.2)
|
| 858 |
+
ctx.quadraticCurveTo(cx, cy - r * 1.05, cx - r * 0.92, cy - r * 0.2)
|
| 859 |
+
ctx.fill()
|
| 860 |
+
// ears
|
| 861 |
+
ctx.beginPath()
|
| 862 |
+
ctx.ellipse(cx - r * 0.95, cy + r * 0.12, r * 0.15, r * 0.24, 0, 0, Math.PI * 2)
|
| 863 |
+
ctx.ellipse(cx + r * 0.95, cy + r * 0.12, r * 0.15, r * 0.24, 0, 0, Math.PI * 2)
|
| 864 |
+
ctx.fill()
|
| 865 |
+
// cheek shade
|
| 866 |
+
ctx.fillStyle = rgba(HERO.skinShade, 0.35)
|
| 867 |
+
ctx.beginPath()
|
| 868 |
+
ctx.ellipse(cx - r * 0.55, cy + r * 0.55, r * 0.35, r * 0.3, 0.4, 0, Math.PI * 2)
|
| 869 |
+
ctx.fill()
|
| 870 |
+
ctx.fillStyle = rgba(HERO.blush, 0.16)
|
| 871 |
+
ctx.beginPath()
|
| 872 |
+
ctx.ellipse(cx - r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
|
| 873 |
+
ctx.ellipse(cx + r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
|
| 874 |
+
ctx.fill()
|
| 875 |
+
// eyes
|
| 876 |
+
const open = o.eyes ?? 0
|
| 877 |
+
ctx.strokeStyle = '#2a1d17'
|
| 878 |
+
ctx.fillStyle = '#2a1d17'
|
| 879 |
+
ctx.lineCap = 'round'
|
| 880 |
+
ctx.lineWidth = Math.max(1, r * 0.06)
|
| 881 |
+
for (const sd of [-1, 1]) {
|
| 882 |
+
const ex = cx + sd * r * 0.38
|
| 883 |
+
const ey = cy + r * 0.08
|
| 884 |
+
ctx.beginPath()
|
| 885 |
+
if (open < 0.3) {
|
| 886 |
+
ctx.arc(ex, ey - r * 0.06, r * 0.17, Math.PI * 0.15, Math.PI * 0.85)
|
| 887 |
+
ctx.stroke()
|
| 888 |
+
} else {
|
| 889 |
+
ctx.ellipse(ex, ey, r * 0.1, r * 0.13 * open, 0, 0, Math.PI * 2)
|
| 890 |
+
ctx.fill()
|
| 891 |
+
ctx.fillStyle = '#ffffff'
|
| 892 |
+
ctx.beginPath()
|
| 893 |
+
ctx.arc(ex + r * 0.035, ey - r * 0.04, r * 0.03, 0, Math.PI * 2)
|
| 894 |
+
ctx.fill()
|
| 895 |
+
ctx.fillStyle = '#2a1d17'
|
| 896 |
+
}
|
| 897 |
+
// thick, slightly sad brows
|
| 898 |
+
ctx.save()
|
| 899 |
+
ctx.lineWidth = Math.max(1.5, r * 0.1)
|
| 900 |
+
ctx.beginPath()
|
| 901 |
+
ctx.moveTo(ex - sd * r * 0.18, ey - r * 0.3)
|
| 902 |
+
ctx.lineTo(ex + sd * r * 0.17, ey - r * 0.25)
|
| 903 |
+
ctx.stroke()
|
| 904 |
+
ctx.restore()
|
| 905 |
+
}
|
| 906 |
+
// nose + mouth (slightly open)
|
| 907 |
+
ctx.strokeStyle = rgba(HERO.skinShade, 0.9)
|
| 908 |
+
ctx.beginPath()
|
| 909 |
+
ctx.moveTo(cx + r * 0.02, cy + r * 0.25)
|
| 910 |
+
ctx.lineTo(cx - r * 0.05, cy + r * 0.42)
|
| 911 |
+
ctx.lineTo(cx + r * 0.04, cy + r * 0.44)
|
| 912 |
+
ctx.stroke()
|
| 913 |
+
ctx.fillStyle = '#7a3a34'
|
| 914 |
+
ctx.beginPath()
|
| 915 |
+
if (o.smile) {
|
| 916 |
+
ctx.strokeStyle = '#7a3a34'
|
| 917 |
+
ctx.arc(cx, cy + r * 0.56, r * 0.14, 0.25, Math.PI - 0.25)
|
| 918 |
+
ctx.stroke()
|
| 919 |
+
} else {
|
| 920 |
+
ctx.strokeStyle = '#6a3530'
|
| 921 |
+
ctx.lineWidth = Math.max(1, r * 0.05)
|
| 922 |
+
ctx.moveTo(cx - r * 0.13, cy + r * 0.66)
|
| 923 |
+
ctx.quadraticCurveTo(cx, cy + r * 0.6, cx + r * 0.13, cy + r * 0.66)
|
| 924 |
+
ctx.stroke()
|
| 925 |
+
}
|
| 926 |
+
// tear
|
| 927 |
+
const tear = o.tear ?? 0
|
| 928 |
+
if (tear > 0) {
|
| 929 |
+
const ty = cy + r * 0.2 + tear * r * 0.55
|
| 930 |
+
ctx.fillStyle = 'rgba(190,230,255,0.9)'
|
| 931 |
+
ctx.beginPath()
|
| 932 |
+
ctx.ellipse(cx - r * 0.42, ty, r * 0.05, r * 0.08, 0, 0, Math.PI * 2)
|
| 933 |
+
ctx.fill()
|
| 934 |
+
ctx.strokeStyle = 'rgba(190,230,255,0.45)'
|
| 935 |
+
ctx.lineWidth = Math.max(1, r * 0.03)
|
| 936 |
+
ctx.beginPath()
|
| 937 |
+
ctx.moveTo(cx - r * 0.42, cy + r * 0.18)
|
| 938 |
+
ctx.lineTo(cx - r * 0.42, ty)
|
| 939 |
+
ctx.stroke()
|
| 940 |
+
}
|
| 941 |
+
// curly fringe + crown on top
|
| 942 |
+
curls(ctx, cx, cy - r * 0.38, r * 1.1, 1, o.wind ?? 0, t, true)
|
| 943 |
+
ctx.fillStyle = HERO.hair
|
| 944 |
+
ctx.beginPath()
|
| 945 |
+
for (let i = 0; i < 7; i++) {
|
| 946 |
+
const fx = cx + (i - 3) * r * 0.26
|
| 947 |
+
const fy = cy - r * 0.66 + Math.abs(i - 3) * r * 0.06 + Math.sin(t * 2 + i) * r * 0.01
|
| 948 |
+
ctx.moveTo(fx + r * 0.2, fy)
|
| 949 |
+
ctx.arc(fx, fy, r * (0.2 + 0.05 * hash(i * 9.1)), 0, Math.PI * 2)
|
| 950 |
+
}
|
| 951 |
+
ctx.fill()
|
| 952 |
+
if (o.rim) {
|
| 953 |
+
ctx.strokeStyle = o.rim
|
| 954 |
+
ctx.lineWidth = Math.max(1, r * 0.05)
|
| 955 |
+
ctx.beginPath()
|
| 956 |
+
ctx.arc(cx, cy - r * 0.2, r * 1.42, Math.PI * 1.08, Math.PI * 1.55)
|
| 957 |
+
ctx.stroke()
|
| 958 |
+
}
|
| 959 |
+
}
|
src/mv/engine/scenesA.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
| 19 |
wetReflection,
|
| 20 |
} from './draw'
|
| 21 |
import { camera, resetCam, type SceneCtx } from './types'
|
|
|
|
| 22 |
import {
|
| 23 |
FONT,
|
| 24 |
PALETTE,
|
|
@@ -128,6 +129,11 @@ export function sIgnite(s: SceneCtx) {
|
|
| 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)
|
|
@@ -248,9 +254,11 @@ export function sStreet(s: SceneCtx) {
|
|
| 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 |
-
//
|
| 252 |
const phase = (s.a.beatPos / 2) % 1
|
| 253 |
-
|
|
|
|
|
|
|
| 254 |
// ground
|
| 255 |
ctx.fillStyle = '#05070a'
|
| 256 |
ctx.fillRect(-ext, groundY, W + ext * 3, H)
|
|
@@ -347,8 +355,8 @@ export function sTunnel(s: SceneCtx) {
|
|
| 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
|
| 351 |
-
|
| 352 |
// countdown on the last beats before the drop
|
| 353 |
const bp = (t - DROP1) / BEAT
|
| 354 |
if (bp >= -3 && bp < 0) {
|
|
@@ -518,9 +526,9 @@ function runnerShot(s: SceneCtx, variant: number) {
|
|
| 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 |
-
|
|
|
|
| 524 |
// vertical type
|
| 525 |
const vs = P ? W * 0.11 : H * 0.12
|
| 526 |
const word = variant ? '不回头' : '夜行者'
|
|
@@ -572,7 +580,8 @@ function gridShot(s: SceneCtx, variant: number) {
|
|
| 572 |
}
|
| 573 |
|
| 574 |
// =====================================================================
|
| 575 |
-
// S5 —
|
|
|
|
| 576 |
// =====================================================================
|
| 577 |
export function sRooftop(s: SceneCtx) {
|
| 578 |
const { ctx, W, H, P, lt, u, t, a } = s
|
|
@@ -581,31 +590,64 @@ export function sRooftop(s: SceneCtx) {
|
|
| 581 |
let zoom = 1
|
| 582 |
let cx = W / 2
|
| 583 |
let cy = H / 2
|
| 584 |
-
const
|
| 585 |
-
const figX = P ? W * 0.5 : W * 0.
|
| 586 |
-
const
|
| 587 |
if (!shotB && !shotC) {
|
| 588 |
zoom = 1 + lt * 0.008
|
| 589 |
-
} else if (
|
| 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.
|
| 597 |
-
cx = W / 2 + lerp(-W * 0.
|
| 598 |
-
cy = H / 2 + H * 0.
|
| 599 |
}
|
| 600 |
-
cx += fbm(t * 0.6, 3) * u * 8 +
|
| 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.
|
| 607 |
-
[
|
|
|
|
| 608 |
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
camera(s, zoom, cx, cy)
|
| 610 |
// stars
|
| 611 |
ctx.fillStyle = 'rgba(255,230,230,0.6)'
|
|
@@ -618,9 +660,6 @@ export function sRooftop(s: SceneCtx) {
|
|
| 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')
|
|
@@ -638,7 +677,6 @@ export function sRooftop(s: SceneCtx) {
|
|
| 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
|
|
@@ -647,54 +685,49 @@ export function sRooftop(s: SceneCtx) {
|
|
| 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,
|
| 657 |
}
|
| 658 |
ctx.restore()
|
| 659 |
-
//
|
| 660 |
-
|
| 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(
|
| 677 |
-
|
| 678 |
-
|
|
|
|
|
|
|
|
|
|
| 679 |
ctx.fill()
|
| 680 |
-
ctx.
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
ctx.
|
| 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 |
-
|
| 691 |
-
ctx.
|
| 692 |
-
ctx.
|
| 693 |
-
ctx.lineTo(
|
| 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)
|
|
|
|
| 19 |
wetReflection,
|
| 20 |
} from './draw'
|
| 21 |
import { camera, resetCam, type SceneCtx } from './types'
|
| 22 |
+
import { bike, heroPortrait, heroRide, heroRideRear, heroWalk } from './hero'
|
| 23 |
import {
|
| 24 |
FONT,
|
| 25 |
PALETTE,
|
|
|
|
| 129 |
// dripping pipe on the left + small sign
|
| 130 |
ctx.fillStyle = '#0b0c10'
|
| 131 |
ctx.fillRect(W * 0.08, 0, u * 16, groundY)
|
| 132 |
+
streetLamp(ctx, W * (P ? 0.12 : 0.16), groundY, P ? H * 0.42 : H * 0.62, 0.8 + 0.2 * flicker(t, 31, 4))
|
| 133 |
+
// his black motorcycle, parked in the rain — headlight wakes up with the title
|
| 134 |
+
const bs = P ? W * 0.5 : H * 0.34
|
| 135 |
+
const headOn = lt > 6.4 ? (lt < 7 ? flicker(lt, 12, 18) : 1) : 0
|
| 136 |
+
bike(ctx, P ? W * 0.56 : W * 0.8, groundY, bs, { facing: -1, light: headOn, beam: headOn > 0.5 })
|
| 137 |
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)
|
| 138 |
// ground
|
| 139 |
resetCam(s)
|
|
|
|
| 254 |
ctx.fillRect(x + nearCell * 0.7, top - u * 40, u * 50, u * 36)
|
| 255 |
if (k % 3 === 0) streetLamp(ctx, x + nearCell * 0.05, groundY, u * 330, 0.85 + 0.15 * flicker(t, k + 99, 5))
|
| 256 |
}
|
| 257 |
+
// 阿飞 pushing his motorcycle through the rain
|
| 258 |
const phase = (s.a.beatPos / 2) % 1
|
| 259 |
+
const bs = wh * 1.05
|
| 260 |
+
bike(ctx, wx + bs * 0.62, groundY + u * 2, bs, { facing: 1, light: 0.9, spin: scroll / (bs * 0.21), beam: true })
|
| 261 |
+
heroWalk(ctx, wx, groundY + u * 2, wh, fract(phase), { reach: 1, t, rim: rgba(PALETTE.cyan, 0.8), eyes: 'closed' })
|
| 262 |
// ground
|
| 263 |
ctx.fillStyle = '#05070a'
|
| 264 |
ctx.fillRect(-ext, groundY, W + ext * 3, H)
|
|
|
|
| 355 |
ctx.stroke()
|
| 356 |
speedLines(ctx, vx, vy, Math.max(W, H) * 0.8, t, 90, '#ffffff', 0.04 + p * p * 0.25, 0.25)
|
| 357 |
// figure
|
| 358 |
+
const rs = P ? H * 0.3 : H * 0.52
|
| 359 |
+
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)
|
| 360 |
// countdown on the last beats before the drop
|
| 361 |
const bp = (t - DROP1) / BEAT
|
| 362 |
if (bp >= -3 && bp < 0) {
|
|
|
|
| 526 |
const x = fract(hash(i * 3.1) - t * (1.5 + hash(i))) * W * 1.4 - W * 0.2
|
| 527 |
ctx.fillRect(x, gy + hash(i) * u * 40, u * (80 + hash(i * 2) * 200), Math.max(1, u * 3))
|
| 528 |
}
|
|
|
|
| 529 |
const facing = variant ? -1 : 1
|
| 530 |
+
const bsz = P ? W * 0.62 : H * 0.6
|
| 531 |
+
heroRide(ctx, cx, gy + a.kick * u * 6, bsz, { facing, wind: 1, t, spin: t * 30, beam: true, eyes: 'open', rim: variant ? PALETTE.red : PALETTE.cyan })
|
| 532 |
// vertical type
|
| 533 |
const vs = P ? W * 0.11 : H * 0.12
|
| 534 |
const word = variant ? '不回头' : '夜行者'
|
|
|
|
| 580 |
}
|
| 581 |
|
| 582 |
// =====================================================================
|
| 583 |
+
// S5 — 山顶·红月 (56.35 – 72.95s) 阿飞 on his bike at the ridge,
|
| 584 |
+
// a close-up of his face, then the city lights below
|
| 585 |
// =====================================================================
|
| 586 |
export function sRooftop(s: SceneCtx) {
|
| 587 |
const { ctx, W, H, P, lt, u, t, a } = s
|
|
|
|
| 590 |
let zoom = 1
|
| 591 |
let cx = W / 2
|
| 592 |
let cy = H / 2
|
| 593 |
+
const ridgeY = P ? H * 0.8 : H * 0.8
|
| 594 |
+
const figX = P ? W * 0.5 : W * 0.34
|
| 595 |
+
const bs = P ? W * 0.46 : H * 0.36
|
| 596 |
if (!shotB && !shotC) {
|
| 597 |
zoom = 1 + lt * 0.008
|
| 598 |
+
} else if (shotC) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
const k = (lt - BAR * 5) / (s.dur - BAR * 5)
|
| 600 |
+
zoom = 1.12
|
| 601 |
+
cx = W / 2 + lerp(-W * 0.12, W * 0.12, easeInOutCubic(k))
|
| 602 |
+
cy = H / 2 + H * 0.06
|
| 603 |
}
|
| 604 |
+
cx += fbm(t * 0.6, 3) * u * 8 + a.kick * (hash(a.beat) - 0.5) * u * 14
|
| 605 |
cy += fbm(t * 0.7, 4) * u * 6
|
| 606 |
|
| 607 |
resetCam(s)
|
| 608 |
vGradient(ctx, 0, 0, W, H, [
|
| 609 |
[0, '#0a0307'],
|
| 610 |
+
[0.45, '#2a0710'],
|
| 611 |
+
[0.75, '#6a1a1c'],
|
| 612 |
+
[1, '#2a0a10'],
|
| 613 |
])
|
| 614 |
+
const mx = P ? W * 0.5 : W * 0.64
|
| 615 |
+
const my = P ? H * 0.3 : H * 0.36
|
| 616 |
+
const R = Math.min(W, H) * (P ? 0.36 : 0.3) * (1 + a.kick * 0.03)
|
| 617 |
+
|
| 618 |
+
if (shotB) {
|
| 619 |
+
// ---- close-up: his face in front of the moon, wind in the curls
|
| 620 |
+
const k = (lt - BAR * 3) / (BAR * 2)
|
| 621 |
+
const MR = Math.max(W, H) * 0.42
|
| 622 |
+
const mmx = W / 2 + (P ? 0 : W * 0.18)
|
| 623 |
+
const mmy = H * (P ? 0.32 : 0.4)
|
| 624 |
+
glowBlob(ctx, mmx, mmy, MR * 2, '#ff3a2e', 0.45)
|
| 625 |
+
const mg = ctx.createRadialGradient(mmx - MR * 0.3, mmy - MR * 0.3, MR * 0.1, mmx, mmy, MR)
|
| 626 |
+
mg.addColorStop(0, '#ffd7a8')
|
| 627 |
+
mg.addColorStop(0.5, '#ff7a4a')
|
| 628 |
+
mg.addColorStop(1, '#b3122a')
|
| 629 |
+
ctx.fillStyle = mg
|
| 630 |
+
ctx.beginPath()
|
| 631 |
+
ctx.arc(mmx, mmy, MR, 0, Math.PI * 2)
|
| 632 |
+
ctx.fill()
|
| 633 |
+
const fr = (P ? W * 0.2 : H * 0.2) * (1 + k * 0.05)
|
| 634 |
+
const fx = P ? W / 2 : W * 0.38
|
| 635 |
+
const fy = H * (P ? 0.5 : 0.52)
|
| 636 |
+
const open = k < 0.45 ? 0 : clamp((k - 0.45) / 0.1)
|
| 637 |
+
heroPortrait(ctx, fx, fy, fr, { t, eyes: open, wind: 0.6, rim: rgba('#ffb08a', 0.9), smile: k > 0.7 })
|
| 638 |
+
// drifting embers / dust in the moonlight
|
| 639 |
+
ctx.fillStyle = '#ffd0a0'
|
| 640 |
+
for (let i = 0; i < 50; i++) {
|
| 641 |
+
const x = fract(hash(i * 1.7) + lt * (0.03 + hash(i) * 0.04)) * W
|
| 642 |
+
const y = hash(i * 3.1) * H
|
| 643 |
+
ctx.globalAlpha = 0.3 + 0.5 * hash(i * 9)
|
| 644 |
+
ctx.fillRect(x, y, u * 3, u * 3)
|
| 645 |
+
}
|
| 646 |
+
ctx.globalAlpha = 1
|
| 647 |
+
rain(ctx, W, H, t, { count: Math.floor(120 * area(s)) + 30, speed: H * 1.4, len: u * 40, slant: -0.3, color: '#ffb0b0', alpha: 0.14, width: Math.max(1, u * 1.2) })
|
| 648 |
+
return
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
camera(s, zoom, cx, cy)
|
| 652 |
// stars
|
| 653 |
ctx.fillStyle = 'rgba(255,230,230,0.6)'
|
|
|
|
| 660 |
}
|
| 661 |
ctx.globalAlpha = 1
|
| 662 |
// moon
|
|
|
|
|
|
|
|
|
|
| 663 |
glowBlob(ctx, mx, my, R * 2.6, '#ff3a2e', 0.4 + a.kick * 0.15)
|
| 664 |
const mg = ctx.createRadialGradient(mx - R * 0.3, my - R * 0.3, R * 0.1, mx, my, R)
|
| 665 |
mg.addColorStop(0, '#ffd7a8')
|
|
|
|
| 677 |
ctx.arc(mx + Math.cos(ang) * rr, my + Math.sin(ang) * rr, R * (0.05 + hash(i) * 0.12), 0, Math.PI * 2)
|
| 678 |
ctx.fill()
|
| 679 |
}
|
|
|
|
| 680 |
ctx.fillStyle = 'rgba(12,3,6,0.75)'
|
| 681 |
for (let i = 0; i < 6; i++) {
|
| 682 |
const y = my - R * 0.7 + i * R * 0.32
|
|
|
|
| 685 |
ctx.ellipse(x, y, R * (0.6 + hash(i * 5) * 0.6), R * 0.05, 0, 0, Math.PI * 2)
|
| 686 |
ctx.fill()
|
| 687 |
}
|
| 688 |
+
// searchlights from the city below
|
| 689 |
ctx.save()
|
| 690 |
ctx.globalCompositeOperation = 'lighter'
|
| 691 |
for (let i = 0; i < 3; i++) {
|
| 692 |
const bx = W * (0.15 + i * 0.35)
|
| 693 |
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)
|
| 694 |
+
lightCone(ctx, bx, ridgeY + H * 0.08, H * 1.4, 0.05, Math.PI + sw, PALETTE.bone, 0.09 + a.mid * 0.05)
|
| 695 |
}
|
| 696 |
ctx.restore()
|
| 697 |
+
// far mountains + city in the valley
|
| 698 |
+
ctx.fillStyle = '#16050a'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 699 |
ctx.beginPath()
|
| 700 |
+
ctx.moveTo(-W, ridgeY)
|
| 701 |
+
for (let i = 0; i <= 40; i++) {
|
| 702 |
+
const x = -W * 0.5 + (i / 40) * W * 2
|
| 703 |
+
ctx.lineTo(x, ridgeY - H * (0.12 + 0.1 * fbm(i * 0.35, 7)))
|
| 704 |
+
}
|
| 705 |
+
ctx.lineTo(W * 2, ridgeY)
|
| 706 |
ctx.fill()
|
| 707 |
+
skyline(ctx, { W: W * 1.6, seed: 77, baseY: ridgeY + H * 0.03, scroll: lt * u * 6 + W * 0.3, cell: u * 55, minH: H * 0.03, maxH: H * 0.12, color: '#0a0306', t, density: 0.4, winAlpha: 0.9, rimColor: rgba('#ff4a3c', 0.3) })
|
| 708 |
+
fogBand(ctx, W * 1.6, ridgeY, H * 0.05, '#ff3a2e', 0.18)
|
| 709 |
+
// the ridge road he stops on
|
| 710 |
+
ctx.fillStyle = '#060204'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
ctx.beginPath()
|
| 712 |
+
ctx.moveTo(-W, ridgeY + H * 0.02)
|
| 713 |
+
ctx.quadraticCurveTo(W * 0.5, ridgeY - H * 0.03, W * 2, ridgeY + H * 0.01)
|
| 714 |
+
ctx.lineTo(W * 2, H * 2)
|
| 715 |
+
ctx.lineTo(-W, H * 2)
|
| 716 |
ctx.fill()
|
| 717 |
+
// guard rail
|
| 718 |
+
ctx.strokeStyle = '#2a1a1e'
|
| 719 |
+
ctx.lineWidth = u * 5
|
| 720 |
+
ctx.beginPath()
|
| 721 |
+
ctx.moveTo(-W, ridgeY - u * 30)
|
| 722 |
+
ctx.lineTo(W * 2, ridgeY - u * 36)
|
| 723 |
+
ctx.stroke()
|
| 724 |
+
ctx.fillStyle = '#2a1a1e'
|
| 725 |
+
for (let i = -6; i < 30; i++) ctx.fillRect(i * u * 90 + u * 20, ridgeY - u * 36, u * 6, u * 40)
|
| 726 |
+
// 阿飞 sitting on the parked bike, looking at the moon
|
| 727 |
+
const blink = fract(lt / 3.7) > 0.96 ? 'closed' : 'open'
|
| 728 |
+
heroRide(ctx, figX, ridgeY + u * 4, bs, { facing: 1, wind: 0.35 + 0.15 * Math.sin(t), t, light: 0.6, smile: lt > 4, eyes: blink, rim: rgba('#ff7a4a', 0.9) })
|
| 729 |
resetCam(s)
|
| 730 |
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) })
|
|
|
|
| 731 |
if (shotC && a.beatPhase < 0.08 && a.beat % 2 === 0) {
|
| 732 |
ctx.fillStyle = 'rgba(255,200,190,0.18)'
|
| 733 |
ctx.fillRect(0, 0, W, H)
|
src/mv/engine/scenesB.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
| 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)
|
|
@@ -245,7 +246,7 @@ export function sMarket(s: SceneCtx) {
|
|
| 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 |
-
|
| 249 |
}
|
| 250 |
// warm sparks / embers drifting
|
| 251 |
ctx.fillStyle = '#ffb35c'
|
|
@@ -335,9 +336,43 @@ export function sHeartbeat(s: SceneCtx) {
|
|
| 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 |
-
//
|
| 339 |
-
const fh = P ? H * 0.
|
| 340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
// heartbeat red pulse vignette
|
| 342 |
const pulse = beatGlow * (0.15 + 0.35 * (lt / dur))
|
| 343 |
if (pulse > 0.01) {
|
|
@@ -531,58 +566,49 @@ function chaseShot(s: SceneCtx, shot: number) {
|
|
| 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 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
const rs = P ? W * 0.5 : H * 0.55
|
| 536 |
-
|
| 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 |
|
|
@@ -621,77 +647,16 @@ function sideShot(s: SceneCtx) {
|
|
| 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.
|
| 627 |
-
const by = gy
|
| 628 |
-
const
|
| 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.
|
| 635 |
-
|
| 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++) {
|
|
@@ -755,16 +720,113 @@ export function sFinale(s: SceneCtx) {
|
|
| 755 |
ctx.fillRect(0, 0, W, H)
|
| 756 |
return
|
| 757 |
}
|
| 758 |
-
//
|
| 759 |
vGradient(ctx, 0, 0, W, H, [
|
| 760 |
-
[0, '#
|
| 761 |
-
[0.55, '#
|
| 762 |
-
[
|
|
|
|
| 763 |
])
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 768 |
// neon bursts on kicks
|
| 769 |
ctx.save()
|
| 770 |
ctx.globalCompositeOperation = 'lighter'
|
|
@@ -813,6 +875,8 @@ export function sFinale(s: SceneCtx) {
|
|
| 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 })
|
|
|
|
| 16 |
wetReflection,
|
| 17 |
} from './draw'
|
| 18 |
import { camera, resetCam, type SceneCtx } from './types'
|
| 19 |
+
import { HERO, bike, flame, heroPortrait, heroRide, heroRideRear, heroSit, heroWalk } from './hero'
|
| 20 |
import { FONT, PALETTE, clamp, easeInOutCubic, easeOutCubic, easeOutExpo, fbm, fract, hash, hash2, lerp, rgba, smoothstep } from './util'
|
| 21 |
|
| 22 |
const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
|
|
|
|
| 246 |
const k = (lt - 8.5) / 7
|
| 247 |
const x = lerp(-W * 0.25, W * 1.25, k)
|
| 248 |
const h = P ? H * 0.75 : H * 1.05
|
| 249 |
+
heroWalk(ctx, x, H * (P ? 1.08 : 1.12), h, fract(s.a.beatPos / 2), { t, eyes: 'open', rim: rgba(PALETTE.amber, 0.8) })
|
| 250 |
}
|
| 251 |
// warm sparks / embers drifting
|
| 252 |
ctx.fillStyle = '#ffb35c'
|
|
|
|
| 336 |
ctx.clip()
|
| 337 |
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) })
|
| 338 |
ctx.restore()
|
| 339 |
+
// 阿飞 sits by his motorcycle under the lamp, reading a letter … then burns it
|
| 340 |
+
const fh = P ? H * 0.2 : H * 0.3
|
| 341 |
+
bike(ctx, lx + fh * 0.95, floorY, fh * 1.25, { facing: -1, light: 0 })
|
| 342 |
+
const burn = smoothstep(9.6, 10.4, lt)
|
| 343 |
+
const letter = 1 - smoothstep(10.2, 14.5, lt)
|
| 344 |
+
heroSit(ctx, lx - fh * 0.35, floorY, fh, t, { facing: 1, letter, fire: burn * (letter > 0.02 ? 1 : smoothstep(15.5, 14.5, lt)) })
|
| 345 |
+
if (burn > 0) {
|
| 346 |
+
// warm firelight on the floor
|
| 347 |
+
ctx.save()
|
| 348 |
+
ctx.globalCompositeOperation = 'lighter'
|
| 349 |
+
glowBlob(ctx, lx, floorY - fh * 0.4, fh * 1.6, '#ff7a2e', 0.25 * burn * (0.85 + 0.15 * Math.sin(t * 13)))
|
| 350 |
+
ctx.restore()
|
| 351 |
+
}
|
| 352 |
+
if (lt > 5.0 && lt < 9.3) {
|
| 353 |
+
const k = (lt - 5.0) / 4.3
|
| 354 |
+
ctx.fillStyle = '#050406'
|
| 355 |
+
ctx.fillRect(0, 0, W, H)
|
| 356 |
+
lightCone(ctx, W / 2, 0, H, 0.5, 0, '#f3e2c4', 0.2 * on)
|
| 357 |
+
const fr = P ? W * 0.24 : H * 0.24
|
| 358 |
+
heroPortrait(ctx, W / 2, H * (P ? 0.46 : 0.48), fr * (1 + k * 0.06), { t, eyes: 0, tear: clamp(k * 1.3), rim: rgba('#f3e2c4', 0.6 * on) })
|
| 359 |
+
ctx.save()
|
| 360 |
+
ctx.strokeStyle = PALETTE.red
|
| 361 |
+
ctx.shadowColor = PALETTE.red
|
| 362 |
+
ctx.shadowBlur = u * 18
|
| 363 |
+
ctx.lineWidth = Math.max(2, u * 4)
|
| 364 |
+
ctx.globalAlpha = 0.7
|
| 365 |
+
ctx.beginPath()
|
| 366 |
+
for (let i = 0; i <= 160; i++) {
|
| 367 |
+
const x = (i / 160) * W
|
| 368 |
+
const tau = lt - (1 - i / 160) * span
|
| 369 |
+
const y = H * 0.9 - ecg(fract(hbAt(tau))) * H * 0.08
|
| 370 |
+
if (i === 0) ctx.moveTo(x, y)
|
| 371 |
+
else ctx.lineTo(x, y)
|
| 372 |
+
}
|
| 373 |
+
ctx.stroke()
|
| 374 |
+
ctx.restore()
|
| 375 |
+
}
|
| 376 |
// heartbeat red pulse vignette
|
| 377 |
const pulse = beatGlow * (0.15 + 0.35 * (lt / dur))
|
| 378 |
if (pulse > 0.01) {
|
|
|
|
| 566 |
ctx.restore()
|
| 567 |
resetCam(s)
|
| 568 |
speedLines(ctx, W / 2, hy, Math.max(W, H) * 0.9, t, 100, '#ffffff', 0.05 + a.kick * 0.12, 0.3)
|
| 569 |
+
// a big truck thundering along in the right lane (as in the reference)
|
| 570 |
+
{
|
| 571 |
+
const tz = 7 + 9 * (0.5 + 0.5 * Math.sin(lt * 0.35 + shot * 2))
|
| 572 |
+
const TX0 = 2.9
|
| 573 |
+
const TX1 = 6.2
|
| 574 |
+
const TH = 4.3
|
| 575 |
+
const back0 = proj(TX0, 0.6, camZ + tz)
|
| 576 |
+
const back1 = proj(TX1, TH, camZ + tz)
|
| 577 |
+
const side0 = proj(TX0, 0.6, camZ + tz + 14)
|
| 578 |
+
const side1 = proj(TX0, TH, camZ + tz + 14)
|
| 579 |
+
ctx.save()
|
| 580 |
+
camera(s, 1 + a.kick * 0.02, W / 2, H / 2, lean)
|
| 581 |
+
// side panel
|
| 582 |
+
ctx.fillStyle = '#2a2d33'
|
| 583 |
+
ctx.beginPath()
|
| 584 |
+
ctx.moveTo(back0.x, back0.y)
|
| 585 |
+
ctx.lineTo(side0.x, side0.y)
|
| 586 |
+
ctx.lineTo(side1.x, side1.y)
|
| 587 |
+
ctx.lineTo(back0.x, back1.y)
|
| 588 |
+
ctx.closePath()
|
| 589 |
+
ctx.fill()
|
| 590 |
+
// rear doors
|
| 591 |
+
ctx.fillStyle = '#5a5e66'
|
| 592 |
+
ctx.fillRect(back0.x, back1.y, back1.x - back0.x, back0.y - back1.y)
|
| 593 |
+
ctx.strokeStyle = '#2a2d33'
|
| 594 |
+
ctx.lineWidth = Math.max(1, (back1.x - back0.x) * 0.02)
|
| 595 |
+
ctx.strokeRect(back0.x, back1.y, back1.x - back0.x, back0.y - back1.y)
|
| 596 |
+
ctx.beginPath()
|
| 597 |
+
ctx.moveTo((back0.x + back1.x) / 2, back1.y)
|
| 598 |
+
ctx.lineTo((back0.x + back1.x) / 2, back0.y)
|
| 599 |
+
ctx.stroke()
|
| 600 |
+
const tw = back1.x - back0.x
|
| 601 |
+
glowBlob(ctx, back0.x + tw * 0.08, back0.y - tw * 0.05, tw * 0.12, PALETTE.red, 1)
|
| 602 |
+
glowBlob(ctx, back1.x - tw * 0.08, back0.y - tw * 0.05, tw * 0.12, PALETTE.red, 1)
|
| 603 |
+
// wheels
|
| 604 |
+
ctx.fillStyle = '#050507'
|
| 605 |
+
ctx.fillRect(back0.x + tw * 0.05, back0.y, tw * 0.25, tw * 0.12)
|
| 606 |
+
ctx.fillRect(back1.x - tw * 0.3, back0.y, tw * 0.25, tw * 0.12)
|
| 607 |
+
ctx.restore()
|
| 608 |
+
}
|
| 609 |
+
// 阿飞 (rear view) at bottom centre — curls flying in the wind
|
| 610 |
const rs = P ? W * 0.5 : H * 0.55
|
| 611 |
+
heroRideRear(ctx, W / 2, H * 1.0 + a.kick * u * 6, rs * 1.15, -curve * 0.14, t, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
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) })
|
| 613 |
}
|
| 614 |
|
|
|
|
| 647 |
ctx.fillRect(x, gy + (H - gy) * 0.45, u * 200, u * 6)
|
| 648 |
}
|
| 649 |
wetReflection(ctx, s.scratch, W, H, gy, t, 0.35, u * 2)
|
| 650 |
+
// 阿飞 on his bike, side view, hair streaming back
|
| 651 |
const bx = W * 0.5 + Math.sin(lt * 1.3) * u * 20
|
| 652 |
+
const bs = P ? W * 0.62 : H * 0.5
|
| 653 |
+
const by = gy + a.kick * u * 4
|
| 654 |
+
const tg = ctx.createLinearGradient(bx - bs * 2.6, 0, bx - bs * 0.6, 0)
|
|
|
|
|
|
|
| 655 |
tg.addColorStop(0, 'rgba(255,45,85,0)')
|
| 656 |
tg.addColorStop(1, 'rgba(255,45,85,0.85)')
|
| 657 |
ctx.fillStyle = tg
|
| 658 |
+
ctx.fillRect(bx - bs * 2.6, by - bs * 0.46, bs * 2, Math.max(2, bs * 0.03))
|
| 659 |
+
heroRide(ctx, bx, by, bs, { facing: 1, wind: 1, t, spin: lt * 40, beam: true, eyes: 'open', rim: rgba(PALETTE.cyan, 0.85) })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 660 |
// horizontal speed lines
|
| 661 |
ctx.fillStyle = 'rgba(255,255,255,0.18)'
|
| 662 |
for (let i = 0; i < 30; i++) {
|
|
|
|
| 720 |
ctx.fillRect(0, 0, W, H)
|
| 721 |
return
|
| 722 |
}
|
| 723 |
+
// night hill: a big tree, a crescent moon, a train passing in the distance
|
| 724 |
vGradient(ctx, 0, 0, W, H, [
|
| 725 |
+
[0, '#04071a'],
|
| 726 |
+
[0.55, '#14204a'],
|
| 727 |
+
[0.8, '#3a1d4a'],
|
| 728 |
+
[1, '#120a18'],
|
| 729 |
])
|
| 730 |
+
// stars
|
| 731 |
+
for (let i = 0; i < 180; i++) {
|
| 732 |
+
const x = hash(i * 1.37) * W
|
| 733 |
+
const y = hash(i * 2.71) * H * 0.7
|
| 734 |
+
const tw = 0.35 + 0.65 * Math.abs(Math.sin(t * (0.6 + hash(i) * 2) + i))
|
| 735 |
+
ctx.fillStyle = i % 9 === 0 ? '#ffe6b0' : '#dfe8ff'
|
| 736 |
+
ctx.globalAlpha = tw * (0.5 + 0.5 * hash(i * 5))
|
| 737 |
+
const sz = u * (1.5 + 2 * hash(i * 7))
|
| 738 |
+
ctx.fillRect(x, y, sz, sz)
|
| 739 |
+
}
|
| 740 |
+
ctx.globalAlpha = 1
|
| 741 |
+
// crescent moon
|
| 742 |
+
{
|
| 743 |
+
const mx = P ? W * 0.76 : W * 0.82
|
| 744 |
+
const my = H * 0.16
|
| 745 |
+
const mr = Math.min(W, H) * 0.07
|
| 746 |
+
glowBlob(ctx, mx, my, mr * 4, '#ffe6b0', 0.25)
|
| 747 |
+
ctx.fillStyle = '#fff1c8'
|
| 748 |
+
ctx.beginPath()
|
| 749 |
+
ctx.arc(mx, my, mr, 0, Math.PI * 2)
|
| 750 |
+
ctx.fill()
|
| 751 |
+
ctx.fillStyle = '#0a1030'
|
| 752 |
+
ctx.beginPath()
|
| 753 |
+
ctx.arc(mx + mr * 0.45, my - mr * 0.2, mr * 0.92, 0, Math.PI * 2)
|
| 754 |
+
ctx.fill()
|
| 755 |
+
}
|
| 756 |
+
const horizon = P ? H * 0.8 : H * 0.78
|
| 757 |
+
// far hills
|
| 758 |
+
ctx.fillStyle = '#0c0f24'
|
| 759 |
+
ctx.beginPath()
|
| 760 |
+
ctx.moveTo(0, horizon)
|
| 761 |
+
for (let i = 0; i <= 30; i++) ctx.lineTo((i / 30) * W, horizon - H * (0.06 + 0.06 * fbm(i * 0.4, 11)))
|
| 762 |
+
ctx.lineTo(W, H)
|
| 763 |
+
ctx.lineTo(0, H)
|
| 764 |
+
ctx.fill()
|
| 765 |
+
// the train (red & yellow carriages, warm windows)
|
| 766 |
+
{
|
| 767 |
+
const ty = horizon - H * 0.035
|
| 768 |
+
const cw = u * (P ? 120 : 150)
|
| 769 |
+
const chh = cw * 0.32
|
| 770 |
+
const head = W * 1.15 - lt * W * 0.09
|
| 771 |
+
for (let c = 0; c < 9; c++) {
|
| 772 |
+
const x = head + c * cw * 1.04
|
| 773 |
+
if (x > W + cw || x + cw < -cw) continue
|
| 774 |
+
ctx.fillStyle = c === 0 ? '#c4142f' : c % 2 ? '#d9a12a' : '#b8202c'
|
| 775 |
+
ctx.fillRect(x, ty - chh, cw, chh)
|
| 776 |
+
ctx.fillStyle = '#2a0a0a'
|
| 777 |
+
ctx.fillRect(x, ty - chh * 0.25, cw, chh * 0.12)
|
| 778 |
+
ctx.fillStyle = '#ffe6a0'
|
| 779 |
+
for (let w = 0; w < 6; w++) ctx.fillRect(x + cw * (0.08 + w * 0.15), ty - chh * 0.78, cw * 0.09, chh * 0.32)
|
| 780 |
+
if (c === 0) glowBlob(ctx, x, ty - chh * 0.5, cw * 0.5, '#fff1c8', 0.9)
|
| 781 |
+
}
|
| 782 |
+
ctx.fillStyle = '#05060f'
|
| 783 |
+
ctx.fillRect(0, ty, W, u * 4)
|
| 784 |
+
}
|
| 785 |
+
// near hill
|
| 786 |
+
ctx.fillStyle = '#05060c'
|
| 787 |
+
ctx.beginPath()
|
| 788 |
+
ctx.moveTo(0, horizon + H * 0.02)
|
| 789 |
+
ctx.quadraticCurveTo(W * 0.3, horizon - H * 0.06, W * 0.6, horizon + H * 0.01)
|
| 790 |
+
ctx.quadraticCurveTo(W * 0.8, horizon + H * 0.04, W, horizon + H * 0.02)
|
| 791 |
+
ctx.lineTo(W, H)
|
| 792 |
+
ctx.lineTo(0, H)
|
| 793 |
+
ctx.fill()
|
| 794 |
+
// the big tree
|
| 795 |
+
{
|
| 796 |
+
const tx = P ? W * 0.2 : W * 0.17
|
| 797 |
+
const base = horizon - H * 0.02
|
| 798 |
+
const th = P ? H * 0.42 : H * 0.6
|
| 799 |
+
ctx.fillStyle = '#04050a'
|
| 800 |
+
ctx.beginPath()
|
| 801 |
+
ctx.moveTo(tx - th * 0.05, base)
|
| 802 |
+
ctx.quadraticCurveTo(tx - th * 0.02, base - th * 0.4, tx - th * 0.1, base - th * 0.62)
|
| 803 |
+
ctx.lineTo(tx + th * 0.08, base - th * 0.62)
|
| 804 |
+
ctx.quadraticCurveTo(tx + th * 0.03, base - th * 0.4, tx + th * 0.07, base)
|
| 805 |
+
ctx.fill()
|
| 806 |
+
ctx.fillStyle = '#060a12'
|
| 807 |
+
ctx.beginPath()
|
| 808 |
+
for (let i = 0; i < 16; i++) {
|
| 809 |
+
const ang = (i / 16) * Math.PI * 2
|
| 810 |
+
const rr = th * (0.26 + 0.1 * hash(i * 2.3))
|
| 811 |
+
const px = tx + Math.cos(ang) * th * 0.32 * (0.7 + 0.3 * hash(i))
|
| 812 |
+
const py = base - th * 0.78 + Math.sin(ang) * th * 0.18 + Math.sin(t * 0.8 + i) * u * 2
|
| 813 |
+
ctx.moveTo(px + rr, py)
|
| 814 |
+
ctx.arc(px, py, rr, 0, Math.PI * 2)
|
| 815 |
+
}
|
| 816 |
+
ctx.fill()
|
| 817 |
+
// fireflies
|
| 818 |
+
ctx.fillStyle = '#d8ff9a'
|
| 819 |
+
for (let i = 0; i < 18; i++) {
|
| 820 |
+
const px = tx + Math.sin(t * 0.5 + i * 2.1) * th * 0.45
|
| 821 |
+
const py = base - th * (0.25 + 0.5 * hash(i * 3.3)) + Math.cos(t * 0.7 + i) * u * 20
|
| 822 |
+
ctx.globalAlpha = 0.4 + 0.6 * Math.abs(Math.sin(t * 2 + i))
|
| 823 |
+
ctx.fillRect(px, py, u * 3, u * 3)
|
| 824 |
+
}
|
| 825 |
+
ctx.globalAlpha = 1
|
| 826 |
+
// 阿飞 sitting on his bike under the tree, watching the train
|
| 827 |
+
const bs = P ? W * 0.34 : H * 0.24
|
| 828 |
+
heroRide(ctx, tx + th * (P ? 0.55 : 0.42), base + u * 2, bs, { facing: 1, wind: 0.25, t, light: 0.5, smile: true, eyes: 'open', rim: rgba('#9ab8ff', 0.6) })
|
| 829 |
+
}
|
| 830 |
// neon bursts on kicks
|
| 831 |
ctx.save()
|
| 832 |
ctx.globalCompositeOperation = 'lighter'
|
|
|
|
| 875 |
// solid neon title
|
| 876 |
const titleOn = smoothstep(9.2, 10.2, lt)
|
| 877 |
if (titleOn > 0) {
|
| 878 |
+
ctx.fillStyle = `rgba(3,4,10,${0.35 * titleOn})`
|
| 879 |
+
ctx.fillRect(0, 0, W, H)
|
| 880 |
const fl = a.drop && hash(a.beat * 3.1) > 0.8 && a.beatPhase < 0.1 ? 0.3 : 1
|
| 881 |
glowBlob(ctx, W / 2, L.cy, L.size * 2.4, PALETTE.red, 0.3 * titleOn)
|
| 882 |
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 })
|
src/mv/engine/timeline.ts
CHANGED
|
@@ -16,15 +16,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: '开场·霓虹
|
| 20 |
-
{ id: 'street', name: '雨夜
|
| 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: '
|
| 24 |
{ id: 'market', name: '葱姜蒜夜市', start: BREAK, end: b2(-32), fn: sMarket, color: '#ffb35c' },
|
| 25 |
-
{ id: 'heart', name: '
|
| 26 |
-
{ id: 'highway', name: 'Drop2·
|
| 27 |
-
{ id: 'finale', name: '终章·
|
| 28 |
]
|
| 29 |
|
| 30 |
export function sceneAt(t: number): SceneDef {
|
|
@@ -40,20 +40,20 @@ export interface Caption {
|
|
| 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 {
|
|
|
|
| 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 {
|
|
|
|
| 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 {
|
src/mv/export/exportMp4.ts
CHANGED
|
@@ -62,6 +62,13 @@ async function decodeAudio(): Promise<AudioBuffer> {
|
|
| 62 |
|
| 63 |
const tick = () => new Promise<void>((r) => setTimeout(r, 0))
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
export async function exportMp4(o: ExportOptions): Promise<ExportResult> {
|
| 66 |
if (!webCodecsSupported()) return exportRealtime(o)
|
| 67 |
const { width, height, fps, signal, onProgress } = o
|
|
@@ -141,7 +148,7 @@ export async function exportMp4(o: ExportOptions): Promise<ExportResult> {
|
|
| 141 |
error: (e) => (failure = e as Error),
|
| 142 |
})
|
| 143 |
ve.configure({ codec, width, height, bitrate, framerate: fps, latencyMode: 'quality', avc: { format: 'avc' } })
|
| 144 |
-
const r =
|
| 145 |
r.setSize(width, height)
|
| 146 |
const total = Math.ceil(DURATION * fps)
|
| 147 |
const t0 = performance.now()
|
|
@@ -179,7 +186,7 @@ async function exportRealtime(o: ExportOptions): Promise<ExportResult> {
|
|
| 179 |
if (typeof MediaRecorder === 'undefined') throw new Error('当前浏览器不支持本地视频编码,请使用最新版 Chrome / Edge / Safari')
|
| 180 |
const mimes = ['video/mp4;codecs=avc1.640028,mp4a.40.2', 'video/mp4;codecs=avc1,mp4a', 'video/mp4', 'video/webm;codecs=vp9,opus', 'video/webm']
|
| 181 |
const mime = mimes.find((m) => MediaRecorder.isTypeSupported(m)) || ''
|
| 182 |
-
const r =
|
| 183 |
r.setSize(width, height)
|
| 184 |
const AC: typeof AudioContext = window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext
|
| 185 |
const ac = new AC()
|
|
|
|
| 62 |
|
| 63 |
const tick = () => new Promise<void>((r) => setTimeout(r, 0))
|
| 64 |
|
| 65 |
+
// one WebGL context for all exports (browsers cap the number of live contexts)
|
| 66 |
+
let sharedRenderer: Renderer | null = null
|
| 67 |
+
export function exportRenderer(): Renderer {
|
| 68 |
+
sharedRenderer ??= new Renderer()
|
| 69 |
+
return sharedRenderer
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
export async function exportMp4(o: ExportOptions): Promise<ExportResult> {
|
| 73 |
if (!webCodecsSupported()) return exportRealtime(o)
|
| 74 |
const { width, height, fps, signal, onProgress } = o
|
|
|
|
| 148 |
error: (e) => (failure = e as Error),
|
| 149 |
})
|
| 150 |
ve.configure({ codec, width, height, bitrate, framerate: fps, latencyMode: 'quality', avc: { format: 'avc' } })
|
| 151 |
+
const r = exportRenderer()
|
| 152 |
r.setSize(width, height)
|
| 153 |
const total = Math.ceil(DURATION * fps)
|
| 154 |
const t0 = performance.now()
|
|
|
|
| 186 |
if (typeof MediaRecorder === 'undefined') throw new Error('当前浏览器不支持本地视频编码,请使用最新版 Chrome / Edge / Safari')
|
| 187 |
const mimes = ['video/mp4;codecs=avc1.640028,mp4a.40.2', 'video/mp4;codecs=avc1,mp4a', 'video/mp4', 'video/webm;codecs=vp9,opus', 'video/webm']
|
| 188 |
const mime = mimes.find((m) => MediaRecorder.isTypeSupported(m)) || ''
|
| 189 |
+
const r = exportRenderer()
|
| 190 |
r.setSize(width, height)
|
| 191 |
const AC: typeof AudioContext = window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext
|
| 192 |
const ac = new AC()
|