Ethscriptions commited on
Commit
c174bde
·
verified ·
1 Parent(s): 6855c38

v4:开场陈雅雯+侧坐+篝火;骑车穿街+10种店铺;新增倒车闪灯、喷射飞越两段高速剧情;重做葱姜蒜夜市;烧报纸动作

Browse files
README.md CHANGED
@@ -112,15 +112,15 @@ pinned: false
112
 
113
  | 时间 | 场景 | 内容 |
114
  |------|------|------|
115
- | 0 – 9s | **S1 开场·霓虹与摩托** | 雨夜路灯下停着他的黑色摩托 →「黑街」霓虹灯管逐笔点亮,摩托车头灯随之亮起 |
116
- | 9 – 24s | **S2 雨夜·推车少年** | 阿飞推着摩托走过霓虹长街,积水倒影,招牌闪烁 |
117
- | 24 – 38.2s | **S3 蓄力·隧道** | 阿飞骑车冲进隧道(后视角),卷发被风吹起,倒数 3·2·1 |
118
- | 38.2 – 56s | **S4 Drop1·霓虹爆裂** | 海报大字 / 均衡器天际线 / 阿飞侧面飙车 / 霓虹格子,按小节快切 |
119
- | 56 – 73s | **S5 山顶·红月** | 阿飞坐在摩托上望着巨大红月 → 脸部特写(睁眼、浅笑)→ 山下城市灯海 |
120
- | 73 – 91s | **S6 葱姜蒜夜市** | 暖色灯笼、蒸汽、葱姜蒜摊位,阿飞从镜头前走过 |
121
- | 91 – 109.4s | **S7 灯下·烧掉的信** | 路灯下,阿飞坐在摩托旁读信 → 闭眼落泪特写 → 把信烧掉,心跳加速 |
122
- | 109.4 – 128s | **S8 Drop2·公路之王** | 夜间高速,大货车并行,阿飞后视角 / 侧面狂飙 |
123
- | 128 – 144.4s | **S9 终章·星空与火车** | 大树、星空、弯月、远处驶过的红黄火车,阿飞坐在车上看着 → 光点汇聚成「黑街」 |
124
 
125
  所有场景同时适配 16:9 和 9:16(按画布宽高比重新排版,不是简单裁切)。
126
 
@@ -221,3 +221,11 @@ npm run build && npm start # 生产(http://localhost:3000)
221
  - 机车:重画为复古街车——辐条轮 + 镀铬轮圈 + 前刹车盘、摆臂、链条、双减震黄色弹簧、带散热片的气缸和曲轴箱盖、镀铬排气管和消音器、侧盖、带缝线的座垫、亮面水滴油箱(镀铬徽章 + 护膝垫)、前叉防尘套、镀铬灯碗车头灯 + 琥珀色转向灯、仪表、圆后视镜、牌照、侧支架(停车时放下)、地面阴影;后视角加双减震、双消音器和带胎纹的粗后胎;
222
  - 防穿模:IK 解算,脚本实测手到车把、脚到脚踏的误差均为 0.00,膝盖不进入车轮,推车的每个步态阶段双手都在车把上;
223
  - 识别模型复查:机车被描述为「黑色摩托、圆形车头灯、两个大圆后视镜、银色轮圈、棕色皮座垫」,人物为「穿蓝衣灰裤、爆炸卷发、表情忧伤的年轻男生」。全时间轴横竖屏逐 0.5 秒扫描无报错。
 
 
 
 
 
 
 
 
 
112
 
113
  | 时间 | 场景 | 内容 |
114
  |------|------|------|
115
+ | 0 – 9s | **S1 开场·篝火与摩托** | 「黑街」霓虹逐笔点亮;右侧「陈雅雯」霓虹招牌;阿飞侧坐在停着的摩托上望着左下角的篝火(旁边两瓶啤酒),车头灯随标题亮起 |
116
+ | 9 – 24s | **S2 雨夜·骑车穿街** | 阿飞骑车穿过雨夜长街;沿街是网吧、桌球、电玩城、机车改装、烧烤大排档、卡拉OK、士多、冰室、纹身、发廊,每家店都画出店内景象 |
117
+ | 24 – 38.2s | **S3 蓄力·隧道** | 骑车冲进隧道(后视角),倒数 3·2·1 |
118
+ | 38.2 – 43.8s | **S4 Drop1·霓虹爆裂** | 海报大字 → 侧面飙车 → 霓虹格子(10 拍) |
119
+ | 43.8 – 73s | **S5 公路·倒车闪灯** | 红色跑车从后面用远光灯挑衅 → 抢到前面别车、点刹、放炮 → 阿飞开着白色小车从左车道超车 → 拉手刹特写 → 甩尾 180°(轮胎烟 + 刹车痕)倒着开、车头对着红车 → 对方视角:远光灯随鼓点狂闪 → 再拉手刹甩回 → 加速离开 |
120
+ | 73 – 91s | **S6 葱姜蒜夜市(重做)** | 老唐楼、晾衣、霓虹、串灯、灯笼下的一排摊位(葱姜蒜 / 烧烤 / 糖水 / 鱼蛋 / 水果 / 炒粉)→ 菜摊特写:阿姨把葱姜蒜装进红袋子递给阿飞 → 车把挂着红袋子骑车离开 |
121
+ | 91 – 109.4s | **S7 灯下·烧报纸** | 路灯下阿飞坐在摩托前读《黑街晚报》(报纸挡住脸)→ 落泪特写 → 掏出打火机点着报纸一角 → 火从角上往上烧、露出他的脸 → 松手扔到地上烧成灰烬 |
122
+ | 109.4 – 128s | **S8 Drop2·喷射飞越** | 被红车左右堵路 → 掀开「JET」开关护盖按下 → 侧面长镜头:车底两个喷口向下喷气把车顶起,从红车上方飞过(红车司机抬头看)→ 落地前再向下喷气缓冲,悬挂压缩回弹、火花 → 喷口转向后方喷气 → 加速离开 → 红车视角看它远去 |
123
+ | 128 – 144.4s | **S9 终章·星空与火车** | 大树、星空、弯月、远处驶过的火车,阿飞坐在车上 → 光点汇聚成「黑街」 |
124
 
125
  所有场景同时适配 16:9 和 9:16(按画布宽高比重新排版,不是简单裁切)。
126
 
 
221
  - 机车:重画为复古街车——辐条轮 + 镀铬轮圈 + 前刹车盘、摆臂、链条、双减震黄色弹簧、带散热片的气缸和曲轴箱盖、镀铬排气管和消音器、侧盖、带缝线的座垫、亮面水滴油箱(镀铬徽章 + 护膝垫)、前叉防尘套、镀铬灯碗车头灯 + 琥珀色转向灯、仪表、圆后视镜、牌照、侧支架(停车时放下)、地面阴影;后视角加双减震、双消音器和带胎纹的粗后胎;
222
  - 防穿模:IK 解算,脚本实测手到车把、脚到脚踏的误差均为 0.00,膝盖不进入车轮,推车的每个步态阶段双手都在车把上;
223
  - 识别模型复查:机车被描述为「黑色摩托、圆形车头灯、两个大圆后视镜、银色轮圈、棕色皮座垫」,人物为「穿蓝衣灰裤、爆炸卷发、表情忧伤的年轻男生」。全时间轴横竖屏逐 0.5 秒扫描无报错。
224
+ - **步骤 9(v4:剧情重构)** ✅
225
+ - 开场:招牌改为「陈雅雯」,阿飞侧坐在摩托上(正面朝镜头,腿垂在车侧、脚落在脚踏高度),去掉左边路灯,左下角加篝火(石圈、交叉木柴、火焰、火星、两瓶啤酒);
226
+ - 雨夜长街:推车改为骑车;店铺不再重复「典当 / 当」,换成 10 种黑街少年常去的店并画出店内(网吧电脑屏、桌球台和吊灯、街机、机车改装铺里的摩托和工具墙、烧烤炉和塑料凳、卡拉OK 迪斯科球、士多货架和冰柜、冰室吊扇、纹身店、发廊转灯);
227
+ - 44 秒–1:12:删掉原片段,新增「倒车闪灯」高速剧情(车内侧脸、主角视角、俯视超车 / 甩尾 / 倒车、拉手刹特写、对方视角远光闪烁),新建 `cars.ts`(白色掀背小车 / 红色跑车的侧视、俯视、车尾、车头四种画法)和 `scenesCar.ts`;
228
+ - 葱姜蒜夜市:整段重做(`scenesMarket.ts`),摊主阿姨用同一套骨骼换配色和头巾绘制,递袋子的交接点由双方肩膀位置解算,保证两只手都够得到;
229
+ - 灯下:信改为报纸,有读报 → 掏打火机 → 点火 → 火焰沿对角线烧开(焦边 + 火苗 + 灰烬)→ 扔地上的完整动作;
230
+ - 结尾:删除原摩托公路段,新增「喷射飞越」剧情;
231
+ - 校验:脚本实测飞越时主角车最低点距红车车顶 ≥ 0.82 m,超车 / 甩尾过程中同车道两车间距 ≥ 3.55 m(无穿模);识别模型复查描述为「白色小车飞越红色汽车」「高速上两辆车面对面」「摊位前一男一女,三筐菜」等;全时间轴横竖屏扫描无报错。
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:a3fa76be4b851fc0b7bd9e508e237a0b705ed8ed9325460e268591c745887db5
3
- size 104752
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0d4bc6c74d8e2248f88ba92c3cbef3441eba6a9654096879a559b5892f32323
3
+ size 110992
src/mv/copy/platforms.ts CHANGED
@@ -21,14 +21,14 @@ export const PLATFORMS: PlatformCopy[] = [
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
  '你最喜欢哪一个镜头?评论区告诉我👇',
31
- tags: ['黑街', 'DJ葱姜蒜进行曲', '原创MV', '音乐可视化', '霓虹夜景', '赛博朋克', '雨夜氛围感', '卡点视频', '动画短片', '城市夜色'],
32
  tip: '标题 ≤ 20 字,话题 ≤ 10 个',
33
  },
34
  {
@@ -38,8 +38,8 @@ export const PLATFORMS: PlatformCopy[] = [
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
  },
@@ -50,11 +50,11 @@ export const PLATFORMS: PlatformCopy[] = [
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
  {
@@ -65,22 +65,23 @@ export const PLATFORMS: PlatformCopy[] = [
65
  tagLimit: 10,
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', '公路之王', '程序化动画', '摩托', '霓虹', '卡点', '动画短片', '音乐可视化'],
 
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
  '你最喜欢哪一个镜头?评论区告诉我👇',
31
+ tags: ['黑街', 'DJ葱姜蒜进行曲', '原创MV', '音乐可视化', '霓虹夜景', '赛博朋克', '雨夜氛围感', '卡点视频', '动画短片', '陈雅雯'],
32
  tip: '标题 ≤ 20 字,话题 ≤ 10 个',
33
  },
34
  {
 
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
  },
 
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
  {
 
65
  tagLimit: 10,
66
  tagStyle: 'comma',
67
  titles: [
68
+ '【原创MV】《黑街》|卷发少年的公路对决:手刹倒车闪远光、喷射飞越挑衅车,两次Drop全程卡点',
69
  '【原创MV】《黑街》DJ葱姜蒜进行曲|纯代码绘制的雨夜霓虹动画,两次Drop全程卡点,支持竖屏观看',
70
+ '【程序化动画】卷发少年的黑街一夜:篝火→雨夜骑行→倒车闪灯→葱姜蒜夜市→烧报纸→喷射飞越',
71
  '105.5BPM卡点!用浏览器实时渲染一支《黑街》MV,每一帧都是代码画的',
72
  ],
73
  desc:
74
  '🎵 音乐:DJ鐘董《黑街(DJ葱姜蒜进行曲)》\n' +
75
  '🎨 画面:原创程序化动画,浏览器 Canvas + WebGL ���时渲染;主角「阿飞」按参考视频里的蓝毛衣卷发少年重新绘制\n\n' +
76
  '⏱ 分镜\n' +
77
+ '00:00 开场·篝火与摩托\n' +
78
+ '00:09 雨夜·骑车穿街\n' +
79
  '00:23 蓄力·隧道\n' +
80
  '00:38 Drop1·霓虹爆裂\n' +
81
+ '00:43 公路·倒车闪灯\n' +
82
  '01:12 葱姜蒜夜市\n' +
83
+ '01:31 灯下·烧报纸\n' +
84
+ '01:49 Drop2·喷射飞越\n' +
85
  '02:07 终章·星空与火车\n\n' +
86
  '喜欢的话一键三连,弹幕告诉我你最喜欢哪个镜头!',
87
  tags: ['黑街', 'DJ葱姜蒜进行曲', '原创MV', '公路之王', '程序化动画', '摩托', '霓虹', '卡点', '动画短片', '音乐可视化'],
src/mv/covers/covers.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BEAT, DROP1 } from '../engine/audio'
2
  import { Renderer } from '../engine/renderer'
3
  import { FONT, PALETTE } from '../engine/util'
4
 
@@ -82,7 +82,7 @@ export const DESIGNS: CoverDesign[] = [
82
  },
83
  {
84
  id: 'street',
85
- name: '雨夜推车',
86
  t: 13.2,
87
  overlay(ctx, W, H) {
88
  const u = S(W, H)
@@ -98,22 +98,19 @@ export const DESIGNS: CoverDesign[] = [
98
  },
99
  },
100
  {
101
- id: 'moon',
102
- name: '红月山顶',
103
- t: 60.6,
104
  overlay(ctx, W, H) {
105
  const u = S(W, H)
106
- const P = H > W
107
- const size = P ? W * 0.2 : H * 0.24
108
- const x = P ? W * 0.16 : W * 0.12
109
- ;['黑', '街'].forEach((c, i) => textBlock(ctx, c, x, H * 0.3 + i * size * 1.05, size, FONT.black, '#fff', { shadow: PALETTE.red, stroke: 'rgba(80,0,10,0.6)' }))
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
@@ -124,8 +121,8 @@ export const DESIGNS: CoverDesign[] = [
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' })
@@ -156,23 +153,19 @@ export const DESIGNS: CoverDesign[] = [
156
  },
157
  },
158
  {
159
- id: 'race',
160
- name: '飙车光轨',
161
- t: 112.6,
162
  overlay(ctx, W, H) {
163
  const u = S(W, H)
164
  ctx.save()
165
- ctx.translate(W / 2, H * 0.24)
166
- ctx.rotate(-0.08)
167
- ctx.fillStyle = PALETTE.red
168
- ctx.fillRect(-W, -u * 70, W * 2, u * 140)
169
- ctx.restore()
170
- ctx.save()
171
- ctx.translate(W / 2, H * 0.24)
172
- ctx.rotate(-0.08)
173
- textBlock(ctx, '油门到底 · 别回头', 0, 0, u * 92, FONT.black, '#fff')
174
  ctx.restore()
175
- textBlock(ctx, '黑街 BLACK STREET', W / 2, H - u * 100, u * 50, FONT.black, PALETTE.bone, { stroke: 'rgba(0,0,0,0.7)' })
176
  },
177
  },
178
  ]
 
1
+ import { BAR, BEAT, DROP1, DROP2 } from '../engine/audio'
2
  import { Renderer } from '../engine/renderer'
3
  import { FONT, PALETTE } from '../engine/util'
4
 
 
82
  },
83
  {
84
  id: 'street',
85
+ name: '雨夜骑行',
86
  t: 13.2,
87
  overlay(ctx, W, H) {
88
  const u = S(W, H)
 
98
  },
99
  },
100
  {
101
+ id: 'reverse',
102
+ name: '倒车闪灯',
103
+ t: DROP1 + 10 * BEAT + 8 * BAR + 0.06,
104
  overlay(ctx, W, H) {
105
  const u = S(W, H)
106
+ badge(ctx, '公路对决', u * 50, u * 50, u * 38, PALETTE.red, '#fff')
107
+ textBlock(ctx, '倒车 · 闪灯', W / 2, H - u * 140, u * 96, FONT.black, '#fff', { stroke: '#000' })
 
 
 
108
  },
109
  },
110
  {
111
  id: 'hero',
112
  name: '阿飞特写',
113
+ t: 97.6,
114
  overlay(ctx, W, H) {
115
  const u = S(W, H)
116
  const P = H > W
 
121
  },
122
  {
123
  id: 'letter',
124
+ name: '灯下烧报纸',
125
+ t: 103.4,
126
  overlay(ctx, W, H) {
127
  const u = S(W, H)
128
  textBlock(ctx, '烧掉它,再出发', W / 2, u * 120, u * 72, FONT.black, '#fff', { shadow: '#ff7a2e' })
 
153
  },
154
  },
155
  {
156
+ id: 'jump',
157
+ name: '喷射飞越',
158
+ t: DROP2 + 3 * BAR + 5 * BEAT,
159
  overlay(ctx, W, H) {
160
  const u = S(W, H)
161
  ctx.save()
162
+ ctx.translate(W / 2, H * 0.16)
163
+ ctx.rotate(-0.06)
164
+ ctx.fillStyle = PALETTE.cyan
165
+ ctx.fillRect(-W, -u * 60, W * 2, u * 120)
166
+ textBlock(ctx, '喷射 · 飞越', 0, 0, u * 84, FONT.black, '#05060a')
 
 
 
 
167
  ctx.restore()
168
+ textBlock(ctx, '黑街 BLACK STREET', W / 2, H - u * 90, u * 46, FONT.black, PALETTE.bone, { stroke: 'rgba(0,0,0,0.7)' })
169
  },
170
  },
171
  ]
src/mv/engine/cars.ts ADDED
@@ -0,0 +1,693 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Cars for the highway stories:
2
+ // • hero: 阿飞's small boxy white hatchback (blue stripe, black lower body),
3
+ // optional under-body jet kit (two swivelling nozzles)
4
+ // • rival: the provoking red sports car (white roof, black stripe, rear wing)
5
+ // Each car can be drawn side-on, top-down, from the rear and (hero) from the front.
6
+ import { glowBlob, lightCone } from './draw'
7
+ import { HERO, circle, frontHead, heroHead, ink, withPalette } from './hero'
8
+ import { clamp, hash, rgba } from './util'
9
+
10
+ type C2D = CanvasRenderingContext2D
11
+ export type CarKind = 'hero' | 'rival'
12
+
13
+ export const CAR = {
14
+ hero: { body: '#eee9de', shade: '#c8c1b2', lower: '#1d1e23', stripe: '#2f5a86', glass: '#1b2632', glassHi: '#6b8aa4', roof: '#eee9de' },
15
+ rival: { body: '#c9142d', shade: '#8c0d1f', lower: '#141418', stripe: '#121216', glass: '#121a24', glassHi: '#4f6a80', roof: '#f3f1ea' },
16
+ }
17
+
18
+ const LINE = '#07080b'
19
+
20
+ function poly(ctx: C2D, L: number, pts: [number, number][]) {
21
+ ctx.beginPath()
22
+ pts.forEach(([x, y], i) => (i ? ctx.lineTo(x * L, y * L) : ctx.moveTo(x * L, y * L)))
23
+ ctx.closePath()
24
+ }
25
+
26
+ function alloy(ctx: C2D, cx: number, cy: number, R: number, spin: number, lw: number) {
27
+ ctx.beginPath()
28
+ ctx.arc(cx, cy, R, 0, Math.PI * 2)
29
+ ink(ctx, '#0b0b0d', lw)
30
+ ctx.beginPath()
31
+ ctx.arc(cx, cy, R * 0.62, 0, Math.PI * 2)
32
+ ink(ctx, '#aab2bc', lw)
33
+ ctx.fillStyle = '#2a2e35'
34
+ for (let k = 0; k < 5; k++) {
35
+ const a = spin + (k / 5) * Math.PI * 2
36
+ ctx.beginPath()
37
+ ctx.moveTo(cx + Math.cos(a - 0.22) * R * 0.18, cy + Math.sin(a - 0.22) * R * 0.18)
38
+ ctx.lineTo(cx + Math.cos(a - 0.3) * R * 0.55, cy + Math.sin(a - 0.3) * R * 0.55)
39
+ ctx.lineTo(cx + Math.cos(a + 0.3) * R * 0.55, cy + Math.sin(a + 0.3) * R * 0.55)
40
+ ctx.lineTo(cx + Math.cos(a + 0.22) * R * 0.18, cy + Math.sin(a + 0.22) * R * 0.18)
41
+ ctx.closePath()
42
+ ctx.fill()
43
+ }
44
+ circle(ctx, { x: cx, y: cy }, R * 0.14, '#d5dbe2', lw)
45
+ }
46
+
47
+ // ------------------------------------------------------------------ jet flame
48
+ /** Thrust plume. (x,y) nozzle exit, angle = direction the gas travels. */
49
+ export function jetFlame(ctx: C2D, x: number, y: number, angle: number, len: number, width: number, t: number, groundY?: number) {
50
+ if (len <= 1) return
51
+ const flick = 0.85 + 0.15 * Math.sin(t * 47) + 0.08 * Math.sin(t * 71)
52
+ const Lf = len * flick
53
+ ctx.save()
54
+ ctx.globalCompositeOperation = 'lighter'
55
+ glowBlob(ctx, x, y, width * 3, '#7fd8ff', 0.5)
56
+ ctx.translate(x, y)
57
+ ctx.rotate(angle)
58
+ const layers: [string, number, number][] = [
59
+ ['rgba(60,140,255,0.55)', 1, 1],
60
+ ['rgba(120,220,255,0.75)', 0.72, 0.65],
61
+ ['rgba(255,255,255,0.95)', 0.42, 0.32],
62
+ ]
63
+ for (const [c, lk, wk] of layers) {
64
+ ctx.fillStyle = c
65
+ ctx.beginPath()
66
+ ctx.moveTo(0, -width * 0.5 * wk)
67
+ ctx.quadraticCurveTo(Lf * lk * 0.6, -width * 0.65 * wk, Lf * lk, 0)
68
+ ctx.quadraticCurveTo(Lf * lk * 0.6, width * 0.65 * wk, 0, width * 0.5 * wk)
69
+ ctx.closePath()
70
+ ctx.fill()
71
+ }
72
+ // shock diamonds
73
+ ctx.fillStyle = 'rgba(255,255,255,0.7)'
74
+ for (let k = 1; k <= 3; k++) {
75
+ const px = Lf * 0.18 * k
76
+ ctx.beginPath()
77
+ ctx.ellipse(px, 0, width * 0.12, width * 0.2, 0, 0, Math.PI * 2)
78
+ ctx.fill()
79
+ }
80
+ ctx.restore()
81
+ // gas hitting the ground: dust + spray
82
+ if (groundY !== undefined) {
83
+ const ex = x + Math.cos(angle) * Lf
84
+ const ey = y + Math.sin(angle) * Lf
85
+ if (ey >= groundY - width) {
86
+ const hitX = x + Math.cos(angle) * ((groundY - y) / Math.max(0.05, Math.sin(angle)))
87
+ ctx.save()
88
+ ctx.globalCompositeOperation = 'lighter'
89
+ glowBlob(ctx, hitX, groundY, width * 3.5, '#9fdcff', 0.45)
90
+ ctx.restore()
91
+ for (let k = 0; k < 18; k++) {
92
+ const life = (t * (1.5 + hash(k)) + hash(k * 3.1)) % 1
93
+ const dir = k % 2 ? 1 : -1
94
+ ctx.fillStyle = `rgba(200,210,225,${0.35 * (1 - life)})`
95
+ ctx.beginPath()
96
+ ctx.arc(hitX + dir * life * width * (3 + 4 * hash(k * 2)), groundY - life * width * (0.6 + hash(k * 5)), width * (0.25 + life * 0.6), 0, Math.PI * 2)
97
+ ctx.fill()
98
+ }
99
+ }
100
+ void ex
101
+ }
102
+ }
103
+
104
+ // ------------------------------------------------------------------ side view
105
+ export interface SideOpts {
106
+ spin?: number
107
+ head?: number
108
+ brake?: number
109
+ /** jet kit: power 0..1, angle of the gas flow (π/2 = straight down, π = backwards) */
110
+ jet?: { power: number; angle: number }
111
+ jetKit?: boolean
112
+ t?: number
113
+ /** driver looks up (rival, when the hero flies over) */
114
+ look?: number
115
+ groundY?: number
116
+ }
117
+
118
+ /** Side view, facing +x. (x,y) = ground point under the car centre, L = car length in px. pitch in radians (nose up negative). */
119
+ export function carSide(ctx: C2D, kind: CarKind, x: number, y: number, L: number, pitch: number, o: SideOpts = {}) {
120
+ const c = CAR[kind]
121
+ const lw = Math.max(1, L * 0.006)
122
+ const t = o.t ?? 0
123
+ const R = L * (kind === 'hero' ? 0.115 : 0.11)
124
+ const wheelsX = kind === 'hero' ? [-0.31, 0.31] : [-0.32, 0.33]
125
+ ctx.save()
126
+ ctx.translate(x, y)
127
+ ctx.rotate(pitch)
128
+ ctx.lineJoin = 'round'
129
+ // headlight beam
130
+ if ((o.head ?? 1) > 0.05) lightCone(ctx, L * 0.5, -L * 0.26, L * 2.6, 0.16, -Math.PI / 2, '#fff2c8', 0.18 * (o.head ?? 1))
131
+ const body: [number, number][] =
132
+ kind === 'hero'
133
+ ? [
134
+ [-0.5, -0.13],
135
+ [-0.5, -0.31],
136
+ [-0.45, -0.345],
137
+ [0.2, -0.345],
138
+ [0.47, -0.3],
139
+ [0.5, -0.25],
140
+ [0.5, -0.13],
141
+ [0.46, -0.1],
142
+ [-0.47, -0.1],
143
+ ]
144
+ : [
145
+ [-0.5, -0.12],
146
+ [-0.5, -0.27],
147
+ [-0.44, -0.3],
148
+ [-0.2, -0.31],
149
+ [0.22, -0.3],
150
+ [0.42, -0.24],
151
+ [0.5, -0.2],
152
+ [0.5, -0.12],
153
+ [0.45, -0.09],
154
+ [-0.46, -0.09],
155
+ ]
156
+ const cabin: [number, number][] =
157
+ kind === 'hero'
158
+ ? [
159
+ [-0.45, -0.34],
160
+ [-0.41, -0.53],
161
+ [0.0, -0.545],
162
+ [0.05, -0.535],
163
+ [0.21, -0.34],
164
+ ]
165
+ : [
166
+ [-0.33, -0.3],
167
+ [-0.14, -0.42],
168
+ [0.06, -0.425],
169
+ [0.25, -0.3],
170
+ ]
171
+ // cabin + glass
172
+ poly(ctx, L, cabin)
173
+ ink(ctx, c.roof, lw)
174
+ const windows: [number, number][][] =
175
+ kind === 'hero'
176
+ ? [
177
+ [
178
+ [-0.41, -0.355],
179
+ [-0.385, -0.505],
180
+ [-0.15, -0.515],
181
+ [-0.15, -0.355],
182
+ ],
183
+ [
184
+ [-0.125, -0.355],
185
+ [-0.125, -0.515],
186
+ [0.0, -0.52],
187
+ [0.18, -0.355],
188
+ ],
189
+ ]
190
+ : [
191
+ [
192
+ [-0.29, -0.31],
193
+ [-0.135, -0.405],
194
+ [0.05, -0.41],
195
+ [0.21, -0.31],
196
+ ],
197
+ ]
198
+ for (const w of windows) {
199
+ poly(ctx, L, w)
200
+ ink(ctx, c.glass, lw)
201
+ }
202
+ // driver inside the front window
203
+ ctx.save()
204
+ poly(ctx, L, windows[windows.length - 1])
205
+ ctx.clip()
206
+ if (kind === 'hero') {
207
+ heroHead(ctx, -0.045 * L, -0.44 * L, 0.058 * L, 1, { t, eyes: 'open', wind: 0.1 })
208
+ } else {
209
+ const hx = -0.02 * L
210
+ const hy = -0.355 * L
211
+ const hr = 0.045 * L
212
+ ctx.save()
213
+ ctx.translate(hx, hy)
214
+ ctx.rotate(-(o.look ?? 0) * 0.5)
215
+ ctx.beginPath()
216
+ ctx.arc(0, 0, hr, 0, Math.PI * 2)
217
+ ink(ctx, '#c99a74', lw)
218
+ ctx.beginPath()
219
+ ctx.moveTo(-hr * 1.05, -hr * 0.1)
220
+ ctx.quadraticCurveTo(0, -hr * 1.6, hr * 1.05, -hr * 0.2)
221
+ ctx.lineTo(hr * 1.7, -hr * 0.05)
222
+ ctx.lineTo(hr * 1.0, hr * 0.05)
223
+ ctx.closePath()
224
+ ink(ctx, '#111216', lw)
225
+ ctx.fillStyle = '#111'
226
+ ctx.fillRect(hr * 0.15, -hr * 0.05, hr * 0.7, hr * 0.22)
227
+ ctx.restore()
228
+ }
229
+ // glare across the glass
230
+ ctx.fillStyle = rgba(c.glassHi, 0.35)
231
+ ctx.beginPath()
232
+ ctx.moveTo(-0.5 * L, -0.3 * L)
233
+ ctx.lineTo(-0.35 * L, -0.6 * L)
234
+ ctx.lineTo(-0.28 * L, -0.6 * L)
235
+ ctx.lineTo(-0.43 * L, -0.3 * L)
236
+ ctx.fill()
237
+ ctx.restore()
238
+ // body
239
+ poly(ctx, L, body)
240
+ ink(ctx, c.body, lw)
241
+ ctx.save()
242
+ poly(ctx, L, body)
243
+ ctx.clip()
244
+ ctx.fillStyle = c.lower
245
+ ctx.fillRect(-0.6 * L, -0.19 * L, 1.2 * L, 0.2 * L)
246
+ ctx.fillStyle = c.stripe
247
+ ctx.fillRect(-0.6 * L, (kind === 'hero' ? -0.265 : -0.215) * L, 1.2 * L, 0.022 * L)
248
+ ctx.fillStyle = rgba('#ffffff', 0.25)
249
+ ctx.fillRect(-0.6 * L, -0.33 * L, 1.2 * L, 0.012 * L)
250
+ ctx.restore()
251
+ // wheel arches
252
+ for (const wx of wheelsX) {
253
+ ctx.beginPath()
254
+ ctx.arc(wx * L, -R, R * 1.18, Math.PI, 0)
255
+ ctx.closePath()
256
+ ink(ctx, '#0a0b0e', lw)
257
+ }
258
+ // details: door, handle, mirror, lights, bumpers
259
+ ctx.strokeStyle = rgba(LINE, 0.7)
260
+ ctx.lineWidth = lw
261
+ ctx.beginPath()
262
+ ctx.moveTo(-0.14 * L, -0.34 * L)
263
+ ctx.lineTo(-0.14 * L, -0.12 * L)
264
+ ctx.moveTo(0.19 * L, -0.34 * L)
265
+ ctx.lineTo(0.19 * L, -0.14 * L)
266
+ ctx.stroke()
267
+ ctx.fillStyle = '#2a2d33'
268
+ ctx.fillRect(-0.09 * L, -0.3 * L, 0.05 * L, 0.012 * L)
269
+ poly(ctx, L, [
270
+ [0.15, -0.355],
271
+ [0.2, -0.385],
272
+ [0.215, -0.355],
273
+ ])
274
+ ink(ctx, c.lower, lw)
275
+ const headOn = o.head ?? 1
276
+ poly(ctx, L, [
277
+ [0.475, -0.3],
278
+ [0.505, -0.255],
279
+ [0.505, -0.235],
280
+ [0.47, -0.24],
281
+ ])
282
+ ink(ctx, headOn > 0.1 ? '#fff4cf' : '#8a8f96', lw)
283
+ if (headOn > 0.1) glowBlob(ctx, 0.5 * L, -0.26 * L, L * 0.12, '#fff1c8', 0.9 * headOn)
284
+ const tail = kind === 'hero' ? -0.31 : -0.27
285
+ poly(ctx, L, [
286
+ [-0.505, tail],
287
+ [-0.48, tail],
288
+ [-0.48, tail + 0.05],
289
+ [-0.505, tail + 0.05],
290
+ ])
291
+ ink(ctx, '#ff2d55', lw)
292
+ glowBlob(ctx, -0.5 * L, (tail + 0.025) * L, L * (0.08 + 0.1 * (o.brake ?? 0)), '#ff2d55', 0.6 + 0.4 * (o.brake ?? 0))
293
+ if (kind === 'rival') {
294
+ // rear wing
295
+ ctx.fillStyle = c.lower
296
+ ctx.fillRect(-0.46 * L, -0.36 * L, 0.012 * L, 0.06 * L)
297
+ ctx.fillRect(-0.39 * L, -0.36 * L, 0.012 * L, 0.06 * L)
298
+ poly(ctx, L, [
299
+ [-0.52, -0.38],
300
+ [-0.35, -0.37],
301
+ [-0.35, -0.355],
302
+ [-0.52, -0.36],
303
+ ])
304
+ ink(ctx, c.lower, lw)
305
+ }
306
+ // jet kit nozzles under the chassis
307
+ const jets: { x: number; y: number }[] = []
308
+ if (kind === 'hero' && o.jetKit) {
309
+ const ang = o.jet?.angle ?? Math.PI / 2
310
+ for (const jx of [-0.17, 0.12]) {
311
+ const px = jx * L
312
+ const py = -0.085 * L
313
+ ctx.beginPath()
314
+ ctx.ellipse(px, py - 0.012 * L, 0.05 * L, 0.018 * L, 0, 0, Math.PI * 2)
315
+ ink(ctx, '#2a2e36', lw)
316
+ ctx.save()
317
+ ctx.translate(px, py)
318
+ ctx.rotate(ang - Math.PI / 2)
319
+ ctx.beginPath()
320
+ ctx.moveTo(-0.02 * L, 0)
321
+ ctx.lineTo(0.02 * L, 0)
322
+ ctx.lineTo(0.026 * L, 0.04 * L)
323
+ ctx.lineTo(-0.026 * L, 0.04 * L)
324
+ ctx.closePath()
325
+ ink(ctx, '#9aa3ad', lw)
326
+ ctx.restore()
327
+ jets.push({ x: px + Math.cos(ang) * 0.04 * L, y: py + Math.sin(ang) * 0.04 * L })
328
+ }
329
+ }
330
+ // wheels (suspension already in the car's pose)
331
+ for (const wx of wheelsX) alloy(ctx, wx * L, -R, R, o.spin ?? 0, lw)
332
+ ctx.restore()
333
+ // jet flames are drawn in world space so the ground interaction is right
334
+ if (jets.length && o.jet && o.jet.power > 0.02) {
335
+ const cs = Math.cos(pitch)
336
+ const sn = Math.sin(pitch)
337
+ for (const j of jets) {
338
+ const wx = x + j.x * cs - j.y * sn
339
+ const wy = y + j.x * sn + j.y * cs
340
+ jetFlame(ctx, wx, wy, o.jet.angle + pitch, L * 0.55 * o.jet.power, L * 0.07, t, o.groundY)
341
+ }
342
+ }
343
+ }
344
+
345
+ // ------------------------------------------------------------------ top-down view
346
+ export interface TopOpts {
347
+ head?: number
348
+ high?: number
349
+ brake?: number
350
+ }
351
+
352
+ /** Top-down. (x,y) centre, heading 0 = facing up the screen. k = px per metre. */
353
+ export function carTop(ctx: C2D, kind: CarKind, x: number, y: number, k: number, heading: number, o: TopOpts = {}) {
354
+ const c = CAR[kind]
355
+ const Lm = kind === 'hero' ? 4.0 : 4.5
356
+ const Wm = kind === 'hero' ? 1.75 : 1.9
357
+ const L = Lm * k
358
+ const W = Wm * k
359
+ const hw = W / 2
360
+ const hl = L / 2
361
+ const lw = Math.max(1, k * 0.05)
362
+ ctx.save()
363
+ ctx.translate(x, y)
364
+ ctx.rotate(heading)
365
+ // headlight beams (forward = -y)
366
+ const head = o.head ?? 1
367
+ const high = o.high ?? 0
368
+ if (head > 0.02 || high > 0.02) {
369
+ ctx.save()
370
+ ctx.globalCompositeOperation = 'lighter'
371
+ for (const sd of [-1, 1]) lightCone(ctx, sd * hw * 0.62, -hl, k * (14 + 26 * high), 0.22 + 0.06 * high, Math.PI, '#fff2c8', 0.16 * head + 0.5 * high)
372
+ if (high > 0.05) glowBlob(ctx, 0, -hl, k * (3 + 6 * high), '#ffffff', 0.9 * high)
373
+ ctx.restore()
374
+ }
375
+ // drop shadow (gives the body some height)
376
+ ctx.fillStyle = 'rgba(0,0,0,0.55)'
377
+ ctx.beginPath()
378
+ ctx.roundRect(-hw * 1.02 + k * 0.25, -hl + k * 0.3, W * 1.04, L, hw * 0.6)
379
+ ctx.fill()
380
+ // tyres (stick out a little past the body)
381
+ for (const ty of [-0.62, 0.62]) {
382
+ for (const sd of [-1, 1]) {
383
+ ctx.beginPath()
384
+ ctx.roundRect(sd * hw - (sd > 0 ? hw * 0.12 : hw * 0.06), ty * hl - hl * 0.15, hw * 0.18, hl * 0.3, hw * 0.05)
385
+ ink(ctx, '#0b0b0d', lw)
386
+ }
387
+ }
388
+ // body outline: rounded nose, wheel-arch bulges, squarer tail
389
+ const body = () => {
390
+ ctx.beginPath()
391
+ ctx.moveTo(-hw * 0.72, -hl)
392
+ ctx.quadraticCurveTo(0, -hl * 1.05, hw * 0.72, -hl)
393
+ ctx.quadraticCurveTo(hw * 0.98, -hl * 0.97, hw * 0.98, -hl * 0.8)
394
+ ctx.quadraticCurveTo(hw * 1.04, -hl * 0.62, hw * 0.97, -hl * 0.42)
395
+ ctx.lineTo(hw * 0.95, hl * 0.42)
396
+ ctx.quadraticCurveTo(hw * 1.04, hl * 0.62, hw * 0.98, hl * 0.82)
397
+ ctx.quadraticCurveTo(hw * 0.96, hl, hw * 0.75, hl)
398
+ ctx.lineTo(-hw * 0.75, hl)
399
+ ctx.quadraticCurveTo(-hw * 0.96, hl, -hw * 0.98, hl * 0.82)
400
+ ctx.quadraticCurveTo(-hw * 1.04, hl * 0.62, -hw * 0.95, hl * 0.42)
401
+ ctx.lineTo(-hw * 0.97, -hl * 0.42)
402
+ ctx.quadraticCurveTo(-hw * 1.04, -hl * 0.62, -hw * 0.98, -hl * 0.8)
403
+ ctx.quadraticCurveTo(-hw * 0.98, -hl * 0.97, -hw * 0.72, -hl)
404
+ ctx.closePath()
405
+ }
406
+ body()
407
+ const g = ctx.createLinearGradient(-hw, 0, hw, 0)
408
+ g.addColorStop(0, c.shade)
409
+ g.addColorStop(0.25, c.body)
410
+ g.addColorStop(0.6, c.body)
411
+ g.addColorStop(1, c.shade)
412
+ ink(ctx, g as unknown as string, lw)
413
+ ctx.save()
414
+ body()
415
+ ctx.clip()
416
+ // racing stripes over hood, roof and boot
417
+ ctx.fillStyle = c.stripe
418
+ ctx.fillRect(-hw * 0.3, -hl, hw * 0.18, L)
419
+ ctx.fillRect(hw * 0.12, -hl, hw * 0.18, L)
420
+ ctx.restore()
421
+ // hood crease lines
422
+ ctx.strokeStyle = rgba(LINE, 0.35)
423
+ ctx.lineWidth = lw
424
+ ctx.beginPath()
425
+ ctx.moveTo(-hw * 0.5, -hl * 0.92)
426
+ ctx.lineTo(-hw * 0.55, -hl * 0.45)
427
+ ctx.moveTo(hw * 0.5, -hl * 0.92)
428
+ ctx.lineTo(hw * 0.55, -hl * 0.45)
429
+ ctx.stroke()
430
+ // greenhouse: windscreen, roof, rear glass
431
+ const wsTop = kind === 'hero' ? -hl * 0.42 : -hl * 0.32
432
+ const wsBot = kind === 'hero' ? -hl * 0.12 : -hl * 0.02
433
+ const roofEnd = kind === 'hero' ? hl * 0.5 : hl * 0.3
434
+ const rearEnd = kind === 'hero' ? hl * 0.68 : hl * 0.62
435
+ const gl = ctx.createLinearGradient(0, wsTop, 0, wsBot)
436
+ gl.addColorStop(0, '#2a3e52')
437
+ gl.addColorStop(1, c.glass)
438
+ ctx.beginPath()
439
+ ctx.moveTo(-hw * 0.8, wsTop)
440
+ ctx.quadraticCurveTo(0, wsTop - hl * 0.06, hw * 0.8, wsTop)
441
+ ctx.lineTo(hw * 0.74, wsBot)
442
+ ctx.lineTo(-hw * 0.74, wsBot)
443
+ ctx.closePath()
444
+ ink(ctx, gl as unknown as string, lw)
445
+ ctx.fillStyle = 'rgba(200,225,245,0.35)'
446
+ ctx.beginPath()
447
+ ctx.moveTo(-hw * 0.5, wsTop + (wsBot - wsTop) * 0.15)
448
+ ctx.lineTo(-hw * 0.2, wsTop + (wsBot - wsTop) * 0.15)
449
+ ctx.lineTo(-hw * 0.45, wsBot - (wsBot - wsTop) * 0.1)
450
+ ctx.lineTo(-hw * 0.65, wsBot - (wsBot - wsTop) * 0.1)
451
+ ctx.closePath()
452
+ ctx.fill()
453
+ // side windows (thin strips)
454
+ ctx.fillStyle = c.glass
455
+ ctx.fillRect(-hw * 0.86, wsBot, hw * 0.1, roofEnd - wsBot)
456
+ ctx.fillRect(hw * 0.76, wsBot, hw * 0.1, roofEnd - wsBot)
457
+ // roof
458
+ ctx.beginPath()
459
+ ctx.roundRect(-hw * 0.74, wsBot, W * 0.74, roofEnd - wsBot, hw * 0.12)
460
+ ink(ctx, c.roof, lw)
461
+ ctx.fillStyle = 'rgba(255,255,255,0.18)'
462
+ ctx.fillRect(-hw * 0.6, wsBot + k * 0.15, hw * 0.25, roofEnd - wsBot - k * 0.3)
463
+ if (kind === 'hero') {
464
+ ctx.fillStyle = c.stripe
465
+ ctx.fillRect(-hw * 0.3, wsBot, hw * 0.18, roofEnd - wsBot)
466
+ ctx.fillRect(hw * 0.12, wsBot, hw * 0.18, roofEnd - wsBot)
467
+ }
468
+ ctx.beginPath()
469
+ ctx.moveTo(-hw * 0.74, roofEnd)
470
+ ctx.lineTo(hw * 0.74, roofEnd)
471
+ ctx.lineTo(hw * 0.7, rearEnd)
472
+ ctx.lineTo(-hw * 0.7, rearEnd)
473
+ ctx.closePath()
474
+ ink(ctx, c.glass, lw)
475
+ // door seams + mirrors
476
+ ctx.strokeStyle = rgba(LINE, 0.5)
477
+ ctx.beginPath()
478
+ ctx.moveTo(-hw * 0.97, wsBot + (roofEnd - wsBot) * 0.45)
479
+ ctx.lineTo(-hw * 0.86, wsBot + (roofEnd - wsBot) * 0.45)
480
+ ctx.moveTo(hw * 0.97, wsBot + (roofEnd - wsBot) * 0.45)
481
+ ctx.lineTo(hw * 0.86, wsBot + (roofEnd - wsBot) * 0.45)
482
+ ctx.stroke()
483
+ for (const sd of [-1, 1]) {
484
+ ctx.beginPath()
485
+ ctx.ellipse(sd * hw * 1.1, wsBot - k * 0.05, hw * 0.16, k * 0.14, sd * 0.3, 0, Math.PI * 2)
486
+ ink(ctx, c.lower, lw)
487
+ }
488
+ // lights
489
+ const lit = head > 0.05 || high > 0.05
490
+ for (const sd of [-1, 1]) {
491
+ ctx.beginPath()
492
+ ctx.ellipse(sd * hw * 0.62, -hl * 0.96, hw * 0.18, k * 0.12, 0, 0, Math.PI * 2)
493
+ ink(ctx, lit ? '#fff6d6' : '#9aa0a8', lw)
494
+ }
495
+ const br = o.brake ?? 0
496
+ for (const sd of [-1, 1]) {
497
+ ctx.beginPath()
498
+ ctx.roundRect(sd * hw * 0.62 - hw * 0.2, hl * 0.95, hw * 0.4, k * 0.12, k * 0.04)
499
+ ink(ctx, '#ff2d55', lw)
500
+ glowBlob(ctx, sd * hw * 0.62, hl, k * (0.8 + 1.6 * br), '#ff2d55', 0.6 + 0.4 * br)
501
+ }
502
+ if (kind === 'rival') {
503
+ // rear wing
504
+ ctx.beginPath()
505
+ ctx.roundRect(-hw * 1.02, hl * 0.78, W * 1.02, k * 0.22, k * 0.05)
506
+ ink(ctx, c.lower, lw)
507
+ }
508
+ ctx.restore()
509
+ }
510
+
511
+ // ------------------------------------------------------------------ rear / front views (for POV shots)
512
+ /** Rear view. (cx, groundY) bottom centre, w = car width in px. */
513
+ export function carRear(ctx: C2D, kind: CarKind, cx: number, groundY: number, w: number, o: { brake?: number; pop?: number; jet?: number; t?: number } = {}) {
514
+ const c = CAR[kind]
515
+ const lw = Math.max(1, w * 0.008)
516
+ const t = o.t ?? 0
517
+ const hgt = kind === 'hero' ? 0.62 : 0.5
518
+ const top = groundY - w * hgt
519
+ ctx.save()
520
+ ctx.lineJoin = 'round'
521
+ ctx.fillStyle = 'rgba(0,0,0,0.5)'
522
+ ctx.beginPath()
523
+ ctx.ellipse(cx, groundY, w * 0.58, w * 0.06, 0, 0, Math.PI * 2)
524
+ ctx.fill()
525
+ // tyres
526
+ ctx.fillStyle = '#0a0a0c'
527
+ ctx.fillRect(cx - w * 0.47, groundY - w * 0.14, w * 0.16, w * 0.14)
528
+ ctx.fillRect(cx + w * 0.31, groundY - w * 0.14, w * 0.16, w * 0.14)
529
+ // cabin + rear glass
530
+ ctx.beginPath()
531
+ ctx.moveTo(cx - w * 0.42, top + w * (hgt - 0.3))
532
+ ctx.lineTo(cx - w * 0.33, top)
533
+ ctx.lineTo(cx + w * 0.33, top)
534
+ ctx.lineTo(cx + w * 0.42, top + w * (hgt - 0.3))
535
+ ctx.closePath()
536
+ ink(ctx, c.roof, lw)
537
+ ctx.beginPath()
538
+ ctx.moveTo(cx - w * 0.37, top + w * (hgt - 0.31))
539
+ ctx.lineTo(cx - w * 0.3, top + w * 0.04)
540
+ ctx.lineTo(cx + w * 0.3, top + w * 0.04)
541
+ ctx.lineTo(cx + w * 0.37, top + w * (hgt - 0.31))
542
+ ctx.closePath()
543
+ ink(ctx, c.glass, lw)
544
+ // driver's head seen through the glass
545
+ ctx.fillStyle = kind === 'hero' ? HERO.hair : '#111216'
546
+ ctx.beginPath()
547
+ ctx.arc(cx - w * 0.14, top + w * (hgt - 0.38) + w * 0.06, w * (kind === 'hero' ? 0.1 : 0.07), 0, Math.PI * 2)
548
+ ctx.fill()
549
+ // body
550
+ ctx.beginPath()
551
+ ctx.roundRect(cx - w / 2, top + w * (hgt - 0.32), w, w * 0.25, w * 0.04)
552
+ ink(ctx, c.body, lw)
553
+ ctx.fillStyle = c.lower
554
+ ctx.fillRect(cx - w / 2, groundY - w * 0.12, w, w * 0.06)
555
+ ctx.fillStyle = c.stripe
556
+ ctx.fillRect(cx - w * 0.13, top + w * (hgt - 0.32), w * 0.08, w * 0.25)
557
+ ctx.fillRect(cx + w * 0.05, top + w * (hgt - 0.32), w * 0.08, w * 0.25)
558
+ // tail lights
559
+ const br = o.brake ?? 0
560
+ const ly = top + w * (hgt - 0.27)
561
+ for (const sd of [-1, 1]) {
562
+ ctx.beginPath()
563
+ if (kind === 'rival') ctx.rect(cx + sd * w * 0.47 - (sd > 0 ? w * 0.27 : 0), ly, w * 0.27, w * 0.045)
564
+ else ctx.rect(cx + sd * w * 0.44 - (sd > 0 ? w * 0.09 : 0), ly - w * 0.02, w * 0.09, w * 0.1)
565
+ ink(ctx, br > 0.3 ? '#ff5a78' : '#d0183c', lw)
566
+ glowBlob(ctx, cx + sd * w * 0.36, ly + w * 0.03, w * (0.12 + 0.25 * br), '#ff2d55', 0.6 + 0.4 * br)
567
+ }
568
+ // plate
569
+ ctx.beginPath()
570
+ ctx.rect(cx - w * 0.11, groundY - w * 0.2, w * 0.22, w * 0.07)
571
+ ink(ctx, '#e8e2d6', lw)
572
+ if (kind === 'rival') {
573
+ // wing
574
+ ctx.fillStyle = c.lower
575
+ ctx.fillRect(cx - w * 0.3, top + w * (hgt - 0.38), w * 0.03, w * 0.07)
576
+ ctx.fillRect(cx + w * 0.27, top + w * (hgt - 0.38), w * 0.03, w * 0.07)
577
+ ctx.beginPath()
578
+ ctx.rect(cx - w * 0.52, top + w * (hgt - 0.41), w * 1.04, w * 0.04)
579
+ ink(ctx, c.lower, lw)
580
+ }
581
+ // exhausts with backfire pops
582
+ const pop = o.pop ?? 0
583
+ for (const sd of [-1, 1]) {
584
+ const ex = cx + sd * w * 0.3
585
+ const ey = groundY - w * 0.08
586
+ circle(ctx, { x: ex, y: ey }, w * 0.03, '#8a929c', lw)
587
+ if (pop > 0.05) {
588
+ ctx.save()
589
+ ctx.globalCompositeOperation = 'lighter'
590
+ glowBlob(ctx, ex, ey, w * 0.2 * pop, '#ff7a2e', 0.9)
591
+ glowBlob(ctx, ex, ey, w * 0.08 * pop, '#ffe08a', 1)
592
+ ctx.restore()
593
+ }
594
+ }
595
+ // hero jet boost seen from behind
596
+ if (kind === 'hero' && (o.jet ?? 0) > 0.02) {
597
+ ctx.save()
598
+ ctx.globalCompositeOperation = 'lighter'
599
+ for (const sd of [-1, 1]) {
600
+ const jx = cx + sd * w * 0.18
601
+ const jy = groundY - w * 0.04
602
+ glowBlob(ctx, jx, jy, w * 0.5 * (o.jet ?? 0), '#7fd8ff', 0.9)
603
+ glowBlob(ctx, jx, jy, w * 0.15 * (o.jet ?? 0), '#ffffff', 1)
604
+ }
605
+ ctx.restore()
606
+ }
607
+ ctx.restore()
608
+ void t
609
+ }
610
+
611
+ /** Front view of the hero hatchback (seen from the rival's car when he drives in reverse). */
612
+ export function heroCarFront(ctx: C2D, cx: number, groundY: number, w: number, o: { head?: number; high?: number; t?: number } = {}) {
613
+ const c = CAR.hero
614
+ const lw = Math.max(1, w * 0.008)
615
+ const t = o.t ?? 0
616
+ const top = groundY - w * 0.64
617
+ ctx.save()
618
+ ctx.lineJoin = 'round'
619
+ ctx.fillStyle = 'rgba(0,0,0,0.5)'
620
+ ctx.beginPath()
621
+ ctx.ellipse(cx, groundY, w * 0.58, w * 0.06, 0, 0, Math.PI * 2)
622
+ ctx.fill()
623
+ ctx.fillStyle = '#0a0a0c'
624
+ ctx.fillRect(cx - w * 0.47, groundY - w * 0.14, w * 0.16, w * 0.14)
625
+ ctx.fillRect(cx + w * 0.31, groundY - w * 0.14, w * 0.16, w * 0.14)
626
+ // cabin + windshield with 阿飞 inside
627
+ ctx.beginPath()
628
+ ctx.moveTo(cx - w * 0.43, top + w * 0.3)
629
+ ctx.lineTo(cx - w * 0.33, top)
630
+ ctx.lineTo(cx + w * 0.33, top)
631
+ ctx.lineTo(cx + w * 0.43, top + w * 0.3)
632
+ ctx.closePath()
633
+ ink(ctx, c.roof, lw)
634
+ ctx.save()
635
+ ctx.beginPath()
636
+ ctx.moveTo(cx - w * 0.38, top + w * 0.29)
637
+ ctx.lineTo(cx - w * 0.3, top + w * 0.04)
638
+ ctx.lineTo(cx + w * 0.3, top + w * 0.04)
639
+ ctx.lineTo(cx + w * 0.38, top + w * 0.29)
640
+ ctx.closePath()
641
+ ink(ctx, c.glass, lw)
642
+ ctx.clip()
643
+ frontHead(ctx, cx - w * 0.14, top + w * 0.2, w * 0.075, { t, eyes: 1, wind: 0 })
644
+ ctx.fillStyle = rgba(c.glassHi, 0.3)
645
+ ctx.beginPath()
646
+ ctx.moveTo(cx + w * 0.05, top)
647
+ ctx.lineTo(cx + w * 0.2, top)
648
+ ctx.lineTo(cx + w * 0.05, top + w * 0.3)
649
+ ctx.lineTo(cx - w * 0.1, top + w * 0.3)
650
+ ctx.fill()
651
+ ctx.restore()
652
+ // body, grille, round headlights, bumper
653
+ ctx.beginPath()
654
+ ctx.roundRect(cx - w / 2, top + w * 0.3, w, w * 0.26, w * 0.04)
655
+ ink(ctx, c.body, lw)
656
+ ctx.fillStyle = c.lower
657
+ ctx.fillRect(cx - w / 2, groundY - w * 0.14, w, w * 0.07)
658
+ ctx.beginPath()
659
+ ctx.rect(cx - w * 0.17, top + w * 0.38, w * 0.34, w * 0.09)
660
+ ink(ctx, '#202228', lw)
661
+ ctx.fillStyle = c.stripe
662
+ ctx.fillRect(cx - w * 0.13, top + w * 0.3, w * 0.08, w * 0.08)
663
+ ctx.fillRect(cx + w * 0.05, top + w * 0.3, w * 0.08, w * 0.08)
664
+ const head = o.head ?? 1
665
+ const high = o.high ?? 0
666
+ for (const sd of [-1, 1]) {
667
+ const hx = cx + sd * w * 0.33
668
+ const hy = top + w * 0.43
669
+ circle(ctx, { x: hx, y: hy }, w * 0.075, '#c9d0d8', lw)
670
+ circle(ctx, { x: hx, y: hy }, w * 0.055, head > 0.05 || high > 0.05 ? '#fff6d6' : '#7d858f', 0)
671
+ if (head > 0.05) glowBlob(ctx, hx, hy, w * 0.25, '#fff1c8', 0.8 * head)
672
+ }
673
+ ctx.restore()
674
+ if (high > 0.02) {
675
+ // high-beam glare + anamorphic streak
676
+ ctx.save()
677
+ ctx.globalCompositeOperation = 'lighter'
678
+ for (const sd of [-1, 1]) {
679
+ const hx = cx + sd * w * 0.33
680
+ const hy = top + w * 0.43
681
+ glowBlob(ctx, hx, hy, w * (0.6 + 1.6 * high), '#ffffff', clamp(high))
682
+ }
683
+ const g = ctx.createLinearGradient(cx - w * 3, 0, cx + w * 3, 0)
684
+ g.addColorStop(0, 'rgba(120,200,255,0)')
685
+ g.addColorStop(0.5, `rgba(200,235,255,${0.8 * high})`)
686
+ g.addColorStop(1, 'rgba(120,200,255,0)')
687
+ ctx.fillStyle = g
688
+ ctx.fillRect(cx - w * 3, top + w * 0.42, w * 6, w * 0.03)
689
+ ctx.restore()
690
+ }
691
+ }
692
+
693
+ export { withPalette }
src/mv/engine/hero.ts CHANGED
@@ -11,7 +11,7 @@
11
  // • Draw order is explicit (far limbs → bike → body → near limbs), so
12
  // nothing pokes through the bike.
13
  import { glowBlob, lightCone } from './draw'
14
- import { clamp, hash, rgba } from './util'
15
 
16
  type C2D = CanvasRenderingContext2D
17
  interface V {
@@ -43,6 +43,35 @@ export const HERO = {
43
  tire: '#0a0a0c',
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  /** standing height of the hero in bike units (bike wheelbase = 1) */
47
  export const HERO_H = 1.4
48
  /** total height of rider + bike in bike units (for layout) */
@@ -53,7 +82,7 @@ const add = (a: V, b: V): V => ({ x: a.x + b.x, y: a.y + b.y })
53
  const lerpV = (a: V, b: V, k: number): V => ({ x: a.x + (b.x - a.x) * k, y: a.y + (b.y - a.y) * k })
54
 
55
  /** Two-bone IK. bend: -1 / +1 picks which side the joint goes. Returns joint + end. */
56
- function ik(a: V, target: V, l1: number, l2: number, bend: number): { j: V; e: V } {
57
  const dx = target.x - a.x
58
  const dy = target.y - a.y
59
  let d = Math.hypot(dx, dy)
@@ -81,23 +110,23 @@ function capsulePath(ctx: C2D, a: V, b: V, ra: number, rb: number) {
81
  ctx.closePath()
82
  }
83
 
84
- function ink(ctx: C2D, fill: string, lw: number) {
85
  ctx.fillStyle = fill
86
  ctx.fill()
87
  if (lw > 0) {
88
- ctx.strokeStyle = HERO.line
89
  ctx.lineWidth = lw
90
  ctx.lineJoin = 'round'
91
  ctx.stroke()
92
  }
93
  }
94
 
95
- function capsule(ctx: C2D, a: V, b: V, ra: number, rb: number, fill: string, lw: number) {
96
  capsulePath(ctx, a, b, ra, rb)
97
  ink(ctx, fill, lw)
98
  }
99
 
100
- function circle(ctx: C2D, c: V, r: number, fill: string, lw: number) {
101
  ctx.beginPath()
102
  ctx.arc(c.x, c.y, r, 0, Math.PI * 2)
103
  ink(ctx, fill, lw)
@@ -150,14 +179,14 @@ function curls(ctx: C2D, cx: number, cy: number, r: number, facing: number, wind
150
  }
151
  // ink outline: same shapes, slightly larger, in line colour
152
  const lw = Math.max(1, r * 0.07)
153
- ctx.fillStyle = HERO.line
154
  ctx.beginPath()
155
  for (const p of pts) {
156
  ctx.moveTo(p.x + p.r + lw, p.y)
157
  ctx.arc(p.x, p.y, p.r + lw, 0, Math.PI * 2)
158
  }
159
  ctx.fill()
160
- ctx.fillStyle = HERO.hair
161
  ctx.beginPath()
162
  for (const p of pts) {
163
  ctx.moveTo(p.x + p.r, p.y)
@@ -166,7 +195,7 @@ function curls(ctx: C2D, cx: number, cy: number, r: number, facing: number, wind
166
  crown()
167
  ctx.fill()
168
  // curl texture: highlight crescent on each curl (light from top-front)
169
- ctx.strokeStyle = HERO.hairHi
170
  ctx.lineWidth = Math.max(1, r * 0.075)
171
  ctx.lineCap = 'round'
172
  ctx.beginPath()
@@ -187,6 +216,7 @@ export interface HeadOpts {
187
  smile?: boolean
188
  rim?: string
189
  tilt?: number
 
190
  }
191
 
192
  /** Side-view head. (cx,cy) = head centre, r = head radius. facing 1 = looking right. */
@@ -209,9 +239,9 @@ export function heroHead(ctx: C2D, cx: number, cy: number, r: number, facing: nu
209
  ctx.quadraticCurveTo(-r * 0.2, r * 0.9, -r * 0.5, r * 0.55)
210
  ctx.quadraticCurveTo(-r * 0.85, r * 0.1, -r * 0.55, -r * 0.7)
211
  ctx.closePath()
212
- ink(ctx, HERO.skin, lw)
213
  // jaw shade
214
- ctx.fillStyle = rgba(HERO.skinShade, 0.45)
215
  ctx.beginPath()
216
  ctx.moveTo(-r * 0.5, r * 0.55)
217
  ctx.quadraticCurveTo(-r * 0.1, r * 0.92, r * 0.32, r * 0.9)
@@ -221,7 +251,7 @@ export function heroHead(ctx: C2D, cx: number, cy: number, r: number, facing: nu
221
  // ear
222
  ctx.beginPath()
223
  ctx.ellipse(-r * 0.12, r * 0.14, r * 0.15, r * 0.21, 0, 0, Math.PI * 2)
224
- ink(ctx, HERO.skinShade, lw * 0.8)
225
  // eye
226
  ctx.strokeStyle = '#21160f'
227
  ctx.fillStyle = '#21160f'
@@ -257,11 +287,27 @@ export function heroHead(ctx: C2D, cx: number, cy: number, r: number, facing: nu
257
  }
258
  ctx.stroke()
259
  // blush
260
- ctx.fillStyle = rgba(HERO.blush, 0.22)
261
  ctx.beginPath()
262
  ctx.ellipse(r * 0.38, r * 0.32, r * 0.14, r * 0.08, 0, 0, Math.PI * 2)
263
  ctx.fill()
264
- curls(ctx, -r * 0.05, -r * 0.14, r, 1, wind, t, 'side')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  if (o.rim) {
266
  ctx.strokeStyle = o.rim
267
  ctx.lineWidth = Math.max(1, r * 0.08)
@@ -288,7 +334,7 @@ export interface Pose {
288
  handF: V
289
  }
290
 
291
- function torso(ctx: C2D, hip: V, sh: V, h: number, f: number, lw: number) {
292
  // sweater body: a rounded slab between hip and shoulder
293
  const ux = sh.x - hip.x
294
  const uy = sh.y - hip.y
@@ -311,9 +357,9 @@ function torso(ctx: C2D, hip: V, sh: V, h: number, f: number, lw: number) {
311
  ctx.quadraticCurveTo(sh.x + (ux / L) * h * 0.05, sh.y + (uy / L) * h * 0.05, p2.x, p2.y)
312
  ctx.quadraticCurveTo((p2.x + p3.x) / 2 - fx * h * 0.025, (p2.y + p3.y) / 2 - fy * h * 0.025, p3.x, p3.y)
313
  ctx.closePath()
314
- ink(ctx, HERO.sweater, lw)
315
  // back shading
316
- ctx.fillStyle = rgba(HERO.sweaterShade, 0.9)
317
  ctx.beginPath()
318
  ctx.moveTo(p3.x, p3.y)
319
  ctx.quadraticCurveTo((p2.x + p3.x) / 2 - fx * h * 0.025, (p2.y + p3.y) / 2 - fy * h * 0.025, p2.x, p2.y)
@@ -322,7 +368,7 @@ function torso(ctx: C2D, hip: V, sh: V, h: number, f: number, lw: number) {
322
  ctx.closePath()
323
  ctx.fill()
324
  // knit texture lines
325
- ctx.strokeStyle = rgba(HERO.sweaterHi, 0.35)
326
  ctx.lineWidth = Math.max(1, h * 0.004)
327
  ctx.beginPath()
328
  for (let k = 1; k < 4; k++) {
@@ -334,15 +380,15 @@ function torso(ctx: C2D, hip: V, sh: V, h: number, f: number, lw: number) {
334
  }
335
  ctx.stroke()
336
  // ribbed hem
337
- capsule(ctx, { x: p3.x + (ux / L) * h * 0.02, y: p3.y + (uy / L) * h * 0.02 }, { x: p0.x + (ux / L) * h * 0.02, y: p0.y + (uy / L) * h * 0.02 }, h * 0.018, h * 0.018, HERO.rib, lw)
338
  }
339
 
340
- function legPiece(ctx: C2D, hip: V, knee: V, foot: V, h: number, f: number, near: boolean, lw: number) {
341
- const col = near ? HERO.pants : HERO.pantsShade
342
  capsule(ctx, hip, knee, h * 0.052, h * 0.045, col, lw)
343
  capsule(ctx, knee, foot, h * 0.045, h * 0.037, col, lw)
344
  // knee crease
345
- ctx.strokeStyle = rgba(HERO.line, 0.35)
346
  ctx.lineWidth = Math.max(1, h * 0.004)
347
  ctx.beginPath()
348
  ctx.moveTo(knee.x - h * 0.02 * f, knee.y - h * 0.01)
@@ -351,26 +397,26 @@ function legPiece(ctx: C2D, hip: V, knee: V, foot: V, h: number, f: number, near
351
  shoe(ctx, foot, h, f, lw)
352
  }
353
 
354
- function shoe(ctx: C2D, foot: V, h: number, f: number, lw: number) {
355
  ctx.beginPath()
356
  ctx.moveTo(foot.x - h * 0.035 * f, foot.y - h * 0.02)
357
  ctx.quadraticCurveTo(foot.x + h * 0.02 * f, foot.y - h * 0.045, foot.x + h * 0.075 * f, foot.y - h * 0.008)
358
  ctx.lineTo(foot.x + h * 0.08 * f, foot.y + h * 0.012)
359
  ctx.lineTo(foot.x - h * 0.04 * f, foot.y + h * 0.012)
360
  ctx.closePath()
361
- ink(ctx, HERO.shoe, lw)
362
- ctx.fillStyle = HERO.sole
363
  ctx.fillRect(Math.min(foot.x - h * 0.04 * f, foot.x + h * 0.08 * f), foot.y + h * 0.003, h * 0.12, h * 0.012)
364
  }
365
 
366
- function armPiece(ctx: C2D, sh: V, elbow: V, hand: V, h: number, near: boolean, lw: number) {
367
- const col = near ? HERO.sweater : HERO.sweaterShade
368
  capsule(ctx, sh, elbow, h * 0.04, h * 0.035, col, lw)
369
  capsule(ctx, elbow, hand, h * 0.035, h * 0.031, col, lw)
370
  // ribbed cuff
371
  const c = lerpV(elbow, hand, 0.86)
372
- capsule(ctx, lerpV(elbow, hand, 0.78), c, h * 0.033, h * 0.033, HERO.rib, lw)
373
- circle(ctx, hand, h * 0.03, HERO.skin, lw)
374
  }
375
 
376
  function drawFar(ctx: C2D, p: Pose, h: number, f: number, lw: number) {
@@ -380,7 +426,7 @@ function drawFar(ctx: C2D, p: Pose, h: number, f: number, lw: number) {
380
 
381
  function drawNear(ctx: C2D, p: Pose, h: number, f: number, lw: number, o: HeadOpts) {
382
  // neck
383
- capsule(ctx, p.sh, { x: p.head.x - f * p.headR * 0.1, y: p.head.y + p.headR * 0.6 }, h * 0.034, h * 0.032, HERO.skinShade, lw)
384
  torso(ctx, p.hip, p.sh, h, f, lw)
385
  legPiece(ctx, p.hip, p.kneeN, p.footN, h, f, true, lw)
386
  heroHead(ctx, p.head.x, p.head.y, p.headR, f, o)
@@ -405,9 +451,11 @@ export interface HeroWalkOpts {
405
  rim?: string
406
  t?: number
407
  eyes?: 'closed' | 'open'
 
408
  /** world-space hand targets (e.g. bike grips) */
409
  gripN?: V
410
  gripF?: V
 
411
  }
412
 
413
  export function walkPose(x: number, y: number, h: number, phase: number, o: HeroWalkOpts): Pose {
@@ -424,8 +472,8 @@ export function walkPose(x: number, y: number, h: number, phase: number, o: Hero
424
  const lift = Math.max(0, Math.cos(ph * P)) * h * (0.045 + run * 0.06)
425
  return { x: x + f * s * stride, y: y - lift }
426
  }
427
- const fN = foot(phase)
428
- const fF = foot(phase + 0.5)
429
  const legN = ik(hip, fN, h * LEG1, h * LEG2, -f)
430
  const legF = ik(hip, fF, h * LEG1, h * LEG2, -f)
431
  const handSwing = (ph: number): V => {
@@ -454,13 +502,14 @@ export function walkPose(x: number, y: number, h: number, phase: number, o: Hero
454
  }
455
 
456
  /** Side-view walking hero. (x,y) = feet on ground, h = total height. */
457
- export function heroWalk(ctx: C2D, x: number, y: number, h: number, phase: number, o: HeroWalkOpts = {}) {
458
  const f = o.facing ?? 1
459
  const lw = Math.max(1, h * 0.007)
460
  const p = walkPose(x, y, h, phase, o)
461
  contactShadow(ctx, x, y, h * 0.2)
462
  drawFar(ctx, p, h, f, lw)
463
- drawNear(ctx, p, h, f, lw, { t: o.t, wind: (o.run ?? 0) * 0.6 + 0.1, eyes: o.eyes ?? 'closed', rim: o.rim })
 
464
  }
465
 
466
  function contactShadow(ctx: C2D, x: number, y: number, w: number) {
@@ -506,14 +555,14 @@ function wheel(ctx: C2D, cx: number, cy: number, R: number, s: number, spin: num
506
  // tyre
507
  ctx.beginPath()
508
  ctx.arc(cx, cy, R, 0, Math.PI * 2)
509
- ink(ctx, HERO.tire, lw)
510
  ctx.strokeStyle = 'rgba(140,150,165,0.35)'
511
  ctx.lineWidth = Math.max(1, s * 0.008)
512
  ctx.beginPath()
513
  ctx.arc(cx, cy, R * 0.92, Math.PI * 1.05, Math.PI * 1.55)
514
  ctx.stroke()
515
  // rim
516
- ctx.strokeStyle = HERO.chrome
517
  ctx.lineWidth = Math.max(1, s * 0.022)
518
  ctx.beginPath()
519
  ctx.arc(cx, cy, R * 0.7, 0, Math.PI * 2)
@@ -523,7 +572,7 @@ function wheel(ctx: C2D, cx: number, cy: number, R: number, s: number, spin: num
523
  ctx.arc(cx, cy, R * 0.66, 0, Math.PI * 2)
524
  ctx.fill()
525
  // spokes
526
- ctx.strokeStyle = rgba(HERO.chrome, 0.85)
527
  ctx.lineWidth = Math.max(1, s * 0.005)
528
  ctx.beginPath()
529
  for (let k = 0; k < 16; k++) {
@@ -535,14 +584,14 @@ function wheel(ctx: C2D, cx: number, cy: number, R: number, s: number, spin: num
535
  ctx.stroke()
536
  if (front) {
537
  // brake disc
538
- ctx.strokeStyle = rgba(HERO.chromeShade, 0.9)
539
  ctx.lineWidth = Math.max(1, s * 0.03)
540
  ctx.beginPath()
541
  ctx.arc(cx, cy, R * 0.33, 0, Math.PI * 2)
542
  ctx.stroke()
543
  }
544
- circle(ctx, { x: cx, y: cy }, R * 0.13, HERO.chrome, lw)
545
- circle(ctx, { x: cx, y: cy }, R * 0.05, HERO.chromeShade, 0)
546
  }
547
 
548
  /** bike drawn at origin facing +x (ground at y = 0) */
@@ -565,11 +614,11 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
565
  ctx.fill()
566
  if (o.beam && light > 0) lightCone(ctx, X(0.55), Y(0.72), s * 3.2, 0.17, -Math.PI / 2, '#fff1c8', 0.16 * light)
567
  // side stand
568
- if (o.parked) capsule(ctx, { x: X(-0.06), y: Y(0.28) }, { x: X(-0.16), y: Y(0.005) }, s * 0.012, s * 0.01, HERO.bikeShade, lw)
569
  wheel(ctx, rx, wy, R, s, spin, false, lw)
570
  wheel(ctx, fx, wy, R, s, spin, true, lw)
571
  // swing arm
572
- capsule(ctx, { x: X(-0.1), y: Y(0.3) }, { x: rx, y: wy }, s * 0.03, s * 0.022, HERO.bike, lw)
573
  // chain
574
  ctx.strokeStyle = '#3a3f48'
575
  ctx.lineWidth = Math.max(1, s * 0.008)
@@ -584,7 +633,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
584
  {
585
  const a = { x: X(-0.36), y: Y(0.58) }
586
  const b = { x: rx + R * 0.15, y: wy - R * 0.1 }
587
- capsule(ctx, a, b, s * 0.016, s * 0.016, HERO.chromeShade, lw)
588
  ctx.strokeStyle = '#d8b04a'
589
  ctx.lineWidth = Math.max(1, s * 0.009)
590
  ctx.beginPath()
@@ -600,8 +649,8 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
600
  ctx.stroke()
601
  }
602
  // frame tubes
603
- capsule(ctx, { x: X(0.36), y: Y(0.78) }, { x: X(0.12), y: Y(0.24) }, s * 0.024, s * 0.024, HERO.bike, lw)
604
- capsule(ctx, { x: X(0.36), y: Y(0.78) }, { x: X(-0.44), y: Y(0.6) }, s * 0.022, s * 0.022, HERO.bike, lw)
605
  // engine: crankcase + finned cylinder
606
  ctx.beginPath()
607
  ctx.moveTo(X(-0.16), Y(0.44))
@@ -617,7 +666,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
617
  ctx.beginPath()
618
  ctx.rect(-s * 0.075, -s * 0.11, s * 0.15, s * 0.17)
619
  ink(ctx, '#2a2f37', lw)
620
- ctx.strokeStyle = HERO.chrome
621
  ctx.lineWidth = Math.max(1, s * 0.009)
622
  ctx.beginPath()
623
  for (let k = 0; k < 6; k++) {
@@ -627,20 +676,20 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
627
  }
628
  ctx.stroke()
629
  ctx.restore()
630
- circle(ctx, { x: X(0.0), y: Y(0.3) }, s * 0.075, HERO.chromeShade, lw)
631
- circle(ctx, { x: X(0.0), y: Y(0.3) }, s * 0.05, HERO.chrome, 0)
632
  // exhaust: header + muffler
633
- ctx.strokeStyle = HERO.line
634
  ctx.lineWidth = s * 0.05
635
  ctx.beginPath()
636
  ctx.moveTo(X(0.2), Y(0.5))
637
  ctx.quadraticCurveTo(X(0.28), Y(0.22), X(0.05), Y(0.16))
638
  ctx.lineTo(X(-0.25), Y(0.2))
639
  ctx.stroke()
640
- ctx.strokeStyle = HERO.chrome
641
  ctx.lineWidth = s * 0.034
642
  ctx.stroke()
643
- capsule(ctx, { x: X(-0.22), y: Y(0.2) }, { x: X(-0.64), y: Y(0.3) }, s * 0.04, s * 0.045, HERO.chrome, lw)
644
  ctx.strokeStyle = rgba('#ffffff', 0.55)
645
  ctx.lineWidth = Math.max(1, s * 0.008)
646
  ctx.beginPath()
@@ -655,8 +704,8 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
655
  ctx.lineTo(X(-0.14), Y(0.42))
656
  ctx.lineTo(X(-0.34), Y(0.44))
657
  ctx.closePath()
658
- ink(ctx, HERO.bike, lw)
659
- circle(ctx, { x: X(-0.25), y: Y(0.51) }, s * 0.025, HERO.chromeShade, lw)
660
  // rear fender + tail light + plate
661
  ctx.beginPath()
662
  ctx.moveTo(X(-0.4), Y(0.6))
@@ -664,7 +713,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
664
  ctx.lineTo(X(-0.68), Y(0.46))
665
  ctx.quadraticCurveTo(X(-0.6), Y(0.56), X(-0.4), Y(0.55))
666
  ctx.closePath()
667
- ink(ctx, HERO.bike, lw)
668
  ctx.beginPath()
669
  ctx.rect(X(-0.72), Y(0.46), s * 0.06, s * 0.08)
670
  ink(ctx, '#e8e2d6', lw)
@@ -680,7 +729,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
680
  ctx.quadraticCurveTo(X(0.02), Y(0.62), X(0.0), Y(0.58))
681
  ctx.lineTo(X(-0.44), Y(0.57))
682
  ctx.closePath()
683
- ink(ctx, HERO.seat, lw)
684
  ctx.strokeStyle = 'rgba(200,180,150,0.25)'
685
  ctx.lineWidth = Math.max(1, s * 0.004)
686
  ctx.setLineDash([s * 0.012, s * 0.01])
@@ -697,8 +746,8 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
697
  ctx.quadraticCurveTo(X(0.36), Y(0.58), X(0.22), Y(0.56))
698
  ctx.quadraticCurveTo(X(0.06), Y(0.54), X(-0.04), Y(0.6))
699
  ctx.closePath()
700
- ink(ctx, HERO.bike, lw)
701
- ctx.strokeStyle = rgba(HERO.bikeHi, 0.9)
702
  ctx.lineWidth = Math.max(1, s * 0.014)
703
  ctx.beginPath()
704
  ctx.moveTo(X(0.04), Y(0.72))
@@ -706,7 +755,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
706
  ctx.stroke()
707
  ctx.beginPath()
708
  ctx.ellipse(X(0.2), Y(0.66), s * 0.045, s * 0.03, 0, 0, Math.PI * 2)
709
- ink(ctx, HERO.chrome, lw)
710
  ctx.fillStyle = '#c4142f'
711
  ctx.beginPath()
712
  ctx.ellipse(X(0.2), Y(0.66), s * 0.026, s * 0.015, 0, 0, Math.PI * 2)
@@ -715,20 +764,20 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
715
  ctx.ellipse(X(0.04), Y(0.6), s * 0.05, s * 0.03, -0.2, 0, Math.PI * 2)
716
  ink(ctx, '#202228', lw)
717
  // front fork + fender
718
- capsule(ctx, { x: X(0.37), y: Y(0.8) }, { x: fx, y: wy }, s * 0.022, s * 0.02, HERO.chrome, lw)
719
  capsule(ctx, { x: X(0.44), y: Y(0.4) }, { x: X(0.49), y: Y(0.27) }, s * 0.03, s * 0.028, '#2a2e36', lw)
720
- ctx.strokeStyle = HERO.line
721
  ctx.lineWidth = s * 0.05
722
  ctx.beginPath()
723
  ctx.arc(fx, wy, R * 1.12, Math.PI * 1.08, Math.PI * 1.72)
724
  ctx.stroke()
725
- ctx.strokeStyle = HERO.bike
726
  ctx.lineWidth = s * 0.034
727
  ctx.stroke()
728
  // handlebar + grips + lever
729
- capsule(ctx, { x: X(0.37), y: Y(0.82) }, { x: X(0.31), y: Y(0.86) }, s * 0.011, s * 0.011, HERO.chrome, lw)
730
  capsule(ctx, { x: X(0.31), y: Y(0.86) }, { x: X(0.24), y: Y(0.84) }, s * 0.018, s * 0.018, '#0e0f12', lw)
731
- ctx.strokeStyle = HERO.chromeShade
732
  ctx.lineWidth = Math.max(1, s * 0.008)
733
  ctx.beginPath()
734
  ctx.moveTo(X(0.31), Y(0.86))
@@ -738,7 +787,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
738
  circle(ctx, { x: X(0.38), y: Y(0.86) }, s * 0.03, '#1a1c22', lw)
739
  circle(ctx, { x: X(0.38), y: Y(0.86) }, s * 0.018, '#d9e2c9', 0)
740
  // mirror
741
- ctx.strokeStyle = HERO.chromeShade
742
  ctx.lineWidth = Math.max(1, s * 0.01)
743
  ctx.beginPath()
744
  ctx.moveTo(X(0.32), Y(0.86))
@@ -746,7 +795,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
746
  ctx.stroke()
747
  ctx.beginPath()
748
  ctx.ellipse(X(0.31), Y(1.03), s * 0.04, s * 0.032, 0, 0, Math.PI * 2)
749
- ink(ctx, HERO.chrome, lw)
750
  ctx.fillStyle = '#6d8296'
751
  ctx.beginPath()
752
  ctx.ellipse(X(0.31), Y(1.03), s * 0.026, s * 0.02, 0, 0, Math.PI * 2)
@@ -754,7 +803,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
754
  // headlight: chrome bucket, glass, amber indicator
755
  ctx.beginPath()
756
  ctx.ellipse(X(0.46), Y(0.72), s * 0.07, s * 0.08, 0, 0, Math.PI * 2)
757
- ink(ctx, HERO.chrome, lw)
758
  ctx.fillStyle = light > 0.1 ? '#fff6d8' : '#5a626c'
759
  ctx.beginPath()
760
  ctx.ellipse(X(0.5), Y(0.72), s * 0.035, s * 0.065, 0, 0, Math.PI * 2)
@@ -764,7 +813,7 @@ function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
764
  ink(ctx, '#ffa63a', lw)
765
  if (light > 0.1) glowBlob(ctx, X(0.52), Y(0.72), s * 0.26, '#fff1c8', 0.9 * light)
766
  // foot peg
767
- capsule(ctx, { x: X(-0.13), y: Y(0.3) }, { x: X(-0.06), y: Y(0.3) }, s * 0.012, s * 0.012, HERO.chromeShade, lw)
768
  }
769
 
770
  // ------------------------------------------------------------------ pushing the bike
@@ -857,7 +906,7 @@ export function heroRide(ctx: C2D, x: number, y: number, s: number, o: RideOpts
857
  drawFar(ctx, p, h, f, lw)
858
  bike(ctx, x, y, s, { facing: f, light: o.light, spin: o.spin, beam: o.beam })
859
  // seat contact: the trousers sit on top of the seat
860
- capsule(ctx, { x: hip.x - f * h * 0.05, y: hip.y + h * 0.01 }, { x: hip.x + f * h * 0.03, y: hip.y + h * 0.015 }, h * 0.05, h * 0.05, HERO.pants, lw)
861
  drawNear(ctx, p, h, f, lw, { t, wind: o.wind ?? 0.6, smile: o.smile, eyes: o.eyes ?? 'open', rim: o.rim })
862
  }
863
 
@@ -868,17 +917,17 @@ export function heroBack(ctx: C2D, x: number, y: number, h: number, sway = 0, o:
868
  const t = o.t ?? 0
869
  contactShadow(ctx, x, y, h * 0.2)
870
  // legs
871
- capsule(ctx, { x: x - h * 0.05, y: y - h * 0.4 }, { x: x - h * 0.055, y: y - h * 0.03 }, h * 0.048, h * 0.038, HERO.pantsShade, lw)
872
- capsule(ctx, { x: x + h * 0.05, y: y - h * 0.4 }, { x: x + h * 0.055, y: y - h * 0.03 }, h * 0.048, h * 0.038, HERO.pants, lw)
873
  for (const sd of [-1, 1]) {
874
  ctx.beginPath()
875
  ctx.ellipse(x + sd * h * 0.055, y - h * 0.015, h * 0.045, h * 0.025, 0, 0, Math.PI * 2)
876
- ink(ctx, HERO.shoe, lw)
877
  }
878
  // arms
879
  for (const sd of [-1, 1]) {
880
- capsule(ctx, { x: x + sd * h * 0.13 + sw, y: y - h * 0.63 }, { x: x + sd * h * 0.155, y: y - h * 0.4 }, h * 0.038, h * 0.032, HERO.sweaterShade, lw)
881
- circle(ctx, { x: x + sd * h * 0.157, y: y - h * 0.375 }, h * 0.028, HERO.skin, lw)
882
  }
883
  // sweater
884
  ctx.beginPath()
@@ -888,19 +937,19 @@ export function heroBack(ctx: C2D, x: number, y: number, h: number, sway = 0, o:
888
  ctx.quadraticCurveTo(x + h * 0.16, y - h * 0.52, x + h * 0.14 + sw, y - h * 0.67)
889
  ctx.quadraticCurveTo(x + sw, y - h * 0.71, x - h * 0.14 + sw, y - h * 0.67)
890
  ctx.closePath()
891
- ink(ctx, HERO.sweater, lw)
892
- ctx.fillStyle = rgba(HERO.sweaterShade, 0.8)
893
  ctx.fillRect(x - h * 0.005, y - h * 0.66, h * 0.01, h * 0.28)
894
- capsule(ctx, { x: x - h * 0.12, y: y - h * 0.385 }, { x: x + h * 0.12, y: y - h * 0.385 }, h * 0.018, h * 0.018, HERO.rib, lw)
895
  // neck + head from behind
896
  const r = h * 0.14
897
  const hx = x + sw * 1.2
898
  const hy = y - h * 0.7 - r * 0.9
899
- capsule(ctx, { x: hx, y: y - h * 0.67 }, { x: hx, y: hy + r * 0.5 }, h * 0.026, h * 0.026, HERO.skinShade, lw)
900
  for (const sd of [-1, 1]) {
901
  ctx.beginPath()
902
  ctx.ellipse(hx + sd * r * 0.92, hy + r * 0.15, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
903
- ink(ctx, HERO.skinShade, lw)
904
  }
905
  curls(ctx, hx, hy, r, 1, o.wind ?? 0, t, 'back')
906
  if (o.rim) {
@@ -923,9 +972,9 @@ export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: nu
923
  ctx.lineJoin = 'round'
924
  // --- far: handlebar, mirrors, headlight glow ahead
925
  glowBlob(ctx, 0, -s * 0.5, s * 0.5, '#fff1c8', 0.12)
926
- capsule(ctx, { x: -s * 0.3, y: -s * 0.6 }, { x: s * 0.3, y: -s * 0.6 }, s * 0.01, s * 0.01, HERO.chrome, lw)
927
  for (const sd of [-1, 1]) {
928
- ctx.strokeStyle = HERO.chromeShade
929
  ctx.lineWidth = Math.max(1, s * 0.008)
930
  ctx.beginPath()
931
  ctx.moveTo(sd * s * 0.25, -s * 0.6)
@@ -933,7 +982,7 @@ export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: nu
933
  ctx.stroke()
934
  ctx.beginPath()
935
  ctx.ellipse(sd * s * 0.305, -s * 0.735, s * 0.034, s * 0.027, 0, 0, Math.PI * 2)
936
- ink(ctx, HERO.chrome, lw)
937
  ctx.fillStyle = '#6d8296'
938
  ctx.beginPath()
939
  ctx.ellipse(sd * s * 0.305, -s * 0.735, s * 0.022, s * 0.017, 0, 0, Math.PI * 2)
@@ -942,16 +991,16 @@ export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: nu
942
  // tank glimpsed between the knees
943
  ctx.beginPath()
944
  ctx.ellipse(0, -s * 0.47, s * 0.09, s * 0.06, 0, 0, Math.PI * 2)
945
- ink(ctx, HERO.bike, lw)
946
  // --- rider: arms reach forward to the grips
947
  const h = s * 0.95
948
  for (const sd of [-1, 1]) {
949
  const shp = { x: sd * h * 0.13, y: -s * 0.78 }
950
  const grip = { x: sd * s * 0.27, y: -s * 0.6 }
951
  const a = ik(shp, grip, h * 0.15, h * 0.14, sd > 0 ? -1 : 1)
952
- capsule(ctx, shp, a.j, h * 0.04, h * 0.035, HERO.sweaterShade, lw)
953
- capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, HERO.sweaterShade, lw)
954
- circle(ctx, a.e, h * 0.03, HERO.skinShade, lw)
955
  }
956
  // back
957
  ctx.beginPath()
@@ -960,34 +1009,34 @@ export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: nu
960
  ctx.quadraticCurveTo(0, -s * 0.84, h * 0.13, -s * 0.8)
961
  ctx.quadraticCurveTo(h * 0.19, -s * 0.66, h * 0.16, -s * 0.47)
962
  ctx.closePath()
963
- ink(ctx, HERO.sweater, lw)
964
- ctx.fillStyle = rgba(HERO.sweaterShade, 0.85)
965
  ctx.fillRect(-h * 0.006, -s * 0.79, h * 0.012, s * 0.3)
966
- capsule(ctx, { x: -h * 0.155, y: -s * 0.475 }, { x: h * 0.155, y: -s * 0.475 }, h * 0.018, h * 0.018, HERO.rib, lw)
967
  // neck + hair
968
  const r = h * 0.14
969
- capsule(ctx, { x: 0, y: -s * 0.8 }, { x: 0, y: -s * 0.86 }, h * 0.026, h * 0.026, HERO.skinShade, lw)
970
  curls(ctx, 0, -s * 0.84 - r * 0.85, r, 1, wind, t, 'back')
971
  // legs out to the pegs (both sides)
972
  for (const sd of [-1, 1]) {
973
  const hipp = { x: sd * h * 0.08, y: -s * 0.44 }
974
  const peg = { x: sd * s * 0.17, y: -s * 0.2 }
975
  const k = ik(hipp, peg, h * 0.2, h * 0.19, sd > 0 ? -1 : 1)
976
- capsule(ctx, hipp, k.j, h * 0.05, h * 0.044, sd > 0 ? HERO.pants : HERO.pantsShade, lw)
977
- capsule(ctx, k.j, k.e, h * 0.044, h * 0.036, sd > 0 ? HERO.pants : HERO.pantsShade, lw)
978
  ctx.beginPath()
979
  ctx.ellipse(k.e.x + sd * h * 0.01, k.e.y + h * 0.01, h * 0.04, h * 0.03, 0, 0, Math.PI * 2)
980
- ink(ctx, HERO.shoe, lw)
981
  }
982
  // --- near: seat edge, twin shocks, mufflers, rear tyre, fender, tail light, plate
983
  ctx.beginPath()
984
  ctx.ellipse(0, -s * 0.43, h * 0.13, s * 0.032, 0, 0, Math.PI * 2)
985
- ink(ctx, HERO.seat, lw)
986
  for (const sd of [-1, 1]) {
987
  // rear shock absorbers with yellow springs
988
  const a = { x: sd * s * 0.11, y: -s * 0.42 }
989
  const b = { x: sd * s * 0.1, y: -s * 0.17 }
990
- capsule(ctx, a, b, s * 0.014, s * 0.014, HERO.chromeShade, lw)
991
  ctx.strokeStyle = '#d8b04a'
992
  ctx.lineWidth = Math.max(1, s * 0.008)
993
  ctx.beginPath()
@@ -997,13 +1046,13 @@ export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: nu
997
  }
998
  ctx.stroke()
999
  // muffler on each side
1000
- capsule(ctx, { x: sd * s * 0.17, y: -s * 0.16 }, { x: sd * s * 0.19, y: -s * 0.25 }, s * 0.036, s * 0.042, HERO.chrome, lw)
1001
  circle(ctx, { x: sd * s * 0.19, y: -s * 0.25 }, s * 0.024, '#2a2f37', lw)
1002
  }
1003
  // fat rear tyre with tread
1004
  ctx.beginPath()
1005
  ctx.ellipse(0, -s * 0.15, s * 0.085, s * 0.16, 0, 0, Math.PI * 2)
1006
- ink(ctx, HERO.tire, lw)
1007
  ctx.strokeStyle = 'rgba(140,150,165,0.4)'
1008
  ctx.lineWidth = Math.max(1, s * 0.006)
1009
  ctx.beginPath()
@@ -1019,7 +1068,7 @@ export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: nu
1019
  ctx.lineTo(s * 0.08, -s * 0.36)
1020
  ctx.lineTo(-s * 0.08, -s * 0.36)
1021
  ctx.closePath()
1022
- ink(ctx, HERO.bike, lw)
1023
  ctx.beginPath()
1024
  ctx.rect(-s * 0.05, -s * 0.27, s * 0.1, s * 0.05)
1025
  ink(ctx, '#e8e2d6', lw)
@@ -1105,7 +1154,7 @@ export function flame(ctx: C2D, x: number, y: number, size: number, t: number) {
1105
  ctx.globalAlpha = 1
1106
  }
1107
 
1108
- // ------------------------------------------------------------------ front portrait
1109
  export interface PortraitOpts {
1110
  t: number
1111
  eyes?: number // 0 closed .. 1 open
@@ -1113,62 +1162,30 @@ export interface PortraitOpts {
1113
  wind?: number
1114
  rim?: string
1115
  smile?: boolean
 
1116
  }
1117
 
1118
- /** Front-facing bust. (cx,cy) = face centre, size = face radius. */
1119
- export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o: PortraitOpts) {
1120
- const r = size
1121
  const t = o.t
1122
  const lw = Math.max(1, r * 0.035)
1123
- // shoulders / sweater
1124
- ctx.beginPath()
1125
- ctx.moveTo(cx - r * 2.5, cy + r * 3.3)
1126
- ctx.quadraticCurveTo(cx - r * 2.4, cy + r * 1.5, cx - r * 0.55, cy + r * 1.28)
1127
- ctx.lineTo(cx + r * 0.55, cy + r * 1.28)
1128
- ctx.quadraticCurveTo(cx + r * 2.4, cy + r * 1.5, cx + r * 2.5, cy + r * 3.3)
1129
- ctx.closePath()
1130
- ink(ctx, HERO.sweater, lw)
1131
- ctx.fillStyle = HERO.sweaterShade
1132
- ctx.beginPath()
1133
- ctx.moveTo(cx - r * 2.5, cy + r * 3.3)
1134
- ctx.quadraticCurveTo(cx - r * 2.4, cy + r * 1.5, cx - r * 1.3, cy + r * 1.34)
1135
- ctx.quadraticCurveTo(cx - r * 1.7, cy + r * 2.2, cx - r * 1.6, cy + r * 3.3)
1136
- ctx.closePath()
1137
- ctx.fill()
1138
- ctx.strokeStyle = rgba(HERO.sweaterHi, 0.35)
1139
- ctx.lineWidth = Math.max(1, r * 0.03)
1140
- ctx.beginPath()
1141
- for (let k = -3; k <= 3; k++) {
1142
- ctx.moveTo(cx + k * r * 0.45, cy + r * 1.75)
1143
- ctx.lineTo(cx + k * r * 0.5, cy + r * 3.2)
1144
- }
1145
- ctx.stroke()
1146
- // neck + ribbed crew collar
1147
- ctx.beginPath()
1148
- ctx.rect(cx - r * 0.34, cy + r * 0.65, r * 0.68, r * 0.72)
1149
- ink(ctx, HERO.skinShade, lw)
1150
- ctx.beginPath()
1151
- ctx.ellipse(cx, cy + r * 1.34, r * 0.6, r * 0.2, 0, 0, Math.PI)
1152
- ctx.strokeStyle = HERO.line
1153
- ctx.lineWidth = r * 0.2
1154
- ctx.stroke()
1155
- ctx.strokeStyle = HERO.rib
1156
- ctx.lineWidth = r * 0.15
1157
- ctx.stroke()
1158
  // back hair volume
1159
- ctx.fillStyle = HERO.line
1160
  ctx.beginPath()
1161
  ctx.ellipse(cx, cy - r * 0.15, r * 1.34, r * 1.22, 0, 0, Math.PI * 2)
1162
  ctx.fill()
1163
- ctx.fillStyle = HERO.hair
1164
  ctx.beginPath()
1165
  ctx.ellipse(cx, cy - r * 0.15, r * 1.3, r * 1.18, 0, 0, Math.PI * 2)
1166
  ctx.fill()
1167
- // ears
1168
  for (const sd of [-1, 1]) {
1169
  ctx.beginPath()
1170
  ctx.ellipse(cx + sd * r * 0.95, cy + r * 0.12, r * 0.15, r * 0.24, 0, 0, Math.PI * 2)
1171
- ink(ctx, HERO.skinShade, lw)
1172
  }
1173
  // face (square-ish jaw)
1174
  ctx.beginPath()
@@ -1179,17 +1196,17 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
1179
  ctx.lineTo(cx + r * 0.94, cy - r * 0.2)
1180
  ctx.quadraticCurveTo(cx, cy - r * 1.05, cx - r * 0.94, cy - r * 0.2)
1181
  ctx.closePath()
1182
- ink(ctx, HERO.skin, lw)
1183
- ctx.fillStyle = rgba(HERO.skinShade, 0.35)
1184
  ctx.beginPath()
1185
  ctx.ellipse(cx - r * 0.6, cy + r * 0.5, r * 0.3, r * 0.35, 0.3, 0, Math.PI * 2)
1186
  ctx.fill()
1187
- ctx.fillStyle = rgba(HERO.blush, 0.16)
1188
  ctx.beginPath()
1189
  ctx.ellipse(cx - r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
1190
  ctx.ellipse(cx + r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
1191
  ctx.fill()
1192
- // eyes
1193
  const open = o.eyes ?? 0
1194
  ctx.strokeStyle = '#21160f'
1195
  ctx.fillStyle = '#21160f'
@@ -1220,7 +1237,7 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
1220
  ctx.restore()
1221
  }
1222
  // nose + mouth
1223
- ctx.strokeStyle = rgba(HERO.skinShade, 0.95)
1224
  ctx.lineWidth = Math.max(1, r * 0.05)
1225
  ctx.beginPath()
1226
  ctx.moveTo(cx + r * 0.02, cy + r * 0.25)
@@ -1235,7 +1252,6 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
1235
  ctx.quadraticCurveTo(cx, cy + r * 0.6, cx + r * 0.13, cy + r * 0.66)
1236
  }
1237
  ctx.stroke()
1238
- // tear
1239
  const tear = o.tear ?? 0
1240
  if (tear > 0) {
1241
  const ty = cy + r * 0.2 + tear * r * 0.55
@@ -1254,21 +1270,21 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
1254
  curls(ctx, cx, cy - r * 0.38, r * 1.1, 1, o.wind ?? 0, t, 'front')
1255
  const fr: { x: number; y: number; rr: number }[] = []
1256
  for (let i = 0; i < 7; i++) fr.push({ x: cx + (i - 3) * r * 0.26, y: cy - r * 0.66 + Math.abs(i - 3) * r * 0.06 + Math.sin(t * 2 + i) * r * 0.01, rr: r * (0.2 + 0.05 * hash(i * 9.1)) })
1257
- ctx.fillStyle = HERO.line
1258
  ctx.beginPath()
1259
  for (const p of fr) {
1260
  ctx.moveTo(p.x + p.rr + lw, p.y)
1261
  ctx.arc(p.x, p.y, p.rr + lw, 0, Math.PI * 2)
1262
  }
1263
  ctx.fill()
1264
- ctx.fillStyle = HERO.hair
1265
  ctx.beginPath()
1266
  for (const p of fr) {
1267
  ctx.moveTo(p.x + p.rr, p.y)
1268
  ctx.arc(p.x, p.y, p.rr, 0, Math.PI * 2)
1269
  }
1270
  ctx.fill()
1271
- ctx.strokeStyle = HERO.hairHi
1272
  ctx.lineWidth = Math.max(1, r * 0.05)
1273
  ctx.beginPath()
1274
  for (const p of fr) {
@@ -1283,5 +1299,316 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
1283
  ctx.arc(cx, cy - r * 0.2, r * 1.45, Math.PI * 1.08, Math.PI * 1.55)
1284
  ctx.stroke()
1285
  }
1286
- void add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1287
  }
 
11
  // • Draw order is explicit (far limbs → bike → body → near limbs), so
12
  // nothing pokes through the bike.
13
  import { glowBlob, lightCone } from './draw'
14
+ import { clamp, fract, hash, rgba } from './util'
15
 
16
  type C2D = CanvasRenderingContext2D
17
  interface V {
 
43
  tire: '#0a0a0c',
44
  }
45
 
46
+ /** active palette (lets the same rig draw other characters, e.g. the stall auntie) */
47
+ let C: typeof HERO = HERO
48
+ export function withPalette(p: Partial<typeof HERO>, fn: () => void) {
49
+ const prev = C
50
+ C = { ...HERO, ...p }
51
+ try {
52
+ fn()
53
+ } finally {
54
+ C = prev
55
+ }
56
+ }
57
+ export const AUNTIE: Partial<typeof HERO> = {
58
+ sweater: '#8a3a3a',
59
+ sweaterShade: '#6a2a2c',
60
+ sweaterHi: '#b0585a',
61
+ rib: '#5a2426',
62
+ pants: '#2f3440',
63
+ pantsShade: '#22262f',
64
+ hair: '#3a3a3c',
65
+ hairHi: '#6a6a70',
66
+ skin: '#e2c09a',
67
+ }
68
+ export const RIVAL: Partial<typeof HERO> = {
69
+ sweater: '#17181c',
70
+ sweaterShade: '#0e0f12',
71
+ sweaterHi: '#3a3c44',
72
+ rib: '#25262c',
73
+ }
74
+
75
  /** standing height of the hero in bike units (bike wheelbase = 1) */
76
  export const HERO_H = 1.4
77
  /** total height of rider + bike in bike units (for layout) */
 
82
  const lerpV = (a: V, b: V, k: number): V => ({ x: a.x + (b.x - a.x) * k, y: a.y + (b.y - a.y) * k })
83
 
84
  /** Two-bone IK. bend: -1 / +1 picks which side the joint goes. Returns joint + end. */
85
+ export function ik(a: V, target: V, l1: number, l2: number, bend: number): { j: V; e: V } {
86
  const dx = target.x - a.x
87
  const dy = target.y - a.y
88
  let d = Math.hypot(dx, dy)
 
110
  ctx.closePath()
111
  }
112
 
113
+ export function ink(ctx: C2D, fill: string, lw: number) {
114
  ctx.fillStyle = fill
115
  ctx.fill()
116
  if (lw > 0) {
117
+ ctx.strokeStyle = C.line
118
  ctx.lineWidth = lw
119
  ctx.lineJoin = 'round'
120
  ctx.stroke()
121
  }
122
  }
123
 
124
+ export function capsule(ctx: C2D, a: V, b: V, ra: number, rb: number, fill: string, lw: number) {
125
  capsulePath(ctx, a, b, ra, rb)
126
  ink(ctx, fill, lw)
127
  }
128
 
129
+ export function circle(ctx: C2D, c: V, r: number, fill: string, lw: number) {
130
  ctx.beginPath()
131
  ctx.arc(c.x, c.y, r, 0, Math.PI * 2)
132
  ink(ctx, fill, lw)
 
179
  }
180
  // ink outline: same shapes, slightly larger, in line colour
181
  const lw = Math.max(1, r * 0.07)
182
+ ctx.fillStyle = C.line
183
  ctx.beginPath()
184
  for (const p of pts) {
185
  ctx.moveTo(p.x + p.r + lw, p.y)
186
  ctx.arc(p.x, p.y, p.r + lw, 0, Math.PI * 2)
187
  }
188
  ctx.fill()
189
+ ctx.fillStyle = C.hair
190
  ctx.beginPath()
191
  for (const p of pts) {
192
  ctx.moveTo(p.x + p.r, p.y)
 
195
  crown()
196
  ctx.fill()
197
  // curl texture: highlight crescent on each curl (light from top-front)
198
+ ctx.strokeStyle = C.hairHi
199
  ctx.lineWidth = Math.max(1, r * 0.075)
200
  ctx.lineCap = 'round'
201
  ctx.beginPath()
 
216
  smile?: boolean
217
  rim?: string
218
  tilt?: number
219
+ scarf?: string
220
  }
221
 
222
  /** Side-view head. (cx,cy) = head centre, r = head radius. facing 1 = looking right. */
 
239
  ctx.quadraticCurveTo(-r * 0.2, r * 0.9, -r * 0.5, r * 0.55)
240
  ctx.quadraticCurveTo(-r * 0.85, r * 0.1, -r * 0.55, -r * 0.7)
241
  ctx.closePath()
242
+ ink(ctx, C.skin, lw)
243
  // jaw shade
244
+ ctx.fillStyle = rgba(C.skinShade, 0.45)
245
  ctx.beginPath()
246
  ctx.moveTo(-r * 0.5, r * 0.55)
247
  ctx.quadraticCurveTo(-r * 0.1, r * 0.92, r * 0.32, r * 0.9)
 
251
  // ear
252
  ctx.beginPath()
253
  ctx.ellipse(-r * 0.12, r * 0.14, r * 0.15, r * 0.21, 0, 0, Math.PI * 2)
254
+ ink(ctx, C.skinShade, lw * 0.8)
255
  // eye
256
  ctx.strokeStyle = '#21160f'
257
  ctx.fillStyle = '#21160f'
 
287
  }
288
  ctx.stroke()
289
  // blush
290
+ ctx.fillStyle = rgba(C.blush, 0.22)
291
  ctx.beginPath()
292
  ctx.ellipse(r * 0.38, r * 0.32, r * 0.14, r * 0.08, 0, 0, Math.PI * 2)
293
  ctx.fill()
294
+ if (o.scarf) {
295
+ // headscarf over the hair, knot at the nape
296
+ ctx.beginPath()
297
+ ctx.moveTo(r * 0.55, -r * 0.55)
298
+ ctx.quadraticCurveTo(r * 0.1, -r * 1.25, -r * 0.75, -r * 0.55)
299
+ ctx.quadraticCurveTo(-r * 0.95, r * 0.1, -r * 0.55, r * 0.45)
300
+ ctx.lineTo(-r * 0.3, r * 0.1)
301
+ ctx.quadraticCurveTo(r * 0.05, -r * 0.6, r * 0.55, -r * 0.55)
302
+ ctx.closePath()
303
+ ink(ctx, o.scarf, lw)
304
+ ctx.beginPath()
305
+ ctx.moveTo(-r * 0.7, r * 0.25)
306
+ ctx.lineTo(-r * 1.05, r * 0.55)
307
+ ctx.lineTo(-r * 0.75, r * 0.6)
308
+ ctx.closePath()
309
+ ink(ctx, o.scarf, lw)
310
+ } else curls(ctx, -r * 0.05, -r * 0.14, r, 1, wind, t, 'side')
311
  if (o.rim) {
312
  ctx.strokeStyle = o.rim
313
  ctx.lineWidth = Math.max(1, r * 0.08)
 
334
  handF: V
335
  }
336
 
337
+ export function torso(ctx: C2D, hip: V, sh: V, h: number, f: number, lw: number) {
338
  // sweater body: a rounded slab between hip and shoulder
339
  const ux = sh.x - hip.x
340
  const uy = sh.y - hip.y
 
357
  ctx.quadraticCurveTo(sh.x + (ux / L) * h * 0.05, sh.y + (uy / L) * h * 0.05, p2.x, p2.y)
358
  ctx.quadraticCurveTo((p2.x + p3.x) / 2 - fx * h * 0.025, (p2.y + p3.y) / 2 - fy * h * 0.025, p3.x, p3.y)
359
  ctx.closePath()
360
+ ink(ctx, C.sweater, lw)
361
  // back shading
362
+ ctx.fillStyle = rgba(C.sweaterShade, 0.9)
363
  ctx.beginPath()
364
  ctx.moveTo(p3.x, p3.y)
365
  ctx.quadraticCurveTo((p2.x + p3.x) / 2 - fx * h * 0.025, (p2.y + p3.y) / 2 - fy * h * 0.025, p2.x, p2.y)
 
368
  ctx.closePath()
369
  ctx.fill()
370
  // knit texture lines
371
+ ctx.strokeStyle = rgba(C.sweaterHi, 0.35)
372
  ctx.lineWidth = Math.max(1, h * 0.004)
373
  ctx.beginPath()
374
  for (let k = 1; k < 4; k++) {
 
380
  }
381
  ctx.stroke()
382
  // ribbed hem
383
+ capsule(ctx, { x: p3.x + (ux / L) * h * 0.02, y: p3.y + (uy / L) * h * 0.02 }, { x: p0.x + (ux / L) * h * 0.02, y: p0.y + (uy / L) * h * 0.02 }, h * 0.018, h * 0.018, C.rib, lw)
384
  }
385
 
386
+ export function legPiece(ctx: C2D, hip: V, knee: V, foot: V, h: number, f: number, near: boolean, lw: number) {
387
+ const col = near ? C.pants : C.pantsShade
388
  capsule(ctx, hip, knee, h * 0.052, h * 0.045, col, lw)
389
  capsule(ctx, knee, foot, h * 0.045, h * 0.037, col, lw)
390
  // knee crease
391
+ ctx.strokeStyle = rgba(C.line, 0.35)
392
  ctx.lineWidth = Math.max(1, h * 0.004)
393
  ctx.beginPath()
394
  ctx.moveTo(knee.x - h * 0.02 * f, knee.y - h * 0.01)
 
397
  shoe(ctx, foot, h, f, lw)
398
  }
399
 
400
+ export function shoe(ctx: C2D, foot: V, h: number, f: number, lw: number) {
401
  ctx.beginPath()
402
  ctx.moveTo(foot.x - h * 0.035 * f, foot.y - h * 0.02)
403
  ctx.quadraticCurveTo(foot.x + h * 0.02 * f, foot.y - h * 0.045, foot.x + h * 0.075 * f, foot.y - h * 0.008)
404
  ctx.lineTo(foot.x + h * 0.08 * f, foot.y + h * 0.012)
405
  ctx.lineTo(foot.x - h * 0.04 * f, foot.y + h * 0.012)
406
  ctx.closePath()
407
+ ink(ctx, C.shoe, lw)
408
+ ctx.fillStyle = C.sole
409
  ctx.fillRect(Math.min(foot.x - h * 0.04 * f, foot.x + h * 0.08 * f), foot.y + h * 0.003, h * 0.12, h * 0.012)
410
  }
411
 
412
+ export function armPiece(ctx: C2D, sh: V, elbow: V, hand: V, h: number, near: boolean, lw: number) {
413
+ const col = near ? C.sweater : C.sweaterShade
414
  capsule(ctx, sh, elbow, h * 0.04, h * 0.035, col, lw)
415
  capsule(ctx, elbow, hand, h * 0.035, h * 0.031, col, lw)
416
  // ribbed cuff
417
  const c = lerpV(elbow, hand, 0.86)
418
+ capsule(ctx, lerpV(elbow, hand, 0.78), c, h * 0.033, h * 0.033, C.rib, lw)
419
+ circle(ctx, hand, h * 0.03, C.skin, lw)
420
  }
421
 
422
  function drawFar(ctx: C2D, p: Pose, h: number, f: number, lw: number) {
 
426
 
427
  function drawNear(ctx: C2D, p: Pose, h: number, f: number, lw: number, o: HeadOpts) {
428
  // neck
429
+ capsule(ctx, p.sh, { x: p.head.x - f * p.headR * 0.1, y: p.head.y + p.headR * 0.6 }, h * 0.034, h * 0.032, C.skinShade, lw)
430
  torso(ctx, p.hip, p.sh, h, f, lw)
431
  legPiece(ctx, p.hip, p.kneeN, p.footN, h, f, true, lw)
432
  heroHead(ctx, p.head.x, p.head.y, p.headR, f, o)
 
451
  rim?: string
452
  t?: number
453
  eyes?: 'closed' | 'open'
454
+ scarf?: string
455
  /** world-space hand targets (e.g. bike grips) */
456
  gripN?: V
457
  gripF?: V
458
+ stand?: boolean
459
  }
460
 
461
  export function walkPose(x: number, y: number, h: number, phase: number, o: HeroWalkOpts): Pose {
 
472
  const lift = Math.max(0, Math.cos(ph * P)) * h * (0.045 + run * 0.06)
473
  return { x: x + f * s * stride, y: y - lift }
474
  }
475
+ const fN = o.stand ? { x: x + f * h * 0.05, y } : foot(phase)
476
+ const fF = o.stand ? { x: x - f * h * 0.04, y } : foot(phase + 0.5)
477
  const legN = ik(hip, fN, h * LEG1, h * LEG2, -f)
478
  const legF = ik(hip, fF, h * LEG1, h * LEG2, -f)
479
  const handSwing = (ph: number): V => {
 
502
  }
503
 
504
  /** Side-view walking hero. (x,y) = feet on ground, h = total height. */
505
+ export function heroWalk(ctx: C2D, x: number, y: number, h: number, phase: number, o: HeroWalkOpts = {}): Pose {
506
  const f = o.facing ?? 1
507
  const lw = Math.max(1, h * 0.007)
508
  const p = walkPose(x, y, h, phase, o)
509
  contactShadow(ctx, x, y, h * 0.2)
510
  drawFar(ctx, p, h, f, lw)
511
+ drawNear(ctx, p, h, f, lw, { t: o.t, wind: (o.run ?? 0) * 0.6 + 0.1, eyes: o.eyes ?? 'closed', rim: o.rim, scarf: o.scarf })
512
+ return p
513
  }
514
 
515
  function contactShadow(ctx: C2D, x: number, y: number, w: number) {
 
555
  // tyre
556
  ctx.beginPath()
557
  ctx.arc(cx, cy, R, 0, Math.PI * 2)
558
+ ink(ctx, C.tire, lw)
559
  ctx.strokeStyle = 'rgba(140,150,165,0.35)'
560
  ctx.lineWidth = Math.max(1, s * 0.008)
561
  ctx.beginPath()
562
  ctx.arc(cx, cy, R * 0.92, Math.PI * 1.05, Math.PI * 1.55)
563
  ctx.stroke()
564
  // rim
565
+ ctx.strokeStyle = C.chrome
566
  ctx.lineWidth = Math.max(1, s * 0.022)
567
  ctx.beginPath()
568
  ctx.arc(cx, cy, R * 0.7, 0, Math.PI * 2)
 
572
  ctx.arc(cx, cy, R * 0.66, 0, Math.PI * 2)
573
  ctx.fill()
574
  // spokes
575
+ ctx.strokeStyle = rgba(C.chrome, 0.85)
576
  ctx.lineWidth = Math.max(1, s * 0.005)
577
  ctx.beginPath()
578
  for (let k = 0; k < 16; k++) {
 
584
  ctx.stroke()
585
  if (front) {
586
  // brake disc
587
+ ctx.strokeStyle = rgba(C.chromeShade, 0.9)
588
  ctx.lineWidth = Math.max(1, s * 0.03)
589
  ctx.beginPath()
590
  ctx.arc(cx, cy, R * 0.33, 0, Math.PI * 2)
591
  ctx.stroke()
592
  }
593
+ circle(ctx, { x: cx, y: cy }, R * 0.13, C.chrome, lw)
594
+ circle(ctx, { x: cx, y: cy }, R * 0.05, C.chromeShade, 0)
595
  }
596
 
597
  /** bike drawn at origin facing +x (ground at y = 0) */
 
614
  ctx.fill()
615
  if (o.beam && light > 0) lightCone(ctx, X(0.55), Y(0.72), s * 3.2, 0.17, -Math.PI / 2, '#fff1c8', 0.16 * light)
616
  // side stand
617
+ if (o.parked) capsule(ctx, { x: X(-0.06), y: Y(0.28) }, { x: X(-0.16), y: Y(0.005) }, s * 0.012, s * 0.01, C.bikeShade, lw)
618
  wheel(ctx, rx, wy, R, s, spin, false, lw)
619
  wheel(ctx, fx, wy, R, s, spin, true, lw)
620
  // swing arm
621
+ capsule(ctx, { x: X(-0.1), y: Y(0.3) }, { x: rx, y: wy }, s * 0.03, s * 0.022, C.bike, lw)
622
  // chain
623
  ctx.strokeStyle = '#3a3f48'
624
  ctx.lineWidth = Math.max(1, s * 0.008)
 
633
  {
634
  const a = { x: X(-0.36), y: Y(0.58) }
635
  const b = { x: rx + R * 0.15, y: wy - R * 0.1 }
636
+ capsule(ctx, a, b, s * 0.016, s * 0.016, C.chromeShade, lw)
637
  ctx.strokeStyle = '#d8b04a'
638
  ctx.lineWidth = Math.max(1, s * 0.009)
639
  ctx.beginPath()
 
649
  ctx.stroke()
650
  }
651
  // frame tubes
652
+ capsule(ctx, { x: X(0.36), y: Y(0.78) }, { x: X(0.12), y: Y(0.24) }, s * 0.024, s * 0.024, C.bike, lw)
653
+ capsule(ctx, { x: X(0.36), y: Y(0.78) }, { x: X(-0.44), y: Y(0.6) }, s * 0.022, s * 0.022, C.bike, lw)
654
  // engine: crankcase + finned cylinder
655
  ctx.beginPath()
656
  ctx.moveTo(X(-0.16), Y(0.44))
 
666
  ctx.beginPath()
667
  ctx.rect(-s * 0.075, -s * 0.11, s * 0.15, s * 0.17)
668
  ink(ctx, '#2a2f37', lw)
669
+ ctx.strokeStyle = C.chrome
670
  ctx.lineWidth = Math.max(1, s * 0.009)
671
  ctx.beginPath()
672
  for (let k = 0; k < 6; k++) {
 
676
  }
677
  ctx.stroke()
678
  ctx.restore()
679
+ circle(ctx, { x: X(0.0), y: Y(0.3) }, s * 0.075, C.chromeShade, lw)
680
+ circle(ctx, { x: X(0.0), y: Y(0.3) }, s * 0.05, C.chrome, 0)
681
  // exhaust: header + muffler
682
+ ctx.strokeStyle = C.line
683
  ctx.lineWidth = s * 0.05
684
  ctx.beginPath()
685
  ctx.moveTo(X(0.2), Y(0.5))
686
  ctx.quadraticCurveTo(X(0.28), Y(0.22), X(0.05), Y(0.16))
687
  ctx.lineTo(X(-0.25), Y(0.2))
688
  ctx.stroke()
689
+ ctx.strokeStyle = C.chrome
690
  ctx.lineWidth = s * 0.034
691
  ctx.stroke()
692
+ capsule(ctx, { x: X(-0.22), y: Y(0.2) }, { x: X(-0.64), y: Y(0.3) }, s * 0.04, s * 0.045, C.chrome, lw)
693
  ctx.strokeStyle = rgba('#ffffff', 0.55)
694
  ctx.lineWidth = Math.max(1, s * 0.008)
695
  ctx.beginPath()
 
704
  ctx.lineTo(X(-0.14), Y(0.42))
705
  ctx.lineTo(X(-0.34), Y(0.44))
706
  ctx.closePath()
707
+ ink(ctx, C.bike, lw)
708
+ circle(ctx, { x: X(-0.25), y: Y(0.51) }, s * 0.025, C.chromeShade, lw)
709
  // rear fender + tail light + plate
710
  ctx.beginPath()
711
  ctx.moveTo(X(-0.4), Y(0.6))
 
713
  ctx.lineTo(X(-0.68), Y(0.46))
714
  ctx.quadraticCurveTo(X(-0.6), Y(0.56), X(-0.4), Y(0.55))
715
  ctx.closePath()
716
+ ink(ctx, C.bike, lw)
717
  ctx.beginPath()
718
  ctx.rect(X(-0.72), Y(0.46), s * 0.06, s * 0.08)
719
  ink(ctx, '#e8e2d6', lw)
 
729
  ctx.quadraticCurveTo(X(0.02), Y(0.62), X(0.0), Y(0.58))
730
  ctx.lineTo(X(-0.44), Y(0.57))
731
  ctx.closePath()
732
+ ink(ctx, C.seat, lw)
733
  ctx.strokeStyle = 'rgba(200,180,150,0.25)'
734
  ctx.lineWidth = Math.max(1, s * 0.004)
735
  ctx.setLineDash([s * 0.012, s * 0.01])
 
746
  ctx.quadraticCurveTo(X(0.36), Y(0.58), X(0.22), Y(0.56))
747
  ctx.quadraticCurveTo(X(0.06), Y(0.54), X(-0.04), Y(0.6))
748
  ctx.closePath()
749
+ ink(ctx, C.bike, lw)
750
+ ctx.strokeStyle = rgba(C.bikeHi, 0.9)
751
  ctx.lineWidth = Math.max(1, s * 0.014)
752
  ctx.beginPath()
753
  ctx.moveTo(X(0.04), Y(0.72))
 
755
  ctx.stroke()
756
  ctx.beginPath()
757
  ctx.ellipse(X(0.2), Y(0.66), s * 0.045, s * 0.03, 0, 0, Math.PI * 2)
758
+ ink(ctx, C.chrome, lw)
759
  ctx.fillStyle = '#c4142f'
760
  ctx.beginPath()
761
  ctx.ellipse(X(0.2), Y(0.66), s * 0.026, s * 0.015, 0, 0, Math.PI * 2)
 
764
  ctx.ellipse(X(0.04), Y(0.6), s * 0.05, s * 0.03, -0.2, 0, Math.PI * 2)
765
  ink(ctx, '#202228', lw)
766
  // front fork + fender
767
+ capsule(ctx, { x: X(0.37), y: Y(0.8) }, { x: fx, y: wy }, s * 0.022, s * 0.02, C.chrome, lw)
768
  capsule(ctx, { x: X(0.44), y: Y(0.4) }, { x: X(0.49), y: Y(0.27) }, s * 0.03, s * 0.028, '#2a2e36', lw)
769
+ ctx.strokeStyle = C.line
770
  ctx.lineWidth = s * 0.05
771
  ctx.beginPath()
772
  ctx.arc(fx, wy, R * 1.12, Math.PI * 1.08, Math.PI * 1.72)
773
  ctx.stroke()
774
+ ctx.strokeStyle = C.bike
775
  ctx.lineWidth = s * 0.034
776
  ctx.stroke()
777
  // handlebar + grips + lever
778
+ capsule(ctx, { x: X(0.37), y: Y(0.82) }, { x: X(0.31), y: Y(0.86) }, s * 0.011, s * 0.011, C.chrome, lw)
779
  capsule(ctx, { x: X(0.31), y: Y(0.86) }, { x: X(0.24), y: Y(0.84) }, s * 0.018, s * 0.018, '#0e0f12', lw)
780
+ ctx.strokeStyle = C.chromeShade
781
  ctx.lineWidth = Math.max(1, s * 0.008)
782
  ctx.beginPath()
783
  ctx.moveTo(X(0.31), Y(0.86))
 
787
  circle(ctx, { x: X(0.38), y: Y(0.86) }, s * 0.03, '#1a1c22', lw)
788
  circle(ctx, { x: X(0.38), y: Y(0.86) }, s * 0.018, '#d9e2c9', 0)
789
  // mirror
790
+ ctx.strokeStyle = C.chromeShade
791
  ctx.lineWidth = Math.max(1, s * 0.01)
792
  ctx.beginPath()
793
  ctx.moveTo(X(0.32), Y(0.86))
 
795
  ctx.stroke()
796
  ctx.beginPath()
797
  ctx.ellipse(X(0.31), Y(1.03), s * 0.04, s * 0.032, 0, 0, Math.PI * 2)
798
+ ink(ctx, C.chrome, lw)
799
  ctx.fillStyle = '#6d8296'
800
  ctx.beginPath()
801
  ctx.ellipse(X(0.31), Y(1.03), s * 0.026, s * 0.02, 0, 0, Math.PI * 2)
 
803
  // headlight: chrome bucket, glass, amber indicator
804
  ctx.beginPath()
805
  ctx.ellipse(X(0.46), Y(0.72), s * 0.07, s * 0.08, 0, 0, Math.PI * 2)
806
+ ink(ctx, C.chrome, lw)
807
  ctx.fillStyle = light > 0.1 ? '#fff6d8' : '#5a626c'
808
  ctx.beginPath()
809
  ctx.ellipse(X(0.5), Y(0.72), s * 0.035, s * 0.065, 0, 0, Math.PI * 2)
 
813
  ink(ctx, '#ffa63a', lw)
814
  if (light > 0.1) glowBlob(ctx, X(0.52), Y(0.72), s * 0.26, '#fff1c8', 0.9 * light)
815
  // foot peg
816
+ capsule(ctx, { x: X(-0.13), y: Y(0.3) }, { x: X(-0.06), y: Y(0.3) }, s * 0.012, s * 0.012, C.chromeShade, lw)
817
  }
818
 
819
  // ------------------------------------------------------------------ pushing the bike
 
906
  drawFar(ctx, p, h, f, lw)
907
  bike(ctx, x, y, s, { facing: f, light: o.light, spin: o.spin, beam: o.beam })
908
  // seat contact: the trousers sit on top of the seat
909
+ capsule(ctx, { x: hip.x - f * h * 0.05, y: hip.y + h * 0.01 }, { x: hip.x + f * h * 0.03, y: hip.y + h * 0.015 }, h * 0.05, h * 0.05, C.pants, lw)
910
  drawNear(ctx, p, h, f, lw, { t, wind: o.wind ?? 0.6, smile: o.smile, eyes: o.eyes ?? 'open', rim: o.rim })
911
  }
912
 
 
917
  const t = o.t ?? 0
918
  contactShadow(ctx, x, y, h * 0.2)
919
  // legs
920
+ capsule(ctx, { x: x - h * 0.05, y: y - h * 0.4 }, { x: x - h * 0.055, y: y - h * 0.03 }, h * 0.048, h * 0.038, C.pantsShade, lw)
921
+ capsule(ctx, { x: x + h * 0.05, y: y - h * 0.4 }, { x: x + h * 0.055, y: y - h * 0.03 }, h * 0.048, h * 0.038, C.pants, lw)
922
  for (const sd of [-1, 1]) {
923
  ctx.beginPath()
924
  ctx.ellipse(x + sd * h * 0.055, y - h * 0.015, h * 0.045, h * 0.025, 0, 0, Math.PI * 2)
925
+ ink(ctx, C.shoe, lw)
926
  }
927
  // arms
928
  for (const sd of [-1, 1]) {
929
+ capsule(ctx, { x: x + sd * h * 0.13 + sw, y: y - h * 0.63 }, { x: x + sd * h * 0.155, y: y - h * 0.4 }, h * 0.038, h * 0.032, C.sweaterShade, lw)
930
+ circle(ctx, { x: x + sd * h * 0.157, y: y - h * 0.375 }, h * 0.028, C.skin, lw)
931
  }
932
  // sweater
933
  ctx.beginPath()
 
937
  ctx.quadraticCurveTo(x + h * 0.16, y - h * 0.52, x + h * 0.14 + sw, y - h * 0.67)
938
  ctx.quadraticCurveTo(x + sw, y - h * 0.71, x - h * 0.14 + sw, y - h * 0.67)
939
  ctx.closePath()
940
+ ink(ctx, C.sweater, lw)
941
+ ctx.fillStyle = rgba(C.sweaterShade, 0.8)
942
  ctx.fillRect(x - h * 0.005, y - h * 0.66, h * 0.01, h * 0.28)
943
+ capsule(ctx, { x: x - h * 0.12, y: y - h * 0.385 }, { x: x + h * 0.12, y: y - h * 0.385 }, h * 0.018, h * 0.018, C.rib, lw)
944
  // neck + head from behind
945
  const r = h * 0.14
946
  const hx = x + sw * 1.2
947
  const hy = y - h * 0.7 - r * 0.9
948
+ capsule(ctx, { x: hx, y: y - h * 0.67 }, { x: hx, y: hy + r * 0.5 }, h * 0.026, h * 0.026, C.skinShade, lw)
949
  for (const sd of [-1, 1]) {
950
  ctx.beginPath()
951
  ctx.ellipse(hx + sd * r * 0.92, hy + r * 0.15, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
952
+ ink(ctx, C.skinShade, lw)
953
  }
954
  curls(ctx, hx, hy, r, 1, o.wind ?? 0, t, 'back')
955
  if (o.rim) {
 
972
  ctx.lineJoin = 'round'
973
  // --- far: handlebar, mirrors, headlight glow ahead
974
  glowBlob(ctx, 0, -s * 0.5, s * 0.5, '#fff1c8', 0.12)
975
+ capsule(ctx, { x: -s * 0.3, y: -s * 0.6 }, { x: s * 0.3, y: -s * 0.6 }, s * 0.01, s * 0.01, C.chrome, lw)
976
  for (const sd of [-1, 1]) {
977
+ ctx.strokeStyle = C.chromeShade
978
  ctx.lineWidth = Math.max(1, s * 0.008)
979
  ctx.beginPath()
980
  ctx.moveTo(sd * s * 0.25, -s * 0.6)
 
982
  ctx.stroke()
983
  ctx.beginPath()
984
  ctx.ellipse(sd * s * 0.305, -s * 0.735, s * 0.034, s * 0.027, 0, 0, Math.PI * 2)
985
+ ink(ctx, C.chrome, lw)
986
  ctx.fillStyle = '#6d8296'
987
  ctx.beginPath()
988
  ctx.ellipse(sd * s * 0.305, -s * 0.735, s * 0.022, s * 0.017, 0, 0, Math.PI * 2)
 
991
  // tank glimpsed between the knees
992
  ctx.beginPath()
993
  ctx.ellipse(0, -s * 0.47, s * 0.09, s * 0.06, 0, 0, Math.PI * 2)
994
+ ink(ctx, C.bike, lw)
995
  // --- rider: arms reach forward to the grips
996
  const h = s * 0.95
997
  for (const sd of [-1, 1]) {
998
  const shp = { x: sd * h * 0.13, y: -s * 0.78 }
999
  const grip = { x: sd * s * 0.27, y: -s * 0.6 }
1000
  const a = ik(shp, grip, h * 0.15, h * 0.14, sd > 0 ? -1 : 1)
1001
+ capsule(ctx, shp, a.j, h * 0.04, h * 0.035, C.sweaterShade, lw)
1002
+ capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, C.sweaterShade, lw)
1003
+ circle(ctx, a.e, h * 0.03, C.skinShade, lw)
1004
  }
1005
  // back
1006
  ctx.beginPath()
 
1009
  ctx.quadraticCurveTo(0, -s * 0.84, h * 0.13, -s * 0.8)
1010
  ctx.quadraticCurveTo(h * 0.19, -s * 0.66, h * 0.16, -s * 0.47)
1011
  ctx.closePath()
1012
+ ink(ctx, C.sweater, lw)
1013
+ ctx.fillStyle = rgba(C.sweaterShade, 0.85)
1014
  ctx.fillRect(-h * 0.006, -s * 0.79, h * 0.012, s * 0.3)
1015
+ capsule(ctx, { x: -h * 0.155, y: -s * 0.475 }, { x: h * 0.155, y: -s * 0.475 }, h * 0.018, h * 0.018, C.rib, lw)
1016
  // neck + hair
1017
  const r = h * 0.14
1018
+ capsule(ctx, { x: 0, y: -s * 0.8 }, { x: 0, y: -s * 0.86 }, h * 0.026, h * 0.026, C.skinShade, lw)
1019
  curls(ctx, 0, -s * 0.84 - r * 0.85, r, 1, wind, t, 'back')
1020
  // legs out to the pegs (both sides)
1021
  for (const sd of [-1, 1]) {
1022
  const hipp = { x: sd * h * 0.08, y: -s * 0.44 }
1023
  const peg = { x: sd * s * 0.17, y: -s * 0.2 }
1024
  const k = ik(hipp, peg, h * 0.2, h * 0.19, sd > 0 ? -1 : 1)
1025
+ capsule(ctx, hipp, k.j, h * 0.05, h * 0.044, sd > 0 ? C.pants : C.pantsShade, lw)
1026
+ capsule(ctx, k.j, k.e, h * 0.044, h * 0.036, sd > 0 ? C.pants : C.pantsShade, lw)
1027
  ctx.beginPath()
1028
  ctx.ellipse(k.e.x + sd * h * 0.01, k.e.y + h * 0.01, h * 0.04, h * 0.03, 0, 0, Math.PI * 2)
1029
+ ink(ctx, C.shoe, lw)
1030
  }
1031
  // --- near: seat edge, twin shocks, mufflers, rear tyre, fender, tail light, plate
1032
  ctx.beginPath()
1033
  ctx.ellipse(0, -s * 0.43, h * 0.13, s * 0.032, 0, 0, Math.PI * 2)
1034
+ ink(ctx, C.seat, lw)
1035
  for (const sd of [-1, 1]) {
1036
  // rear shock absorbers with yellow springs
1037
  const a = { x: sd * s * 0.11, y: -s * 0.42 }
1038
  const b = { x: sd * s * 0.1, y: -s * 0.17 }
1039
+ capsule(ctx, a, b, s * 0.014, s * 0.014, C.chromeShade, lw)
1040
  ctx.strokeStyle = '#d8b04a'
1041
  ctx.lineWidth = Math.max(1, s * 0.008)
1042
  ctx.beginPath()
 
1046
  }
1047
  ctx.stroke()
1048
  // muffler on each side
1049
+ capsule(ctx, { x: sd * s * 0.17, y: -s * 0.16 }, { x: sd * s * 0.19, y: -s * 0.25 }, s * 0.036, s * 0.042, C.chrome, lw)
1050
  circle(ctx, { x: sd * s * 0.19, y: -s * 0.25 }, s * 0.024, '#2a2f37', lw)
1051
  }
1052
  // fat rear tyre with tread
1053
  ctx.beginPath()
1054
  ctx.ellipse(0, -s * 0.15, s * 0.085, s * 0.16, 0, 0, Math.PI * 2)
1055
+ ink(ctx, C.tire, lw)
1056
  ctx.strokeStyle = 'rgba(140,150,165,0.4)'
1057
  ctx.lineWidth = Math.max(1, s * 0.006)
1058
  ctx.beginPath()
 
1068
  ctx.lineTo(s * 0.08, -s * 0.36)
1069
  ctx.lineTo(-s * 0.08, -s * 0.36)
1070
  ctx.closePath()
1071
+ ink(ctx, C.bike, lw)
1072
  ctx.beginPath()
1073
  ctx.rect(-s * 0.05, -s * 0.27, s * 0.1, s * 0.05)
1074
  ink(ctx, '#e8e2d6', lw)
 
1154
  ctx.globalAlpha = 1
1155
  }
1156
 
1157
+ // ------------------------------------------------------------------ front head + portrait
1158
  export interface PortraitOpts {
1159
  t: number
1160
  eyes?: number // 0 closed .. 1 open
 
1162
  wind?: number
1163
  rim?: string
1164
  smile?: boolean
1165
+ tilt?: number
1166
  }
1167
 
1168
+ /** Front-facing head. (cx,cy) = face centre, r = face radius. */
1169
+ export function frontHead(ctx: C2D, cx: number, cy: number, r: number, o: PortraitOpts) {
 
1170
  const t = o.t
1171
  const lw = Math.max(1, r * 0.035)
1172
+ ctx.save()
1173
+ ctx.translate(cx, cy)
1174
+ ctx.rotate(o.tilt ?? 0)
1175
+ ctx.translate(-cx, -cy)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1176
  // back hair volume
1177
+ ctx.fillStyle = C.line
1178
  ctx.beginPath()
1179
  ctx.ellipse(cx, cy - r * 0.15, r * 1.34, r * 1.22, 0, 0, Math.PI * 2)
1180
  ctx.fill()
1181
+ ctx.fillStyle = C.hair
1182
  ctx.beginPath()
1183
  ctx.ellipse(cx, cy - r * 0.15, r * 1.3, r * 1.18, 0, 0, Math.PI * 2)
1184
  ctx.fill()
 
1185
  for (const sd of [-1, 1]) {
1186
  ctx.beginPath()
1187
  ctx.ellipse(cx + sd * r * 0.95, cy + r * 0.12, r * 0.15, r * 0.24, 0, 0, Math.PI * 2)
1188
+ ink(ctx, C.skinShade, lw)
1189
  }
1190
  // face (square-ish jaw)
1191
  ctx.beginPath()
 
1196
  ctx.lineTo(cx + r * 0.94, cy - r * 0.2)
1197
  ctx.quadraticCurveTo(cx, cy - r * 1.05, cx - r * 0.94, cy - r * 0.2)
1198
  ctx.closePath()
1199
+ ink(ctx, C.skin, lw)
1200
+ ctx.fillStyle = rgba(C.skinShade, 0.35)
1201
  ctx.beginPath()
1202
  ctx.ellipse(cx - r * 0.6, cy + r * 0.5, r * 0.3, r * 0.35, 0.3, 0, Math.PI * 2)
1203
  ctx.fill()
1204
+ ctx.fillStyle = rgba(C.blush, 0.16)
1205
  ctx.beginPath()
1206
  ctx.ellipse(cx - r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
1207
  ctx.ellipse(cx + r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
1208
  ctx.fill()
1209
+ // eyes + thick brows
1210
  const open = o.eyes ?? 0
1211
  ctx.strokeStyle = '#21160f'
1212
  ctx.fillStyle = '#21160f'
 
1237
  ctx.restore()
1238
  }
1239
  // nose + mouth
1240
+ ctx.strokeStyle = rgba(C.skinShade, 0.95)
1241
  ctx.lineWidth = Math.max(1, r * 0.05)
1242
  ctx.beginPath()
1243
  ctx.moveTo(cx + r * 0.02, cy + r * 0.25)
 
1252
  ctx.quadraticCurveTo(cx, cy + r * 0.6, cx + r * 0.13, cy + r * 0.66)
1253
  }
1254
  ctx.stroke()
 
1255
  const tear = o.tear ?? 0
1256
  if (tear > 0) {
1257
  const ty = cy + r * 0.2 + tear * r * 0.55
 
1270
  curls(ctx, cx, cy - r * 0.38, r * 1.1, 1, o.wind ?? 0, t, 'front')
1271
  const fr: { x: number; y: number; rr: number }[] = []
1272
  for (let i = 0; i < 7; i++) fr.push({ x: cx + (i - 3) * r * 0.26, y: cy - r * 0.66 + Math.abs(i - 3) * r * 0.06 + Math.sin(t * 2 + i) * r * 0.01, rr: r * (0.2 + 0.05 * hash(i * 9.1)) })
1273
+ ctx.fillStyle = C.line
1274
  ctx.beginPath()
1275
  for (const p of fr) {
1276
  ctx.moveTo(p.x + p.rr + lw, p.y)
1277
  ctx.arc(p.x, p.y, p.rr + lw, 0, Math.PI * 2)
1278
  }
1279
  ctx.fill()
1280
+ ctx.fillStyle = C.hair
1281
  ctx.beginPath()
1282
  for (const p of fr) {
1283
  ctx.moveTo(p.x + p.rr, p.y)
1284
  ctx.arc(p.x, p.y, p.rr, 0, Math.PI * 2)
1285
  }
1286
  ctx.fill()
1287
+ ctx.strokeStyle = C.hairHi
1288
  ctx.lineWidth = Math.max(1, r * 0.05)
1289
  ctx.beginPath()
1290
  for (const p of fr) {
 
1299
  ctx.arc(cx, cy - r * 0.2, r * 1.45, Math.PI * 1.08, Math.PI * 1.55)
1300
  ctx.stroke()
1301
  }
1302
+ ctx.restore()
1303
+ }
1304
+
1305
+ /** Front-facing bust. (cx,cy) = face centre, size = face radius. */
1306
+ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o: PortraitOpts) {
1307
+ const r = size
1308
+ const lw = Math.max(1, r * 0.035)
1309
+ ctx.beginPath()
1310
+ ctx.moveTo(cx - r * 2.5, cy + r * 3.3)
1311
+ ctx.quadraticCurveTo(cx - r * 2.4, cy + r * 1.5, cx - r * 0.55, cy + r * 1.28)
1312
+ ctx.lineTo(cx + r * 0.55, cy + r * 1.28)
1313
+ ctx.quadraticCurveTo(cx + r * 2.4, cy + r * 1.5, cx + r * 2.5, cy + r * 3.3)
1314
+ ctx.closePath()
1315
+ ink(ctx, C.sweater, lw)
1316
+ ctx.fillStyle = C.sweaterShade
1317
+ ctx.beginPath()
1318
+ ctx.moveTo(cx - r * 2.5, cy + r * 3.3)
1319
+ ctx.quadraticCurveTo(cx - r * 2.4, cy + r * 1.5, cx - r * 1.3, cy + r * 1.34)
1320
+ ctx.quadraticCurveTo(cx - r * 1.7, cy + r * 2.2, cx - r * 1.6, cy + r * 3.3)
1321
+ ctx.closePath()
1322
+ ctx.fill()
1323
+ ctx.strokeStyle = rgba(C.sweaterHi, 0.35)
1324
+ ctx.lineWidth = Math.max(1, r * 0.03)
1325
+ ctx.beginPath()
1326
+ for (let k = -3; k <= 3; k++) {
1327
+ ctx.moveTo(cx + k * r * 0.45, cy + r * 1.75)
1328
+ ctx.lineTo(cx + k * r * 0.5, cy + r * 3.2)
1329
+ }
1330
+ ctx.stroke()
1331
+ ctx.beginPath()
1332
+ ctx.rect(cx - r * 0.34, cy + r * 0.65, r * 0.68, r * 0.72)
1333
+ ink(ctx, C.skinShade, lw)
1334
+ ctx.beginPath()
1335
+ ctx.ellipse(cx, cy + r * 1.34, r * 0.6, r * 0.2, 0, 0, Math.PI)
1336
+ ctx.strokeStyle = C.line
1337
+ ctx.lineWidth = r * 0.2
1338
+ ctx.stroke()
1339
+ ctx.strokeStyle = C.rib
1340
+ ctx.lineWidth = r * 0.15
1341
+ ctx.stroke()
1342
+ frontHead(ctx, cx, cy, r, o)
1343
+ }
1344
+
1345
+ // ------------------------------------------------------------------ front-view body (sitting)
1346
+ function frontTorso(ctx: C2D, cx: number, hipY: number, shY: number, h: number, lw: number) {
1347
+ const sw = h * 0.16
1348
+ const ww = h * 0.13
1349
+ ctx.beginPath()
1350
+ ctx.moveTo(cx - ww, hipY)
1351
+ ctx.quadraticCurveTo(cx - sw * 1.05, (hipY + shY) / 2, cx - sw, shY + h * 0.02)
1352
+ ctx.quadraticCurveTo(cx - sw * 0.6, shY - h * 0.02, cx, shY - h * 0.015)
1353
+ ctx.quadraticCurveTo(cx + sw * 0.6, shY - h * 0.02, cx + sw, shY + h * 0.02)
1354
+ ctx.quadraticCurveTo(cx + sw * 1.05, (hipY + shY) / 2, cx + ww, hipY)
1355
+ ctx.closePath()
1356
+ ink(ctx, C.sweater, lw)
1357
+ ctx.fillStyle = rgba(C.sweaterShade, 0.85)
1358
+ ctx.beginPath()
1359
+ ctx.moveTo(cx - ww, hipY)
1360
+ ctx.quadraticCurveTo(cx - sw * 1.05, (hipY + shY) / 2, cx - sw, shY + h * 0.02)
1361
+ ctx.lineTo(cx - sw * 0.55, shY + h * 0.03)
1362
+ ctx.quadraticCurveTo(cx - ww * 0.8, (hipY + shY) / 2, cx - ww * 0.55, hipY)
1363
+ ctx.closePath()
1364
+ ctx.fill()
1365
+ ctx.strokeStyle = rgba(C.sweaterHi, 0.3)
1366
+ ctx.lineWidth = Math.max(1, h * 0.004)
1367
+ ctx.beginPath()
1368
+ for (let k = -2; k <= 2; k++) {
1369
+ ctx.moveTo(cx + k * h * 0.05, shY + h * 0.05)
1370
+ ctx.lineTo(cx + k * h * 0.045, hipY - h * 0.03)
1371
+ }
1372
+ ctx.stroke()
1373
+ capsule(ctx, { x: cx - ww, y: hipY - h * 0.01 }, { x: cx + ww, y: hipY - h * 0.01 }, h * 0.018, h * 0.018, C.rib, lw)
1374
+ // crew collar + neck
1375
+ capsule(ctx, { x: cx, y: shY }, { x: cx, y: shY - h * 0.05 }, h * 0.034, h * 0.032, C.skinShade, lw)
1376
+ ctx.beginPath()
1377
+ ctx.ellipse(cx, shY + h * 0.005, h * 0.05, h * 0.02, 0, 0, Math.PI)
1378
+ ctx.strokeStyle = C.rib
1379
+ ctx.lineWidth = h * 0.016
1380
+ ctx.stroke()
1381
+ }
1382
+
1383
+ function frontShoe(ctx: C2D, p: V, h: number, lw: number) {
1384
+ ctx.beginPath()
1385
+ ctx.ellipse(p.x, p.y - h * 0.018, h * 0.045, h * 0.03, 0, 0, Math.PI * 2)
1386
+ ink(ctx, C.shoe, lw)
1387
+ ctx.fillStyle = C.sole
1388
+ ctx.fillRect(p.x - h * 0.045, p.y - h * 0.008, h * 0.09, h * 0.01)
1389
+ }
1390
+
1391
+ /**
1392
+ * Hero sitting side-saddle on his parked bike, body turned to the camera.
1393
+ * (x,y) = bike ground point, s = bike scale.
1394
+ */
1395
+ export function heroSideSit(ctx: C2D, x: number, y: number, s: number, o: { facing?: number; t?: number; light?: number; beam?: boolean; look?: number; rim?: string } = {}) {
1396
+ const f = o.facing ?? 1
1397
+ const t = o.t ?? 0
1398
+ const h = HERO_H * s
1399
+ const lw = Math.max(1, h * 0.007)
1400
+ const A = bikeAnchors(x, y, s, f)
1401
+ bike(ctx, x, y, s, { facing: f, light: o.light, beam: o.beam, parked: true })
1402
+ const cx = A.seat.x + f * s * 0.04
1403
+ const hipY = A.seat.y - h * 0.02
1404
+ const breathe = Math.sin(t * 1.6) * h * 0.004
1405
+ const shY = hipY - h * TORSO + breathe
1406
+ // legs dangle on the near side, feet resting at foot-peg height
1407
+ const footY = A.peg.y + s * 0.02
1408
+ const swing = Math.sin(t * 1.3) * h * 0.012
1409
+ const hipL = { x: cx - h * 0.07, y: hipY }
1410
+ const hipR = { x: cx + h * 0.07, y: hipY }
1411
+ const kneeL = { x: cx - h * 0.09, y: hipY + h * 0.06 }
1412
+ const kneeR = { x: cx + h * 0.1, y: hipY + h * 0.06 }
1413
+ const footL = { x: cx - h * 0.1 + swing, y: footY }
1414
+ const footR = { x: cx + h * 0.12, y: footY - h * 0.01 }
1415
+ frontTorso(ctx, cx, hipY, shY, h, lw)
1416
+ for (const [hp, kn, ft] of [
1417
+ [hipL, kneeL, footL],
1418
+ [hipR, kneeR, footR],
1419
+ ] as [V, V, V][]) {
1420
+ capsule(ctx, hp, kn, h * 0.062, h * 0.056, C.pants, lw)
1421
+ capsule(ctx, kn, ft, h * 0.048, h * 0.04, C.pants, lw)
1422
+ frontShoe(ctx, ft, h, lw)
1423
+ }
1424
+ // arms resting on the knees, hands loosely together
1425
+ const hands = { x: cx + h * 0.005, y: kneeL.y - h * 0.02 }
1426
+ for (const sd of [-1, 1]) {
1427
+ const shp = { x: cx + sd * h * 0.15, y: shY + h * 0.03 }
1428
+ const a = ik(shp, { x: hands.x + sd * h * 0.03, y: hands.y }, h * ARM1, h * ARM2, sd)
1429
+ capsule(ctx, shp, a.j, h * 0.04, h * 0.035, sd < 0 ? C.sweaterShade : C.sweater, lw)
1430
+ capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, sd < 0 ? C.sweaterShade : C.sweater, lw)
1431
+ circle(ctx, a.e, h * 0.03, C.skin, lw)
1432
+ }
1433
+ const r = h * 0.14
1434
+ frontHead(ctx, cx, shY - h * 0.05 - r * 0.85, r, { t, eyes: 0.8, tilt: (o.look ?? 0) * 0.15, rim: o.rim, wind: 0.1 })
1435
+ }
1436
+
1437
+ // ------------------------------------------------------------------ sitting on the ground with a newspaper (front view)
1438
+ export interface PaperState {
1439
+ /** 0..1 left hand bringing the lighter to the corner */
1440
+ lighter?: number
1441
+ /** lighter flame visible */
1442
+ lit?: boolean
1443
+ /** 0..1 burn progress (from the bottom-left corner) */
1444
+ burn?: number
1445
+ /** 0 held … 1 lying on the ground */
1446
+ drop?: number
1447
+ }
1448
+
1449
+ function paperSheet(ctx: C2D, w: number, hh: number, burn: number, t: number) {
1450
+ // local: (0,0) top-left, (w,hh) bottom-right
1451
+ const lw = Math.max(1, w * 0.008)
1452
+ ctx.save()
1453
+ // unburned region: py < px + 1 - 2p (normalised)
1454
+ if (burn > 0) {
1455
+ const p = burn
1456
+ ctx.beginPath()
1457
+ ctx.moveTo(-0.5 * w, (0.5 - 2 * p) * hh)
1458
+ ctx.lineTo(1.5 * w, (2.5 - 2 * p) * hh)
1459
+ ctx.lineTo(1.5 * w, -1 * hh)
1460
+ ctx.lineTo(-0.5 * w, -1 * hh)
1461
+ ctx.closePath()
1462
+ ctx.clip()
1463
+ }
1464
+ ctx.beginPath()
1465
+ ctx.rect(0, 0, w, hh)
1466
+ ink(ctx, '#e9e3d3', lw)
1467
+ // fold line + print
1468
+ ctx.strokeStyle = 'rgba(90,80,60,0.35)'
1469
+ ctx.lineWidth = lw
1470
+ ctx.beginPath()
1471
+ ctx.moveTo(w / 2, 0)
1472
+ ctx.lineTo(w / 2, hh)
1473
+ ctx.stroke()
1474
+ ctx.fillStyle = '#1d1b18'
1475
+ ctx.font = `${hh * 0.16}px "MV Black", sans-serif`
1476
+ ctx.textBaseline = 'top'
1477
+ ctx.fillText('黑街晚报', w * 0.06, hh * 0.05)
1478
+ ctx.fillRect(w * 0.06, hh * 0.25, w * 0.38, hh * 0.012)
1479
+ ctx.fillStyle = 'rgba(40,36,30,0.55)'
1480
+ for (let c = 0; c < 2; c++)
1481
+ for (let k = 0; k < 9; k++) ctx.fillRect(w * (0.06 + c * 0.2), hh * (0.31 + k * 0.07), w * (0.16 - (k === 8 ? 0.06 : 0)), Math.max(1, hh * 0.022))
1482
+ ctx.fillStyle = 'rgba(40,36,30,0.75)'
1483
+ ctx.fillRect(w * 0.55, hh * 0.08, w * 0.38, hh * 0.4)
1484
+ ctx.fillStyle = 'rgba(200,190,170,0.6)'
1485
+ ctx.beginPath()
1486
+ ctx.arc(w * 0.74, hh * 0.3, hh * 0.1, 0, Math.PI * 2)
1487
+ ctx.fill()
1488
+ ctx.fillStyle = 'rgba(40,36,30,0.55)'
1489
+ for (let k = 0; k < 5; k++) ctx.fillRect(w * 0.55, hh * (0.56 + k * 0.08), w * 0.38, Math.max(1, hh * 0.022))
1490
+ ctx.restore()
1491
+ if (burn > 0 && burn < 1) {
1492
+ // charred band + flames along the burn front
1493
+ const p = burn
1494
+ ctx.save()
1495
+ ctx.beginPath()
1496
+ ctx.rect(0, 0, w, hh)
1497
+ ctx.clip()
1498
+ ctx.strokeStyle = 'rgba(30,18,8,0.9)'
1499
+ ctx.lineWidth = hh * 0.06
1500
+ ctx.beginPath()
1501
+ ctx.moveTo(-0.5 * w, (0.5 - 2 * p) * hh - hh * 0.03)
1502
+ ctx.lineTo(1.5 * w, (2.5 - 2 * p) * hh - hh * 0.03)
1503
+ ctx.stroke()
1504
+ ctx.strokeStyle = 'rgba(255,140,40,0.9)'
1505
+ ctx.lineWidth = hh * 0.02
1506
+ ctx.stroke()
1507
+ ctx.restore()
1508
+ for (let k = 0; k <= 8; k++) {
1509
+ const px = k / 8
1510
+ const py = px + 1 - 2 * p
1511
+ if (py < 0 || py > 1) continue
1512
+ flame(ctx, px * w, py * hh, hh * (0.12 + 0.08 * hash(k * 3.1 + Math.floor(t * 6))), t + k)
1513
+ }
1514
+ }
1515
+ }
1516
+
1517
+ /** Hero sits on the ground facing camera, knees up, a newspaper in front of his face. h = standing height. */
1518
+ export function heroSitPaper(ctx: C2D, x: number, y: number, h: number, t: number, st: PaperState = {}) {
1519
+ const lw = Math.max(1, h * 0.007)
1520
+ const hipY = y - h * 0.07
1521
+ const shY = hipY - h * TORSO
1522
+ const r = h * 0.14
1523
+ contactShadow(ctx, x, y, h * 0.28)
1524
+ // torso + head (behind the paper)
1525
+ frontTorso(ctx, x, hipY, shY, h, lw)
1526
+ const headY = shY - h * 0.05 - r * 0.85
1527
+ const reveal = clamp(((st.burn ?? 0) - 0.25) / 0.3) + (st.drop ?? 0)
1528
+ frontHead(ctx, x, headY, r, { t, eyes: reveal > 0.5 ? 0.9 : 0, wind: 0.05, tilt: -0.05 })
1529
+ // knees up (in front of the torso)
1530
+ for (const sd of [-1, 1]) {
1531
+ const hp = { x: x + sd * h * 0.07, y: hipY }
1532
+ const kn = { x: x + sd * h * 0.12, y: y - h * 0.3 }
1533
+ const ft = { x: x + sd * h * 0.11, y }
1534
+ capsule(ctx, hp, kn, h * 0.06, h * 0.05, sd < 0 ? C.pantsShade : C.pants, lw)
1535
+ capsule(ctx, ft, kn, h * 0.042, h * 0.048, sd < 0 ? C.pantsShade : C.pants, lw)
1536
+ frontShoe(ctx, ft, h, lw)
1537
+ }
1538
+ // newspaper geometry
1539
+ const pw = h * 0.46
1540
+ const ph = h * 0.32
1541
+ const drop = st.drop ?? 0
1542
+ const burn = st.burn ?? 0
1543
+ const held = { x: x - pw / 2, y: headY - ph * 0.45 }
1544
+ const ground = { x: x - pw * 0.15, y: y + h * 0.04 }
1545
+ const px0 = held.x + (ground.x - held.x) * drop
1546
+ const py0 = held.y + (ground.y - held.y) * drop * drop
1547
+ const sy = 1 - drop * 0.72 // lying flat → foreshortened
1548
+ // hands: right hand holds the top-right edge; left hand holds the left edge or the lighter
1549
+ const rightHand = drop < 0.15 ? { x: px0 + pw, y: py0 + ph * 0.35 * sy } : { x: x + h * 0.14, y: y - h * 0.34 }
1550
+ const leftHold = { x: px0, y: py0 + ph * 0.5 * sy }
1551
+ const lighterPos = { x: px0 + pw * 0.02, y: py0 + ph * 1.04 }
1552
+ const restL = { x: x - h * 0.14, y: y - h * 0.34 }
1553
+ const lk = st.lighter ?? 0
1554
+ let leftHand: V
1555
+ if (burn > 0.3 || drop > 0) leftHand = restL
1556
+ else if (lk <= 0) leftHand = leftHold
1557
+ else if (lk < 0.5) leftHand = lerpV(leftHold, { x: x - h * 0.2, y: y - h * 0.25 }, lk * 2) // reach into the pocket
1558
+ else leftHand = lerpV({ x: x - h * 0.2, y: y - h * 0.25 }, lighterPos, (lk - 0.5) * 2)
1559
+ // arms (drawn before the paper when holding it up)
1560
+ const arms = () => {
1561
+ for (const [sd, hand] of [
1562
+ [-1, leftHand],
1563
+ [1, rightHand],
1564
+ ] as [number, V][]) {
1565
+ const shp = { x: x + sd * h * 0.15, y: shY + h * 0.03 }
1566
+ const a = ik(shp, hand, h * ARM1, h * ARM2, sd)
1567
+ capsule(ctx, shp, a.j, h * 0.04, h * 0.035, sd < 0 ? C.sweaterShade : C.sweater, lw)
1568
+ capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, sd < 0 ? C.sweaterShade : C.sweater, lw)
1569
+ circle(ctx, a.e, h * 0.03, C.skin, lw)
1570
+ }
1571
+ }
1572
+ if (burn < 1) {
1573
+ ctx.save()
1574
+ ctx.translate(px0, py0)
1575
+ ctx.scale(1, sy)
1576
+ ctx.rotate(-0.04 + drop * 0.25)
1577
+ paperSheet(ctx, pw, ph, burn, t)
1578
+ ctx.restore()
1579
+ } else {
1580
+ // ashes + embers on the ground
1581
+ ctx.fillStyle = 'rgba(30,26,22,0.85)'
1582
+ ctx.beginPath()
1583
+ ctx.ellipse(ground.x + pw * 0.45, ground.y + ph * 0.12, pw * 0.4, ph * 0.08, 0, 0, Math.PI * 2)
1584
+ ctx.fill()
1585
+ ctx.fillStyle = '#ff8a3d'
1586
+ for (let k = 0; k < 14; k++) {
1587
+ ctx.globalAlpha = 0.4 + 0.6 * Math.abs(Math.sin(t * 3 + k))
1588
+ ctx.fillRect(ground.x + pw * (0.1 + 0.7 * hash(k)), ground.y + ph * (0.06 + 0.12 * hash(k * 2)), h * 0.008, h * 0.008)
1589
+ }
1590
+ ctx.globalAlpha = 1
1591
+ }
1592
+ arms()
1593
+ // the lighter
1594
+ if (lk > 0.5 && burn <= 0.3 && drop === 0) {
1595
+ ctx.save()
1596
+ ctx.translate(leftHand.x, leftHand.y)
1597
+ ctx.beginPath()
1598
+ ctx.rect(-h * 0.012, -h * 0.05, h * 0.024, h * 0.045)
1599
+ ink(ctx, '#c4142f', lw)
1600
+ ctx.beginPath()
1601
+ ctx.rect(-h * 0.012, -h * 0.062, h * 0.024, h * 0.014)
1602
+ ink(ctx, C.chrome, lw)
1603
+ ctx.restore()
1604
+ if (st.lit) flame(ctx, leftHand.x, leftHand.y - h * 0.062, h * 0.03, t)
1605
+ }
1606
+ // smoke / ash flakes drifting up while burning
1607
+ if (burn > 0) {
1608
+ for (let k = 0; k < 16; k++) {
1609
+ const life = fract(t * (0.3 + hash(k) * 0.3) + hash(k * 7))
1610
+ ctx.fillStyle = k % 3 ? `rgba(60,55,50,${0.5 * (1 - life)})` : `rgba(255,150,60,${0.8 * (1 - life)})`
1611
+ ctx.fillRect(px0 + pw * hash(k * 3.3) + Math.sin(t + k) * h * 0.03, py0 - life * h * 0.5, h * 0.012, h * 0.008)
1612
+ }
1613
+ }
1614
  }
src/mv/engine/renderer.ts CHANGED
@@ -16,7 +16,7 @@ export class Renderer {
16
  private post: Post | null
17
  private out2d: CanvasRenderingContext2D | null = null
18
  private cache = new Map<string, unknown>()
19
- private warned = false
20
  W = 0
21
  H = 0
22
 
@@ -75,8 +75,9 @@ export class Renderer {
75
  sc.fn(s)
76
  } catch (e) {
77
  // never let a single drawing glitch break playback / export
78
- if (!this.warned) console.warn('scene error', sc.id, t, e)
79
- this.warned = true
 
80
  }
81
  ctx.restore()
82
  ctx.setTransform(1, 0, 0, 1, 0, 0)
 
16
  private post: Post | null
17
  private out2d: CanvasRenderingContext2D | null = null
18
  private cache = new Map<string, unknown>()
19
+ private warned = new Set<string>()
20
  W = 0
21
  H = 0
22
 
 
75
  sc.fn(s)
76
  } catch (e) {
77
  // never let a single drawing glitch break playback / export
78
+ const key = sc.id + ':' + String(e)
79
+ if (!this.warned.has(key)) console.warn('scene error', sc.id, t.toFixed(2), String(e), (e as Error)?.stack?.split('\n')[1] ?? '')
80
+ this.warned.add(key)
81
  }
82
  ctx.restore()
83
  ctx.setTransform(1, 0, 0, 1, 0, 0)
src/mv/engine/scenesA.ts CHANGED
@@ -19,7 +19,7 @@ import {
19
  wetReflection,
20
  } from './draw'
21
  import { camera, resetCam, type SceneCtx } from './types'
22
- import { HERO_H, bike, heroPortrait, heroPush, heroRide, heroRideRear } from './hero'
23
  import {
24
  FONT,
25
  PALETTE,
@@ -39,7 +39,7 @@ import {
39
  smoothstep,
40
  } from './util'
41
 
42
- const SIGN_WORDS = ['旅馆', '当铺', '通宵', '麻将', '烧腊', '冰室', '粥', '按摩', '影院', '理发', '茶餐厅', '桌球', '夜宵', '酒', '当', '典当', '药房', '电玩']
43
  const SIGN_COLORS = [PALETTE.red, PALETTE.cyan, PALETTE.sodium, PALETTE.violet, PALETTE.teal, '#ff5fa2']
44
 
45
  const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
@@ -66,8 +66,8 @@ export function sIgnite(s: SceneCtx) {
66
  const zoom = 1 + lt * 0.014
67
  camera(s, zoom, W / 2, H * 0.47)
68
 
69
- const size = P ? Math.min(W * 0.46, H * 0.21) : Math.min(W * 0.27, H * 0.42)
70
- const cy = P ? H * 0.4 : H * 0.42
71
  const pos: [number, number][] = P
72
  ? [
73
  [W / 2, cy - size * 0.55],
@@ -106,7 +106,7 @@ export function sIgnite(s: SceneCtx) {
106
  const sub = 'BLACK STREET'
107
  const typed = Math.floor(clamp((lt - 4.2) / 1.4) * sub.length)
108
  if (typed > 0) {
109
- const sy = P ? cy + size * 1.55 : cy + size * 0.95
110
  const fs = P ? size * 0.26 : size * 0.22
111
  ctx.save()
112
  ctx.font = `${fs}px ${FONT.latin}`
@@ -123,18 +123,18 @@ export function sIgnite(s: SceneCtx) {
123
  ctx.font = `${(P ? W : H) * 0.022}px ${FONT.black}`
124
  ctx.textAlign = 'center'
125
  ctx.fillStyle = PALETTE.bone
126
- ctx.fillText('DJ鐘董 ·《黑街》DJ葱姜蒜进行曲', W / 2, P ? cy + size * 1.95 : cy + size * 1.25)
127
  ctx.restore()
128
  }
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, parked: true })
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)
140
  ctx.fillStyle = '#050608'
@@ -193,8 +193,8 @@ export function sStreet(s: SceneCtx) {
193
  const k0 = Math.floor(midScroll / midCell) - 1
194
  for (let k = k0; k < k0 + Math.ceil((W + ext) / midCell) + 2; k++) {
195
  if (hash(k * 5.7) < 0.4) continue
196
- const word = SIGN_WORDS[Math.floor(hash(k * 2.3) * SIGN_WORDS.length)]
197
- const col = SIGN_COLORS[Math.floor(hash(k * 8.1) * SIGN_COLORS.length)]
198
  const n = Array.from(word).length
199
  const sw = u * 50
200
  const sh = sw * n * 1.05 + sw * 0.4
@@ -203,61 +203,19 @@ export function sStreet(s: SceneCtx) {
203
  const on = hash(k * 4.4) > 0.8 ? flicker(t, k, 10) : 0.85 + 0.15 * a.mid
204
  neonSign(ctx, x, y, sw, sh, word, col, on, true)
205
  }
206
- // near shopfronts
207
- const nearCell = u * 270
208
  const kk0 = Math.floor(scroll / nearCell) - 1
209
  for (let k = kk0; k < kk0 + Math.ceil((W + ext) / nearCell) + 2; k++) {
210
  const x = k * nearCell - scroll
211
- const top = groundY - u * 300
212
- ctx.fillStyle = '#06080c'
213
- ctx.fillRect(x, top, nearCell + 1, groundY - top)
214
- const type = hash(k * 1.9)
215
- const doorX = x + nearCell * 0.1
216
- const doorW = nearCell * 0.8
217
- const doorTop = groundY - u * 175
218
- if (type < 0.45) {
219
- // rolling shutter
220
- ctx.fillStyle = '#0f1218'
221
- ctx.fillRect(doorX, doorTop, doorW, groundY - doorTop)
222
- ctx.fillStyle = 'rgba(120,140,160,0.08)'
223
- for (let y = doorTop; y < groundY; y += u * 7) ctx.fillRect(doorX, y, doorW, Math.max(1, u * 1.5))
224
- // graffiti tag
225
- if (type < 0.2) {
226
- ctx.save()
227
- ctx.font = `${u * 46}px ${FONT.neon}`
228
- ctx.fillStyle = rgba(PALETTE.red, 0.35)
229
- ctx.textAlign = 'center'
230
- ctx.fillText('黑街', doorX + doorW / 2, doorTop + u * 90)
231
- ctx.restore()
232
- }
233
- } else {
234
- // lit shop window
235
- const g = ctx.createLinearGradient(0, doorTop, 0, groundY)
236
- const warm = type > 0.75
237
- g.addColorStop(0, warm ? '#7a4520' : '#1a5560')
238
- g.addColorStop(1, warm ? '#f0a050' : '#45c0c8')
239
- ctx.fillStyle = g
240
- ctx.globalAlpha = 0.8 + 0.2 * flicker(t, k + 50, 3)
241
- ctx.fillRect(doorX, doorTop, doorW, groundY - doorTop)
242
- ctx.globalAlpha = 1
243
- glowBlob(ctx, doorX + doorW / 2, groundY, doorW * 0.9, warm ? PALETTE.sodium : PALETTE.cyan, 0.3)
244
- ctx.fillStyle = '#06080c'
245
- ctx.fillRect(doorX + doorW * 0.48, doorTop, u * 4, groundY - doorTop)
246
- ctx.fillRect(doorX, doorTop + (groundY - doorTop) * 0.45, doorW, u * 3)
247
- }
248
- // horizontal sign
249
- const word = SIGN_WORDS[Math.floor(hash(k * 6.3 + 1) * SIGN_WORDS.length)]
250
- const col = SIGN_COLORS[Math.floor(hash(k * 3.7 + 2) * SIGN_COLORS.length)]
251
- neonSign(ctx, x + nearCell * 0.12, top + u * 26, nearCell * 0.76, u * 60, word, col, hash(k * 9.1) > 0.85 ? flicker(t, k, 8) : 1, false)
252
- // AC unit
253
- ctx.fillStyle = '#10131a'
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 / HERO_H
260
- heroPush(ctx, wx + bs * 0.1, groundY + u * 2, bs, fract(phase), { t, spin: scroll / (bs * 0.23), light: 0.9, beam: true, rim: rgba(PALETTE.cyan, 0.8), eyes: 'closed' })
 
261
  // ground
262
  ctx.fillStyle = '#05070a'
263
  ctx.fillRect(-ext, groundY, W + ext * 3, H)
@@ -380,14 +338,10 @@ const POSTER_WORDS: string[][] = [
380
  const GRID_CHARS = ['黑', '街', '夜', '行', '王', '灯', '雨', '火', '醒', '狂', '燃', '跳', '闪', '冲', '霓', '虹']
381
 
382
  export function sDrop1(s: SceneCtx) {
383
- const { lt } = s
384
- const shot = Math.min(7, Math.floor(lt / BAR))
385
- const variant = shot >= 4 ? 1 : 0
386
- const kind = shot % 4
387
- if (kind === 0) posterShot(s, variant)
388
- else if (kind === 1) eqShot(s, variant)
389
- else if (kind === 2) runnerShot(s, variant)
390
- else gridShot(s, variant)
391
  }
392
 
393
  function posterShot(s: SceneCtx, variant: number) {
@@ -578,158 +532,385 @@ function gridShot(s: SceneCtx, variant: number) {
578
  void u
579
  }
580
 
581
- // =====================================================================
582
- // S5 — 山顶·红月 (56.35 – 72.95s) 阿飞 on his bike at the ridge,
583
- // a close-up of his face, then the city lights below
584
- // =====================================================================
585
- export function sRooftop(s: SceneCtx) {
586
- const { ctx, W, H, P, lt, u, t, a } = s
587
- const shotB = lt >= BAR * 3 && lt < BAR * 5
588
- const shotC = lt >= BAR * 5
589
- let zoom = 1
590
- let cx = W / 2
591
- let cy = H / 2
592
- const ridgeY = P ? H * 0.8 : H * 0.8
593
- const figX = P ? W * 0.5 : W * 0.34
594
- const bs = P ? W * 0.46 : H * 0.36
595
- if (!shotB && !shotC) {
596
- zoom = 1 + lt * 0.008
597
- } else if (shotC) {
598
- const k = (lt - BAR * 5) / (s.dur - BAR * 5)
599
- zoom = 1.12
600
- cx = W / 2 + lerp(-W * 0.12, W * 0.12, easeInOutCubic(k))
601
- cy = H / 2 + H * 0.06
602
- }
603
- cx += fbm(t * 0.6, 3) * u * 8 + a.kick * (hash(a.beat) - 0.5) * u * 14
604
- cy += fbm(t * 0.7, 4) * u * 6
605
-
606
- resetCam(s)
607
- vGradient(ctx, 0, 0, W, H, [
608
- [0, '#0a0307'],
609
- [0.45, '#2a0710'],
610
- [0.75, '#6a1a1c'],
611
- [1, '#2a0a10'],
612
- ])
613
- const mx = P ? W * 0.5 : W * 0.64
614
- const my = P ? H * 0.3 : H * 0.36
615
- const R = Math.min(W, H) * (P ? 0.36 : 0.3) * (1 + a.kick * 0.03)
616
-
617
- if (shotB) {
618
- // ---- close-up: his face in front of the moon, wind in the curls
619
- const k = (lt - BAR * 3) / (BAR * 2)
620
- const MR = Math.max(W, H) * 0.42
621
- const mmx = W / 2 + (P ? 0 : W * 0.18)
622
- const mmy = H * (P ? 0.32 : 0.4)
623
- glowBlob(ctx, mmx, mmy, MR * 2, '#ff3a2e', 0.45)
624
- const mg = ctx.createRadialGradient(mmx - MR * 0.3, mmy - MR * 0.3, MR * 0.1, mmx, mmy, MR)
625
- mg.addColorStop(0, '#ffd7a8')
626
- mg.addColorStop(0.5, '#ff7a4a')
627
- mg.addColorStop(1, '#b3122a')
628
- ctx.fillStyle = mg
629
  ctx.beginPath()
630
- ctx.arc(mmx, mmy, MR, 0, Math.PI * 2)
631
  ctx.fill()
632
- const fr = (P ? W * 0.2 : H * 0.2) * (1 + k * 0.05)
633
- const fx = P ? W / 2 : W * 0.38
634
- const fy = H * (P ? 0.5 : 0.52)
635
- const open = k < 0.45 ? 0 : clamp((k - 0.45) / 0.1)
636
- heroPortrait(ctx, fx, fy, fr, { t, eyes: open, wind: 0.6, rim: rgba('#ffb08a', 0.9), smile: k > 0.7 })
637
- // drifting embers / dust in the moonlight
638
- ctx.fillStyle = '#ffd0a0'
639
- for (let i = 0; i < 50; i++) {
640
- const x = fract(hash(i * 1.7) + lt * (0.03 + hash(i) * 0.04)) * W
641
- const y = hash(i * 3.1) * H
642
- ctx.globalAlpha = 0.3 + 0.5 * hash(i * 9)
643
- ctx.fillRect(x, y, u * 3, u * 3)
644
- }
645
- ctx.globalAlpha = 1
646
- 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) })
647
- return
648
  }
649
-
650
- camera(s, zoom, cx, cy)
651
- // stars
652
- ctx.fillStyle = 'rgba(255,230,230,0.6)'
653
- for (let i = 0; i < 80; i++) {
654
- const x = hash(i * 1.3) * W * 1.6 - W * 0.3
655
- const y = hash(i * 2.9) * H * 0.5
656
- const tw = 0.4 + 0.6 * Math.abs(Math.sin(t * (1 + hash(i)) + i))
657
- ctx.globalAlpha = tw * 0.6
658
- ctx.fillRect(x, y, u * 2, u * 2)
659
- }
660
- ctx.globalAlpha = 1
661
- // moon
662
- glowBlob(ctx, mx, my, R * 2.6, '#ff3a2e', 0.4 + a.kick * 0.15)
663
- const mg = ctx.createRadialGradient(mx - R * 0.3, my - R * 0.3, R * 0.1, mx, my, R)
664
- mg.addColorStop(0, '#ffd7a8')
665
- mg.addColorStop(0.45, '#ff7a4a')
666
- mg.addColorStop(1, '#b3122a')
667
- ctx.fillStyle = mg
668
- ctx.beginPath()
669
- ctx.arc(mx, my, R, 0, Math.PI * 2)
670
- ctx.fill()
671
- ctx.fillStyle = 'rgba(90,10,20,0.18)'
672
- for (let i = 0; i < 9; i++) {
673
- const ang = hash(i * 4.1) * Math.PI * 2
674
- const rr = R * Math.sqrt(hash(i * 2.2)) * 0.75
675
  ctx.beginPath()
676
- ctx.arc(mx + Math.cos(ang) * rr, my + Math.sin(ang) * rr, R * (0.05 + hash(i) * 0.12), 0, Math.PI * 2)
677
- ctx.fill()
 
 
 
 
 
 
 
 
678
  }
679
- ctx.fillStyle = 'rgba(12,3,6,0.75)'
680
- for (let i = 0; i < 6; i++) {
681
- const y = my - R * 0.7 + i * R * 0.32
682
- const x = fract(hash(i * 3.3) + lt * (0.01 + hash(i) * 0.015)) * (W + R * 4) - R * 2
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  ctx.beginPath()
684
- ctx.ellipse(x, y, R * (0.6 + hash(i * 5) * 0.6), R * 0.05, 0, 0, Math.PI * 2)
685
  ctx.fill()
 
 
 
 
 
 
686
  }
687
- // searchlights from the city below
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
688
  ctx.save()
689
- ctx.globalCompositeOperation = 'lighter'
690
- for (let i = 0; i < 3; i++) {
691
- const bx = W * (0.15 + i * 0.35)
692
- 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)
693
- lightCone(ctx, bx, ridgeY + H * 0.08, H * 1.4, 0.05, Math.PI + sw, PALETTE.bone, 0.09 + a.mid * 0.05)
694
- }
695
- ctx.restore()
696
- // far mountains + city in the valley
697
- ctx.fillStyle = '#16050a'
698
  ctx.beginPath()
699
- ctx.moveTo(-W, ridgeY)
700
- for (let i = 0; i <= 40; i++) {
701
- const x = -W * 0.5 + (i / 40) * W * 2
702
- ctx.lineTo(x, ridgeY - H * (0.12 + 0.1 * fbm(i * 0.35, 7)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
703
  }
704
- ctx.lineTo(W * 2, ridgeY)
705
- ctx.fill()
706
- 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) })
707
- fogBand(ctx, W * 1.6, ridgeY, H * 0.05, '#ff3a2e', 0.18)
708
- // the ridge road he stops on
709
- ctx.fillStyle = '#060204'
710
  ctx.beginPath()
711
- ctx.moveTo(-W, ridgeY + H * 0.02)
712
- ctx.quadraticCurveTo(W * 0.5, ridgeY - H * 0.03, W * 2, ridgeY + H * 0.01)
713
- ctx.lineTo(W * 2, H * 2)
714
- ctx.lineTo(-W, H * 2)
715
  ctx.fill()
716
- // guard rail
717
- ctx.strokeStyle = '#2a1a1e'
718
- ctx.lineWidth = u * 5
719
- ctx.beginPath()
720
- ctx.moveTo(-W, ridgeY - u * 30)
721
- ctx.lineTo(W * 2, ridgeY - u * 36)
722
- ctx.stroke()
723
- ctx.fillStyle = '#2a1a1e'
724
- for (let i = -6; i < 30; i++) ctx.fillRect(i * u * 90 + u * 20, ridgeY - u * 36, u * 6, u * 40)
725
- // 阿飞 sitting on the parked bike, looking at the moon
726
- const blink = fract(lt / 3.7) > 0.96 ? 'closed' : 'open'
727
- 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, tuck: 0, rim: rgba('#ff7a4a', 0.9) })
728
- resetCam(s)
729
- 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) })
730
- if (shotC && a.beatPhase < 0.08 && a.beat % 2 === 0) {
731
- ctx.fillStyle = 'rgba(255,200,190,0.18)'
732
- ctx.fillRect(0, 0, W, H)
 
 
 
 
 
 
 
733
  }
734
- void beatTime
 
 
 
 
735
  }
 
19
  wetReflection,
20
  } from './draw'
21
  import { camera, resetCam, type SceneCtx } from './types'
22
+ import { bike, flame, heroRide, heroRideRear, heroSideSit } from './hero'
23
  import {
24
  FONT,
25
  PALETTE,
 
39
  smoothstep,
40
  } from './util'
41
 
42
+ const SIGN_WORDS = ['网吧', '桌球', '电玩城', '机车改装', '烧烤', '大排档', '卡拉OK', '士多', '冰室', '纹身', '发廊', '录像厅', '溜冰场', '夜宵', '修车', '通宵']
43
  const SIGN_COLORS = [PALETTE.red, PALETTE.cyan, PALETTE.sodium, PALETTE.violet, PALETTE.teal, '#ff5fa2']
44
 
45
  const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
 
66
  const zoom = 1 + lt * 0.014
67
  camera(s, zoom, W / 2, H * 0.47)
68
 
69
+ const size = P ? Math.min(W * 0.4, H * 0.17) : Math.min(W * 0.25, H * 0.36)
70
+ const cy = P ? H * 0.31 : H * 0.36
71
  const pos: [number, number][] = P
72
  ? [
73
  [W / 2, cy - size * 0.55],
 
106
  const sub = 'BLACK STREET'
107
  const typed = Math.floor(clamp((lt - 4.2) / 1.4) * sub.length)
108
  if (typed > 0) {
109
+ const sy = P ? H * 0.075 : cy + size * 0.95
110
  const fs = P ? size * 0.26 : size * 0.22
111
  ctx.save()
112
  ctx.font = `${fs}px ${FONT.latin}`
 
123
  ctx.font = `${(P ? W : H) * 0.022}px ${FONT.black}`
124
  ctx.textAlign = 'center'
125
  ctx.fillStyle = PALETTE.bone
126
+ ctx.fillText('DJ鐘董 ·《黑街》DJ葱姜蒜进行曲', W / 2, P ? H * 0.115 : cy + size * 1.25)
127
  ctx.restore()
128
  }
129
+ // the singer's name in neon on the right wall
130
+ neonSign(ctx, W * (P ? 0.8 : 0.9), H * (P ? 0.5 : 0.07), u * (P ? 64 : 70), u * (P ? 200 : 220), '陈雅雯', PALETTE.cyan, lt > 3.8 ? (lt < 4.6 ? flicker(t, 4, 14) : 0.92 + 0.08 * flicker(t, 4, 3)) : 0, true)
131
+ // 阿飞 sitting side-saddle on his parked bike, watching the fire
132
+ const bs = P ? W * 0.34 : H * 0.28
 
 
133
  const headOn = lt > 6.4 ? (lt < 7 ? flicker(lt, 12, 18) : 1) : 0
134
+ const fireX = P ? W * 0.2 : W * 0.13
135
+ const fireS = P ? W * 0.1 : H * 0.1
136
+ heroSideSit(ctx, P ? W * 0.62 : W * 0.78, groundY, bs, { facing: -1, t, light: headOn, beam: headOn > 0.5, look: -0.6, rim: rgba('#ff9a4a', 0.75) })
137
+ bonfire(ctx, fireX, groundY + u * 6, fireS, t)
138
  // ground
139
  resetCam(s)
140
  ctx.fillStyle = '#050608'
 
193
  const k0 = Math.floor(midScroll / midCell) - 1
194
  for (let k = k0; k < k0 + Math.ceil((W + ext) / midCell) + 2; k++) {
195
  if (hash(k * 5.7) < 0.4) continue
196
+ const word = SIGN_WORDS[(((k * 5) % SIGN_WORDS.length) + SIGN_WORDS.length) % SIGN_WORDS.length]
197
+ const col = SIGN_COLORS[((k % SIGN_COLORS.length) + SIGN_COLORS.length) % SIGN_COLORS.length]
198
  const n = Array.from(word).length
199
  const sw = u * 50
200
  const sh = sw * n * 1.05 + sw * 0.4
 
203
  const on = hash(k * 4.4) > 0.8 ? flicker(t, k, 10) : 0.85 + 0.15 * a.mid
204
  neonSign(ctx, x, y, sw, sh, word, col, on, true)
205
  }
206
+ // near shopfronts — the places the street kids hang out
207
+ const nearCell = u * 300
208
  const kk0 = Math.floor(scroll / nearCell) - 1
209
  for (let k = kk0; k < kk0 + Math.ceil((W + ext) / nearCell) + 2; k++) {
210
  const x = k * nearCell - scroll
211
+ shopfront(ctx, x, groundY, nearCell, u, t, k)
212
+ if (((k % 3) + 3) % 3 === 0) streetLamp(ctx, x + nearCell * 0.02, groundY, u * 340, 0.85 + 0.15 * flicker(t, k + 99, 5))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  }
214
  // 阿飞 pushing his motorcycle through the rain
215
  const phase = (s.a.beatPos / 2) % 1
216
+ const bs = wh / 1.45
217
+ heroRide(ctx, wx, groundY + u * 2, bs, { facing: 1, t, spin: scroll / (bs * 0.23), light: 1, beam: true, wind: 0.45, eyes: 'open', tuck: 0.3, rim: rgba(PALETTE.cyan, 0.8) })
218
+ void phase
219
  // ground
220
  ctx.fillStyle = '#05070a'
221
  ctx.fillRect(-ext, groundY, W + ext * 3, H)
 
338
  const GRID_CHARS = ['黑', '街', '夜', '行', '王', '灯', '雨', '火', '醒', '狂', '燃', '跳', '闪', '冲', '霓', '虹']
339
 
340
  export function sDrop1(s: SceneCtx) {
341
+ const bi = Math.floor(s.lt / BEAT)
342
+ if (bi < 4) posterShot(s, 0)
343
+ else if (bi < 8) runnerShot(s, 0)
344
+ else gridShot(s, 0)
 
 
 
 
345
  }
346
 
347
  function posterShot(s: SceneCtx, variant: number) {
 
532
  void u
533
  }
534
 
535
+ /** campfire with logs, stones and two beer bottles (from the reference footage) */
536
+ function bonfire(ctx: CanvasRenderingContext2D, x: number, y: number, sz: number, t: number) {
537
+ ctx.save()
538
+ ctx.globalCompositeOperation = 'lighter'
539
+ glowBlob(ctx, x, y - sz * 0.6, sz * 9, '#ff7a2e', 0.32 + 0.06 * Math.sin(t * 9))
540
+ ctx.restore()
541
+ // stones
542
+ for (let i = 0; i < 9; i++) {
543
+ const a = Math.PI + (i / 8) * Math.PI
544
+ ctx.fillStyle = i % 2 ? '#2a2420' : '#3a312a'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
  ctx.beginPath()
546
+ ctx.ellipse(x + Math.cos(a) * sz * 0.9, y + Math.sin(a) * sz * 0.18 + sz * 0.1, sz * 0.2, sz * 0.13, 0, 0, Math.PI * 2)
547
  ctx.fill()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
  }
549
+ // crossed logs
550
+ ctx.lineCap = 'round'
551
+ for (const [a, c] of [
552
+ [0.35, '#4a2e1a'],
553
+ [-0.35, '#5a3820'],
554
+ [0.05, '#3a2414'],
555
+ ] as [number, string][]) {
556
+ ctx.strokeStyle = c
557
+ ctx.lineWidth = sz * 0.2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  ctx.beginPath()
559
+ ctx.moveTo(x - Math.cos(a) * sz * 0.8, y + Math.sin(a) * sz * 0.2)
560
+ ctx.lineTo(x + Math.cos(a) * sz * 0.8, y - Math.sin(a) * sz * 0.2 - sz * 0.05)
561
+ ctx.stroke()
562
+ }
563
+ // embers bed
564
+ glowBlob(ctx, x, y, sz * 0.9, '#ff4a1c', 0.9)
565
+ // flames
566
+ for (let i = 0; i < 5; i++) {
567
+ const fx = x + (i - 2) * sz * 0.22
568
+ flame(ctx, fx, y - sz * 0.05, sz * (0.55 + 0.35 * Math.abs(Math.sin(t * 3 + i * 1.7))) * (i === 2 ? 1.5 : 1), t + i * 0.37)
569
  }
570
+ // sparks rising
571
+ ctx.fillStyle = '#ffcf7a'
572
+ for (let i = 0; i < 24; i++) {
573
+ const life = fract(t * (0.35 + hash(i) * 0.4) + hash(i * 3.7))
574
+ ctx.globalAlpha = 1 - life
575
+ ctx.fillRect(x + Math.sin(i * 2.3 + t * 2) * sz * (0.3 + life), y - sz * (0.6 + life * 5), Math.max(1, sz * 0.04), Math.max(1, sz * 0.04))
576
+ }
577
+ ctx.globalAlpha = 1
578
+ // two beer bottles next to the fire
579
+ for (const [dx, tilt] of [
580
+ [1.35, 0.05],
581
+ [1.6, -0.12],
582
+ ] as [number, number][]) {
583
+ ctx.save()
584
+ ctx.translate(x + sz * dx, y + sz * 0.15)
585
+ ctx.rotate(tilt)
586
+ ctx.fillStyle = '#1f5a2a'
587
  ctx.beginPath()
588
+ ctx.roundRect(-sz * 0.09, -sz * 0.5, sz * 0.18, sz * 0.5, sz * 0.04)
589
  ctx.fill()
590
+ ctx.fillRect(-sz * 0.035, -sz * 0.72, sz * 0.07, sz * 0.24)
591
+ ctx.fillStyle = '#e8d8a8'
592
+ ctx.fillRect(-sz * 0.09, -sz * 0.36, sz * 0.18, sz * 0.12)
593
+ ctx.fillStyle = 'rgba(255,190,120,0.5)'
594
+ ctx.fillRect(sz * 0.03, -sz * 0.48, sz * 0.03, sz * 0.4)
595
+ ctx.restore()
596
  }
597
+ }
598
+
599
+ const SHOPS = ['网吧', '桌球', '电玩城', '机车改装', '烧烤', '卡拉OK', '士多', '冰室', '纹身', '发廊']
600
+ const SHOP_COL = [PALETTE.cyan, '#5aff8a', '#ff5fa2', PALETTE.sodium, PALETTE.red, PALETTE.violet, '#9fe8ff', PALETTE.amber, PALETTE.red, '#ff8ad8']
601
+
602
+ /** one street-level shop with its interior visible: the kids' hangouts */
603
+ function shopfront(ctx: CanvasRenderingContext2D, x: number, groundY: number, cell: number, u: number, t: number, k: number) {
604
+ const type = ((k % SHOPS.length) + SHOPS.length) % SHOPS.length
605
+ const top = groundY - u * 330
606
+ ctx.fillStyle = '#07090d'
607
+ ctx.fillRect(x, top, cell + 1, groundY - top)
608
+ // pilasters
609
+ ctx.fillStyle = '#0d1016'
610
+ ctx.fillRect(x, top, cell * 0.05, groundY - top)
611
+ ctx.fillRect(x + cell * 0.95, top, cell * 0.05, groundY - top)
612
+ const wx = x + cell * 0.08
613
+ const ww = cell * 0.84
614
+ const wt = groundY - u * 215
615
+ const wh = groundY - wt
616
  ctx.save()
 
 
 
 
 
 
 
 
 
617
  ctx.beginPath()
618
+ ctx.rect(wx, wt, ww, wh)
619
+ ctx.clip()
620
+ const X = (f: number) => wx + ww * f
621
+ const Y = (f: number) => wt + wh * f
622
+ const fl = (seed: number, rate = 6) => 0.7 + 0.3 * flicker(t, k * 13 + seed, rate)
623
+ switch (type) {
624
+ case 0: {
625
+ // 网吧: rows of glowing monitors
626
+ vGradient(ctx, wx, wt, ww, wh, [
627
+ [0, '#06121e'],
628
+ [1, '#0c2236'],
629
+ ])
630
+ for (let r = 0; r < 2; r++)
631
+ for (let c = 0; c < 5; c++) {
632
+ const mx = X(0.06 + c * 0.19)
633
+ const my = Y(0.32 + r * 0.3)
634
+ glowBlob(ctx, mx + ww * 0.07, my + wh * 0.06, ww * 0.12, '#3da8ff', 0.35)
635
+ ctx.fillStyle = c % 2 ? '#7fd0ff' : '#b8e6ff'
636
+ ctx.globalAlpha = fl(c + r * 5, 3)
637
+ ctx.fillRect(mx, my, ww * 0.14, wh * 0.11)
638
+ ctx.globalAlpha = 1
639
+ ctx.fillStyle = '#05080c'
640
+ ctx.fillRect(mx + ww * 0.02, my + wh * 0.13, ww * 0.1, wh * 0.14)
641
+ }
642
+ break
643
+ }
644
+ case 1: {
645
+ // 桌球: green table under a hanging lamp
646
+ vGradient(ctx, wx, wt, ww, wh, [
647
+ [0, '#06100a'],
648
+ [1, '#0c1e12'],
649
+ ])
650
+ lightCone(ctx, X(0.5), Y(0.2), wh * 0.7, 0.55, 0, '#d8ffb0', 0.25)
651
+ ctx.fillStyle = '#1a3a1a'
652
+ ctx.beginPath()
653
+ ctx.moveTo(X(0.42), Y(0.12))
654
+ ctx.lineTo(X(0.58), Y(0.12))
655
+ ctx.lineTo(X(0.62), Y(0.2))
656
+ ctx.lineTo(X(0.38), Y(0.2))
657
+ ctx.fill()
658
+ ctx.fillStyle = '#4a2a14'
659
+ ctx.fillRect(X(0.15), Y(0.62), ww * 0.7, wh * 0.12)
660
+ ctx.fillStyle = '#1f8a3a'
661
+ ctx.fillRect(X(0.17), Y(0.6), ww * 0.66, wh * 0.06)
662
+ ctx.fillStyle = '#e8e2d6'
663
+ ctx.beginPath()
664
+ ctx.arc(X(0.4), Y(0.6), wh * 0.02, 0, Math.PI * 2)
665
+ ctx.arc(X(0.55), Y(0.6), wh * 0.02, 0, Math.PI * 2)
666
+ ctx.fill()
667
+ ctx.fillStyle = '#c4142f'
668
+ ctx.beginPath()
669
+ ctx.arc(X(0.48), Y(0.6), wh * 0.02, 0, Math.PI * 2)
670
+ ctx.fill()
671
+ ctx.strokeStyle = '#c9a26a'
672
+ ctx.lineWidth = Math.max(1, u * 2)
673
+ ctx.beginPath()
674
+ for (let i = 0; i < 4; i++) {
675
+ ctx.moveTo(X(0.88 + i * 0.02), Y(0.25))
676
+ ctx.lineTo(X(0.88 + i * 0.02), Y(0.85))
677
+ }
678
+ ctx.stroke()
679
+ break
680
+ }
681
+ case 2: {
682
+ // 电玩城: arcade cabinets with flickering screens
683
+ vGradient(ctx, wx, wt, ww, wh, [
684
+ [0, '#14061e'],
685
+ [1, '#2a0a30'],
686
+ ])
687
+ const cols = ['#ff5fa2', '#3de0ff', '#ffe04a', '#8a5cff']
688
+ for (let c = 0; c < 4; c++) {
689
+ const cx0 = X(0.06 + c * 0.235)
690
+ ctx.fillStyle = '#0a0410'
691
+ ctx.fillRect(cx0, Y(0.2), ww * 0.18, wh * 0.8)
692
+ ctx.fillStyle = cols[c]
693
+ ctx.globalAlpha = fl(c, 9)
694
+ ctx.fillRect(cx0 + ww * 0.02, Y(0.24), ww * 0.14, wh * 0.06)
695
+ ctx.fillRect(cx0 + ww * 0.025, Y(0.36), ww * 0.13, wh * 0.18)
696
+ ctx.globalAlpha = 1
697
+ glowBlob(ctx, cx0 + ww * 0.09, Y(0.45), ww * 0.14, cols[c], 0.4)
698
+ ctx.fillStyle = '#ff2d55'
699
+ ctx.beginPath()
700
+ ctx.arc(cx0 + ww * 0.06, Y(0.62), wh * 0.02, 0, Math.PI * 2)
701
+ ctx.fill()
702
+ }
703
+ break
704
+ }
705
+ case 3: {
706
+ // 机车改装: open garage, a bike on the stand, tools on the pegboard
707
+ vGradient(ctx, wx, wt, ww, wh, [
708
+ [0, '#1a140c'],
709
+ [1, '#2a2014'],
710
+ ])
711
+ lightCone(ctx, X(0.5), Y(0.08), wh, 0.6, 0, '#ffe6b0', 0.22)
712
+ ctx.fillStyle = '#3a3226'
713
+ ctx.fillRect(X(0.05), Y(0.15), ww * 0.4, wh * 0.3)
714
+ ctx.fillStyle = '#9aa3ad'
715
+ for (let i = 0; i < 8; i++) ctx.fillRect(X(0.08 + (i % 4) * 0.09), Y(0.19 + Math.floor(i / 4) * 0.12), ww * 0.015, wh * 0.08)
716
+ ctx.fillStyle = '#0c0c0e'
717
+ for (let i = 0; i < 3; i++) {
718
+ ctx.beginPath()
719
+ ctx.ellipse(X(0.88), Y(0.94 - i * 0.1), ww * 0.08, wh * 0.05, 0, 0, Math.PI * 2)
720
+ ctx.fill()
721
+ }
722
+ bike(ctx, X(0.52), Y(0.98), ww * 0.42, { facing: 1, light: 0, parked: true })
723
+ // half-raised shutter
724
+ ctx.fillStyle = '#14171c'
725
+ ctx.fillRect(wx, wt, ww, wh * 0.08)
726
+ break
727
+ }
728
+ case 4: {
729
+ // 烧烤 / 大排档: glowing grill, smoke, plastic stools
730
+ vGradient(ctx, wx, wt, ww, wh, [
731
+ [0, '#1e0e06'],
732
+ [1, '#3a1a0a'],
733
+ ])
734
+ ctx.fillStyle = '#1a1a1c'
735
+ ctx.fillRect(X(0.1), Y(0.55), ww * 0.45, wh * 0.08)
736
+ glowBlob(ctx, X(0.32), Y(0.55), ww * 0.3, '#ff5a1c', 0.6 + 0.2 * Math.sin(t * 7 + k))
737
+ ctx.strokeStyle = '#c9a26a'
738
+ ctx.lineWidth = Math.max(1, u * 2)
739
+ ctx.beginPath()
740
+ for (let i = 0; i < 7; i++) {
741
+ ctx.moveTo(X(0.12 + i * 0.06), Y(0.52))
742
+ ctx.lineTo(X(0.16 + i * 0.06), Y(0.57))
743
+ }
744
+ ctx.stroke()
745
+ for (let i = 0; i < 8; i++) {
746
+ const life = fract(t * 0.4 + hash(i + k))
747
+ ctx.fillStyle = `rgba(220,210,200,${0.18 * (1 - life)})`
748
+ ctx.beginPath()
749
+ ctx.arc(X(0.2 + 0.25 * hash(i)), Y(0.5 - life * 0.5), wh * (0.05 + life * 0.1), 0, Math.PI * 2)
750
+ ctx.fill()
751
+ }
752
+ for (const [fx, c] of [
753
+ [0.65, '#c4142f'],
754
+ [0.8, '#2a6ac4'],
755
+ ] as [number, string][]) {
756
+ ctx.fillStyle = c
757
+ ctx.fillRect(X(fx), Y(0.8), ww * 0.08, wh * 0.04)
758
+ ctx.fillRect(X(fx + 0.01), Y(0.84), ww * 0.015, wh * 0.16)
759
+ ctx.fillRect(X(fx + 0.055), Y(0.84), ww * 0.015, wh * 0.16)
760
+ }
761
+ ctx.fillStyle = '#1f5a2a'
762
+ ctx.fillRect(X(0.72), Y(0.64), ww * 0.02, wh * 0.1)
763
+ ctx.fillRect(X(0.76), Y(0.66), ww * 0.02, wh * 0.08)
764
+ break
765
+ }
766
+ case 5: {
767
+ // 卡拉OK: disco ball and swirling spots
768
+ vGradient(ctx, wx, wt, ww, wh, [
769
+ [0, '#14062a'],
770
+ [1, '#2a0a40'],
771
+ ])
772
+ const bx = X(0.5)
773
+ const by = Y(0.22)
774
+ for (let i = 0; i < 18; i++) {
775
+ const a = t * 1.2 + i * 0.7
776
+ ctx.fillStyle = ['#ff5fa2', '#3de0ff', '#ffe04a'][i % 3]
777
+ ctx.globalAlpha = 0.6
778
+ ctx.beginPath()
779
+ ctx.arc(bx + Math.cos(a) * ww * (0.15 + 0.3 * hash(i)), by + wh * 0.3 + Math.sin(a * 1.3) * wh * 0.3, wh * 0.025, 0, Math.PI * 2)
780
+ ctx.fill()
781
+ }
782
+ ctx.globalAlpha = 1
783
+ ctx.fillStyle = '#b8c0c8'
784
+ ctx.beginPath()
785
+ ctx.arc(bx, by, wh * 0.08, 0, Math.PI * 2)
786
+ ctx.fill()
787
+ glowBlob(ctx, bx, by, wh * 0.2, '#ffffff', 0.5)
788
+ ctx.strokeStyle = '#555'
789
+ ctx.beginPath()
790
+ ctx.moveTo(bx, wt)
791
+ ctx.lineTo(bx, by - wh * 0.08)
792
+ ctx.stroke()
793
+ break
794
+ }
795
+ case 6: {
796
+ // 士多 / 便利店: bright shelves + fridge
797
+ vGradient(ctx, wx, wt, ww, wh, [
798
+ [0, '#dfe8ee'],
799
+ [1, '#aebdc8'],
800
+ ])
801
+ for (let r = 0; r < 4; r++)
802
+ for (let c = 0; c < 9; c++) {
803
+ ctx.fillStyle = ['#c4142f', '#2a6ac4', '#e8a01c', '#2a9a4a', '#8a3ac4'][(c + r * 2 + k) % 5]
804
+ ctx.fillRect(X(0.05 + c * 0.06), Y(0.2 + r * 0.18), ww * 0.045, wh * 0.1)
805
+ }
806
+ ctx.fillStyle = '#1a3a5a'
807
+ ctx.fillRect(X(0.66), Y(0.1), ww * 0.3, wh * 0.9)
808
+ glowBlob(ctx, X(0.8), Y(0.5), ww * 0.25, '#7fd8ff', 0.5)
809
+ ctx.fillStyle = '#9fdcff'
810
+ for (let i = 0; i < 12; i++) ctx.fillRect(X(0.68 + (i % 4) * 0.07), Y(0.2 + Math.floor(i / 4) * 0.25), ww * 0.03, wh * 0.14)
811
+ break
812
+ }
813
+ case 7: {
814
+ // 冰室: warm diner, booth + ceiling fan
815
+ vGradient(ctx, wx, wt, ww, wh, [
816
+ [0, '#3a2414'],
817
+ [1, '#5a361c'],
818
+ ])
819
+ ctx.fillStyle = '#7a1e1e'
820
+ ctx.fillRect(X(0.05), Y(0.55), ww * 0.25, wh * 0.45)
821
+ ctx.fillRect(X(0.7), Y(0.55), ww * 0.25, wh * 0.45)
822
+ ctx.fillStyle = '#e8d8b8'
823
+ ctx.fillRect(X(0.35), Y(0.62), ww * 0.3, wh * 0.04)
824
+ ctx.fillRect(X(0.48), Y(0.66), ww * 0.04, wh * 0.34)
825
+ ctx.save()
826
+ ctx.translate(X(0.5), Y(0.12))
827
+ ctx.scale(1, 0.25)
828
+ ctx.rotate(t * 6)
829
+ ctx.fillStyle = '#2a1a0e'
830
+ for (let i = 0; i < 3; i++) {
831
+ ctx.rotate((Math.PI * 2) / 3)
832
+ ctx.fillRect(0, -wh * 0.02, ww * 0.2, wh * 0.04)
833
+ }
834
+ ctx.restore()
835
+ ctx.fillStyle = '#f0e0b0'
836
+ ctx.fillRect(X(0.2), Y(0.22), ww * 0.6, wh * 0.12)
837
+ ctx.fillStyle = '#5a361c'
838
+ for (let i = 0; i < 4; i++) ctx.fillRect(X(0.24 + i * 0.14), Y(0.26), ww * 0.1, wh * 0.03)
839
+ break
840
+ }
841
+ case 8: {
842
+ // 纹身: dark red, flash art on the wall
843
+ vGradient(ctx, wx, wt, ww, wh, [
844
+ [0, '#1a0608'],
845
+ [1, '#2a0a0e'],
846
+ ])
847
+ for (let i = 0; i < 6; i++) {
848
+ ctx.fillStyle = '#e8e2d6'
849
+ ctx.fillRect(X(0.08 + (i % 3) * 0.14), Y(0.2 + Math.floor(i / 3) * 0.22), ww * 0.11, wh * 0.16)
850
+ ctx.fillStyle = ['#c4142f', '#1a1a1a', '#2a6ac4'][i % 3]
851
+ ctx.beginPath()
852
+ ctx.arc(X(0.135 + (i % 3) * 0.14), Y(0.28 + Math.floor(i / 3) * 0.22), wh * 0.04, 0, Math.PI * 2)
853
+ ctx.fill()
854
+ }
855
+ neonText(ctx, 'TATTOO', X(0.75), Y(0.3), wh * 0.12, PALETTE.red, fl(3, 4), { font: FONT.latin })
856
+ ctx.fillStyle = '#0a0a0c'
857
+ ctx.fillRect(X(0.62), Y(0.6), ww * 0.3, wh * 0.12)
858
+ ctx.fillRect(X(0.7), Y(0.72), ww * 0.04, wh * 0.28)
859
+ break
860
+ }
861
+ default: {
862
+ // 发廊: pink interior, mirror, barber chair
863
+ vGradient(ctx, wx, wt, ww, wh, [
864
+ [0, '#2a0a1e'],
865
+ [1, '#4a1430'],
866
+ ])
867
+ ctx.fillStyle = '#6a8a9a'
868
+ ctx.fillRect(X(0.25), Y(0.15), ww * 0.4, wh * 0.4)
869
+ ctx.fillStyle = 'rgba(255,255,255,0.25)'
870
+ ctx.fillRect(X(0.28), Y(0.17), ww * 0.06, wh * 0.36)
871
+ ctx.fillStyle = '#0a0a0c'
872
+ ctx.fillRect(X(0.33), Y(0.6), ww * 0.24, wh * 0.14)
873
+ ctx.fillRect(X(0.43), Y(0.74), ww * 0.04, wh * 0.26)
874
+ glowBlob(ctx, X(0.45), Y(0.35), ww * 0.35, '#ff8ad8', 0.3)
875
+ }
876
  }
877
+ ctx.restore()
878
+ // glass reflection + frame
879
+ ctx.fillStyle = 'rgba(255,255,255,0.05)'
 
 
 
880
  ctx.beginPath()
881
+ ctx.moveTo(wx + ww * 0.1, wt)
882
+ ctx.lineTo(wx + ww * 0.25, wt)
883
+ ctx.lineTo(wx + ww * 0.05, groundY)
884
+ ctx.lineTo(wx - ww * 0.1, groundY)
885
  ctx.fill()
886
+ ctx.strokeStyle = '#1a1d24'
887
+ ctx.lineWidth = Math.max(1, u * 4)
888
+ ctx.strokeRect(wx, wt, ww, wh)
889
+ glowBlob(ctx, wx + ww / 2, groundY, ww * 0.8, SHOP_COL[type], 0.22)
890
+ // barber pole outside the 发廊
891
+ if (type === 9) {
892
+ const px = x + cell * 0.93
893
+ ctx.fillStyle = '#f2f2f2'
894
+ ctx.fillRect(px - u * 9, groundY - u * 150, u * 18, u * 80)
895
+ ctx.save()
896
+ ctx.beginPath()
897
+ ctx.rect(px - u * 9, groundY - u * 150, u * 18, u * 80)
898
+ ctx.clip()
899
+ for (let i = -2; i < 8; i++) {
900
+ const yy = groundY - u * 150 + ((i * u * 20 + t * u * 40) % (u * 160)) - u * 20
901
+ ctx.fillStyle = i % 2 ? '#c4142f' : '#2a6ac4'
902
+ ctx.beginPath()
903
+ ctx.moveTo(px - u * 9, yy)
904
+ ctx.lineTo(px + u * 9, yy - u * 10)
905
+ ctx.lineTo(px + u * 9, yy - u * 4)
906
+ ctx.lineTo(px - u * 9, yy + u * 6)
907
+ ctx.fill()
908
+ }
909
+ ctx.restore()
910
  }
911
+ // shop sign
912
+ neonSign(ctx, x + cell * 0.1, top + u * 24, cell * 0.8, u * 64, SHOPS[type], SHOP_COL[type], hash(k * 9.1) > 0.85 ? flicker(t, k, 8) : 1, false)
913
+ // AC unit + drip
914
+ ctx.fillStyle = '#10131a'
915
+ ctx.fillRect(x + cell * 0.7, top - u * 40, u * 50, u * 36)
916
  }
src/mv/engine/scenesB.ts CHANGED
@@ -16,251 +16,11 @@ import {
16
  wetReflection,
17
  } from './draw'
18
  import { camera, resetCam, type SceneCtx } from './types'
19
- import { HERO_H, bike, 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)
23
 
24
- // =====================================================================
25
- // S6 — 葱姜蒜夜市 (72.95 – 92s) calm, warm, one-point perspective dolly
26
- // =====================================================================
27
- const STALL_SIGNS = ['葱', '姜', '蒜', '糖水', '烧烤', '牛杂', '鱼蛋', '粥', '夜宵', '凉茶']
28
-
29
- export function sMarket(s: SceneCtx) {
30
- const { ctx, W, H, P, lt, u, t } = s
31
- const hy = P ? H * 0.46 : H * 0.44
32
- const f = P ? W * 1.05 : W * 0.62
33
- const camZ = lt * 0.85
34
- const camX = Math.sin(lt * 0.22) * 0.3
35
- const camH = 1.65
36
- const proj = (X: number, Y: number, Z: number) => {
37
- const zr = Math.max(0.05, Z - camZ)
38
- const k = f / zr
39
- return { x: W / 2 + (X - camX) * k, y: hy - (Y - camH) * k, k, zr }
40
- }
41
- // sky slit + haze
42
- vGradient(ctx, 0, 0, W, H, [
43
- [0, '#05070b'],
44
- [0.42, '#1b1210'],
45
- [0.5, '#3a2112'],
46
- [1, '#0a0705'],
47
- ])
48
- glowBlob(ctx, W / 2, hy, Math.max(W, H) * 0.5, PALETTE.amber, 0.22)
49
- // ground
50
- vGradient(ctx, 0, hy, W, H - hy, [
51
- [0, '#1a120c'],
52
- [1, '#070504'],
53
- ])
54
- const D = 3
55
- const first = Math.floor(camZ / D)
56
- const reflections: { x: number; y: number; r: number; c: string; a: number }[] = []
57
- for (let n = 13; n >= 0; n--) {
58
- const i = first + n
59
- const Z = i * D
60
- if (Z + D < camZ + 0.4) continue
61
- const fogA = clamp(1.25 - (Z - camZ) / 36) * clamp((Z + D - camZ) / 1.2)
62
- ctx.globalAlpha = fogA
63
- for (const side of [-1, 1]) {
64
- const sid = i * 2 + (side > 0 ? 1 : 0)
65
- // building wall face above the stalls
66
- const a0 = proj(side * 4.6, 0, Z)
67
- const a1 = proj(side * 4.6, 0, Z + D)
68
- const b0 = proj(side * 4.6, 10, Z)
69
- const b1 = proj(side * 4.6, 10, Z + D)
70
- ctx.fillStyle = hash(sid) > 0.5 ? '#0d0b0b' : '#0a0c0f'
71
- ctx.beginPath()
72
- ctx.moveTo(a0.x, a0.y)
73
- ctx.lineTo(a1.x, a1.y)
74
- ctx.lineTo(b1.x, b1.y)
75
- ctx.lineTo(b0.x, b0.y)
76
- ctx.closePath()
77
- ctx.fill()
78
- // windows
79
- for (let w = 0; w < 3; w++) {
80
- if (hash2(sid, w) < 0.45) continue
81
- const wy = 4.8 + w * 1.7
82
- const p0 = proj(side * 4.6, wy, Z + 0.7)
83
- const p1 = proj(side * 4.6, wy + 0.9, Z + 1.6)
84
- ctx.fillStyle = hash2(sid, w + 9) > 0.7 ? '#3f8f95' : '#c9853d'
85
- ctx.fillRect(Math.min(p0.x, p1.x), Math.min(p0.y, p1.y), Math.abs(p1.x - p0.x), Math.abs(p1.y - p0.y))
86
- }
87
- // stall counter (side face toward the alley)
88
- const c0 = proj(side * 2.0, 0, Z + 0.3)
89
- const c1 = proj(side * 2.0, 0, Z + 2.7)
90
- const c2 = proj(side * 2.0, 1.05, Z + 2.7)
91
- const c3 = proj(side * 2.0, 1.05, Z + 0.3)
92
- ctx.fillStyle = '#1e140d'
93
- ctx.beginPath()
94
- ctx.moveTo(c0.x, c0.y)
95
- ctx.lineTo(c1.x, c1.y)
96
- ctx.lineTo(c2.x, c2.y)
97
- ctx.lineTo(c3.x, c3.y)
98
- ctx.closePath()
99
- ctx.fill()
100
- // lit back of stall
101
- const g0 = proj(side * 4.4, 1.05, Z + 0.3)
102
- const g1 = proj(side * 4.4, 2.3, Z + 2.7)
103
- ctx.fillStyle = '#6a3a17'
104
- ctx.beginPath()
105
- ctx.moveTo(c3.x, c3.y)
106
- ctx.lineTo(c2.x, c2.y)
107
- ctx.lineTo(g1.x, proj(side * 4.4, 1.05, Z + 2.7).y)
108
- ctx.lineTo(g0.x, g0.y)
109
- ctx.closePath()
110
- ctx.fill()
111
- // goods on counter
112
- const kind = ((i % 10) + 10) % 10
113
- for (let q = 0; q < 5; q++) {
114
- const gp = proj(side * 2.15, 1.12, Z + 0.6 + q * 0.45)
115
- const r = 0.13 * gp.k
116
- if (r < 0.6) continue
117
- if (kind === 0 || (kind > 2 && q % 3 === 0)) {
118
- // scallion bundle
119
- ctx.strokeStyle = q % 2 ? '#6fbf4a' : '#9ddf6a'
120
- ctx.lineWidth = Math.max(1, r * 0.25)
121
- ctx.beginPath()
122
- for (let l = -2; l <= 2; l++) {
123
- ctx.moveTo(gp.x + l * r * 0.2, gp.y)
124
- ctx.lineTo(gp.x + l * r * 0.5, gp.y - r * 2.4)
125
- }
126
- ctx.stroke()
127
- ctx.fillStyle = '#efe9dc'
128
- ctx.fillRect(gp.x - r * 0.5, gp.y - r * 0.5, r, r * 0.5)
129
- } else if (kind === 1) {
130
- ctx.fillStyle = '#d9a446'
131
- ctx.beginPath()
132
- ctx.ellipse(gp.x, gp.y - r * 0.4, r * 0.9, r * 0.45, 0.3, 0, Math.PI * 2)
133
- ctx.ellipse(gp.x + r * 0.5, gp.y - r * 0.8, r * 0.45, r * 0.3, -0.5, 0, Math.PI * 2)
134
- ctx.fill()
135
- } else {
136
- ctx.fillStyle = '#efe6d6'
137
- ctx.beginPath()
138
- ctx.arc(gp.x, gp.y - r * 0.6, r * 0.62, 0, Math.PI * 2)
139
- ctx.fill()
140
- ctx.fillStyle = '#c9b9a0'
141
- ctx.fillRect(gp.x - r * 0.08, gp.y - r * 1.4, r * 0.16, r * 0.4)
142
- }
143
- }
144
- // awning
145
- const w0 = proj(side * 1.5, 2.35, Z + 0.15)
146
- const w1 = proj(side * 1.5, 2.35, Z + 2.85)
147
- const w2 = proj(side * 4.5, 2.85, Z + 2.85)
148
- const w3 = proj(side * 4.5, 2.85, Z + 0.15)
149
- const red = hash(sid * 3.3) > 0.4
150
- ctx.fillStyle = red ? '#8c1720' : '#174a52'
151
- ctx.beginPath()
152
- ctx.moveTo(w0.x, w0.y)
153
- ctx.lineTo(w1.x, w1.y)
154
- ctx.lineTo(w2.x, w2.y)
155
- ctx.lineTo(w3.x, w3.y)
156
- ctx.closePath()
157
- ctx.fill()
158
- // awning edge with bulb string
159
- ctx.strokeStyle = '#ffcf8a'
160
- ctx.lineWidth = Math.max(1, 0.03 * w0.k)
161
- ctx.beginPath()
162
- ctx.moveTo(w0.x, w0.y)
163
- ctx.lineTo(w1.x, w1.y)
164
- ctx.stroke()
165
- // sign board
166
- const word = STALL_SIGNS[((i * 2 + (side > 0 ? 1 : 0)) % STALL_SIGNS.length + STALL_SIGNS.length) % STALL_SIGNS.length]
167
- const sp = proj(side * 1.75, 4.3, Z + 1.4)
168
- const sw = 0.55 * sp.k
169
- const sh = (0.5 + 0.55 * Array.from(word).length) * sp.k
170
- if (sw > 3) {
171
- const col = [PALETTE.sodium, PALETTE.red, '#ff5fa2', PALETTE.cyan][(i + (side > 0 ? 2 : 0)) % 4 < 0 ? 0 : (i + (side > 0 ? 2 : 0)) % 4]
172
- neonSign(ctx, sp.x - sw / 2, sp.y, sw, sh, word, col, 0.9 + 0.1 * Math.sin(t * 3 + sid), true)
173
- reflections.push({ x: sp.x, y: proj(side * 1.75, -4.8, Z + 1.4).y, r: sw * 0.9, c: col, a: 0.25 * fogA })
174
- }
175
- // lantern
176
- if ((i + (side > 0 ? 1 : 0)) % 2 === 0) {
177
- const lp = proj(side * 1.15, 3.25, Z + 1.5)
178
- const r = 0.24 * lp.k
179
- if (r > 1) {
180
- lantern(ctx, lp.x, lp.y, r, Math.sin(t * 1.3 + sid) * 0.12, 1)
181
- reflections.push({ x: lp.x, y: proj(side * 1.15, -3.25, Z + 1.5).y, r: r * 1.6, c: '#ff5a2e', a: 0.4 * fogA })
182
- }
183
- }
184
- // steam
185
- if (hash(sid * 7.7) > 0.45) {
186
- for (let q = 0; q < 6; q++) {
187
- const life = fract(t * 0.25 + q / 6 + hash(sid + q))
188
- const sp2 = proj(side * (2.8 + Math.sin(q + t) * 0.2), 1.2 + life * 2.4, Z + 1.4)
189
- const rr = (0.25 + life * 0.6) * sp2.k
190
- ctx.fillStyle = `rgba(255,236,220,${0.07 * (1 - life)})`
191
- ctx.beginPath()
192
- ctx.arc(sp2.x, sp2.y, rr, 0, Math.PI * 2)
193
- ctx.fill()
194
- }
195
- }
196
- // customer silhouettes
197
- if (hash(sid * 1.1) > 0.55) {
198
- const pp = proj(side * 1.55, 0, Z + 1.0 + hash(sid) * 1.2)
199
- figureBack(ctx, pp.x, pp.y, 1.7 * pp.k, Math.sin(t + sid), { color: '#0a0706' })
200
- }
201
- }
202
- // string lights across the alley
203
- const pts: { x: number; y: number; k: number }[] = []
204
- for (let q = 0; q <= 16; q++) {
205
- const xx = lerp(-4.5, 4.5, q / 16)
206
- const sag = 0.7 * (1 - Math.pow(xx / 4.5, 2))
207
- pts.push(proj(xx, 4.9 - sag, Z))
208
- }
209
- ctx.strokeStyle = '#1a120c'
210
- ctx.lineWidth = Math.max(1, 0.015 * pts[0].k)
211
- ctx.beginPath()
212
- pts.forEach((p, q) => (q ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y)))
213
- ctx.stroke()
214
- for (let q = 1; q < 16; q++) {
215
- const p = pts[q]
216
- const r = Math.max(1, 0.06 * p.k)
217
- const on = 0.75 + 0.25 * Math.sin(t * 4 + q * 1.7 + i)
218
- ctx.fillStyle = q % 3 === 0 ? '#ff9a6a' : '#ffe0a0'
219
- ctx.globalAlpha = fogA * on
220
- ctx.beginPath()
221
- ctx.arc(p.x, p.y, r, 0, Math.PI * 2)
222
- ctx.fill()
223
- }
224
- ctx.globalAlpha = 1
225
- }
226
- ctx.globalAlpha = 1
227
- // wet ground reflections of lights
228
- ctx.save()
229
- ctx.globalCompositeOperation = 'lighter'
230
- for (const r of reflections) {
231
- if (r.y < hy || r.y > H * 1.3) continue
232
- const g = ctx.createRadialGradient(r.x, r.y, 0, r.x, r.y, r.r * 2)
233
- g.addColorStop(0, rgba(r.c, r.a))
234
- g.addColorStop(1, rgba(r.c, 0))
235
- ctx.fillStyle = g
236
- ctx.save()
237
- ctx.translate(r.x, r.y)
238
- ctx.scale(0.45, 1.8)
239
- ctx.translate(-r.x, -r.y)
240
- ctx.fillRect(r.x - r.r * 2, r.y - r.r * 2, r.r * 4, r.r * 4)
241
- ctx.restore()
242
- }
243
- ctx.restore()
244
- // foreground walker crossing the frame
245
- if (lt > 8.5 && lt < 15.5) {
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'
253
- for (let i = 0; i < 40; i++) {
254
- const life = fract(t * (0.08 + hash(i) * 0.06) + hash(i * 3.3))
255
- const x = hash(i * 1.9) * W + Math.sin(t + i) * u * 20
256
- const y = H * (1 - life) * 0.9
257
- ctx.globalAlpha = (1 - life) * 0.6
258
- ctx.fillRect(x, y, u * 3, u * 3)
259
- }
260
- ctx.globalAlpha = 1
261
- void easeOutCubic
262
- }
263
-
264
  // =====================================================================
265
  // S7 — 暗场·心跳 (92 – 109.436s)
266
  // =====================================================================
@@ -336,19 +96,21 @@ export function sHeartbeat(s: SceneCtx) {
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
  const hh = fh * 1.3
342
- // parked bike behind him (side stand down), he sits on the ground in front of it
343
- bike(ctx, lx + hh * 0.32, floorY, hh / HERO_H, { facing: -1, light: 0, parked: true })
344
- const burn = smoothstep(9.6, 10.4, lt)
345
- const letter = 1 - smoothstep(10.2, 14.5, lt)
346
- heroSit(ctx, lx - hh * 0.22, floorY, hh, t, { facing: 1, letter, fire: burn * (letter > 0.02 ? 1 : smoothstep(15.5, 14.5, lt)) })
347
- if (burn > 0) {
348
- // warm firelight on the floor
 
349
  ctx.save()
350
  ctx.globalCompositeOperation = 'lighter'
351
- glowBlob(ctx, lx, floorY - fh * 0.4, fh * 1.6, '#ff7a2e', 0.25 * burn * (0.85 + 0.15 * Math.sin(t * 13)))
352
  ctx.restore()
353
  }
354
  if (lt > 5.0 && lt < 9.3) {
@@ -395,280 +157,6 @@ export function sHeartbeat(s: SceneCtx) {
395
  }
396
  }
397
 
398
- // =====================================================================
399
- // S8 — Drop2·飙车光轨 (109.436 – 127.64s)
400
- // =====================================================================
401
- const PUNCH = ['油门到底', '别回头', '冲', '黑街之王']
402
-
403
- export function sHighway(s: SceneCtx) {
404
- const shot = Math.floor(s.lt / (BAR * 2))
405
- if (shot === 2) sideShot(s)
406
- else chaseShot(s, shot)
407
- // punch word on the first beat of each 2-bar shot
408
- const inShot = s.lt - shot * BAR * 2
409
- if (inShot < BEAT * 0.9) {
410
- const { ctx, W, H, u, P } = s
411
- const k = inShot / (BEAT * 0.9)
412
- const word = PUNCH[Math.min(3, shot)]
413
- const size = Math.min((W * 0.82) / Array.from(word).length, P ? H * 0.2 : H * 0.42)
414
- ctx.save()
415
- ctx.globalAlpha = 1 - easeInOutCubic(k)
416
- splitText(ctx, word, W / 2, H * 0.45, size * (1 + k * 0.15), FONT.black, '#ffffff', u * 16)
417
- ctx.restore()
418
- }
419
- }
420
-
421
- function chaseShot(s: SceneCtx, shot: number) {
422
- const { ctx, W, H, P, lt, u, t, a } = s
423
- const hy = P ? H * 0.42 : H * 0.42
424
- const f = P ? W * 1.0 : W * 0.62
425
- const curve = Math.sin(lt * 0.55 + shot)
426
- const camX = curve * 0.8
427
- const camH = 1.25
428
- const camZ = lt * 34
429
- const lean = -curve * 0.1
430
- const proj = (X: number, Y: number, Z: number) => {
431
- const zr = Math.max(0.3, Z - camZ)
432
- const k = f / zr
433
- // road curvature: bend lateral position by depth
434
- const bend = curve * zr * zr * 0.0009
435
- return { x: W / 2 + (X - camX + bend) * k, y: hy - (Y - camH) * k, k, zr }
436
- }
437
- resetCam(s)
438
- vGradient(ctx, 0, 0, W, H, [
439
- [0, '#060818'],
440
- [0.3, '#1a2050'],
441
- [0.42, '#8a2a5a'],
442
- [0.46, '#16101a'],
443
- [1, '#0a0a10'],
444
- ])
445
- camera(s, 1 + a.kick * 0.02, W / 2, H / 2, lean)
446
- glowBlob(ctx, W / 2 + curve * W * 0.1, hy, Math.max(W, H) * 0.55, '#ff4a6a', 0.38)
447
- skyline(ctx, { W: W * 1.4, seed: 91, baseY: hy + u * 4, scroll: W * 0.2 + curve * u * 80, cell: u * 40, minH: H * 0.02, maxH: H * 0.14, color: '#06060c', t, density: 0.25, winAlpha: 0.7 })
448
- // road surface
449
- const r0 = proj(-8, 0, camZ + 1.5)
450
- const r1 = proj(8, 0, camZ + 1.5)
451
- ctx.fillStyle = '#07080b'
452
- ctx.beginPath()
453
- ctx.moveTo(r0.x, r0.y)
454
- for (let z = 2; z <= 400; z *= 1.25) ctx.lineTo(proj(-8, 0, camZ + z).x, proj(-8, 0, camZ + z).y)
455
- for (let z = 400; z >= 1.5; z /= 1.25) ctx.lineTo(proj(8, 0, camZ + z).x, proj(8, 0, camZ + z).y)
456
- ctx.lineTo(r1.x, r1.y)
457
- ctx.closePath()
458
- ctx.fill()
459
- // far → near objects
460
- const zStart = Math.floor(camZ / 20) * 20
461
- for (let Z = zStart + 300; Z >= zStart; Z -= 20) {
462
- const zr = Z - camZ
463
- if (zr < 0.5) continue
464
- const fogA = clamp(1.3 - zr / 280)
465
- ctx.globalAlpha = fogA
466
- const zi = Z / 20
467
- // buildings side faces
468
- for (const side of [-1, 1]) {
469
- const bh = 14 + 34 * hash(zi * 2 + side)
470
- const q0 = proj(side * 13, 0, Z)
471
- const q1 = proj(side * 13, 0, Z + 17)
472
- const q2 = proj(side * 13, bh, Z + 17)
473
- const q3 = proj(side * 13, bh, Z)
474
- ctx.fillStyle = '#05060a'
475
- ctx.beginPath()
476
- ctx.moveTo(q0.x, q0.y)
477
- ctx.lineTo(q1.x, q1.y)
478
- ctx.lineTo(q2.x, q2.y)
479
- ctx.lineTo(q3.x, q3.y)
480
- ctx.closePath()
481
- ctx.fill()
482
- ctx.strokeStyle = hash(zi + side * 3) > 0.5 ? PALETTE.cyan : PALETTE.sodium
483
- ctx.lineWidth = Math.max(1.5, 0.45 * q0.k)
484
- ctx.beginPath()
485
- for (let l = 1; l < 5; l++) {
486
- const yy = (bh * l) / 5
487
- if (hash2(zi + side, l) < 0.4) continue
488
- const p0 = proj(side * 13, yy, Z + 1)
489
- const p1 = proj(side * 13, yy, Z + 16)
490
- ctx.moveTo(p0.x, p0.y)
491
- ctx.lineTo(p1.x, p1.y)
492
- }
493
- ctx.stroke()
494
- // street lamps
495
- const lp = proj(side * 8.5, 0, Z)
496
- const lt2 = proj(side * 8.5, 7.5, Z)
497
- const lh = proj(side * 6.3, 7.5, Z)
498
- ctx.strokeStyle = '#0c0d12'
499
- ctx.lineWidth = Math.max(1, 0.18 * lp.k)
500
- ctx.beginPath()
501
- ctx.moveTo(lp.x, lp.y)
502
- ctx.lineTo(lt2.x, lt2.y)
503
- ctx.lineTo(lh.x, lh.y)
504
- ctx.stroke()
505
- glowBlob(ctx, lh.x, lh.y, Math.max(3, 2.2 * lh.k), PALETTE.sodium, 1)
506
- const pool = proj(side * 6.3, 0, Z)
507
- ctx.save()
508
- ctx.translate(pool.x, pool.y)
509
- ctx.scale(1, 0.3)
510
- glowBlob(ctx, 0, 0, Math.max(4, 6 * pool.k), PALETTE.sodium, 0.35)
511
- ctx.restore()
512
- }
513
- // lane dashes
514
- ctx.fillStyle = rgba(PALETTE.bone, 0.95)
515
- for (const X of [-2.6, 2.6]) {
516
- for (let d = 0; d < 2; d++) {
517
- const dz = Z + d * 10
518
- const d0 = proj(X - 0.14, 0, dz)
519
- const d1 = proj(X + 0.14, 0, dz)
520
- const d2 = proj(X + 0.14, 0, dz + 4)
521
- const d3 = proj(X - 0.14, 0, dz + 4)
522
- if (d0.zr < 0.5) continue
523
- ctx.beginPath()
524
- ctx.moveTo(d0.x, d0.y)
525
- ctx.lineTo(d1.x, d1.y)
526
- ctx.lineTo(d2.x, d2.y)
527
- ctx.lineTo(d3.x, d3.y)
528
- ctx.closePath()
529
- ctx.fill()
530
- }
531
- }
532
- }
533
- ctx.globalAlpha = 1
534
- // cars ahead (tail lights) and oncoming (headlights)
535
- ctx.save()
536
- ctx.globalCompositeOperation = 'lighter'
537
- for (let j = 0; j < 6; j++) {
538
- const X = j % 2 ? 1.3 : 4.0
539
- const zr = 16 + j * 22 + Math.sin(lt * 0.4 + j) * 6
540
- const c = proj(X, 0.8, camZ + zr)
541
- const sp = 0.7 * c.k
542
- glowBlob(ctx, c.x - sp, c.y, Math.max(3, 0.9 * c.k), PALETTE.red, 0.9)
543
- glowBlob(ctx, c.x + sp, c.y, Math.max(3, 0.9 * c.k), PALETTE.red, 0.9)
544
- // light trail streak on the road
545
- const g = ctx.createLinearGradient(0, c.y, 0, c.y + 3 * c.k)
546
- g.addColorStop(0, 'rgba(255,45,85,0.35)')
547
- g.addColorStop(1, 'rgba(255,45,85,0)')
548
- ctx.fillStyle = g
549
- ctx.fillRect(c.x - sp * 1.2, c.y, sp * 2.4, 3 * c.k)
550
- }
551
- for (let j = 0; j < 5; j++) {
552
- const zr = fract(-lt * 0.9 + hash(j * 2.7)) * 180 + 2
553
- const X = j % 2 ? -1.4 : -4.2
554
- const c = proj(X, 0.7, camZ + zr)
555
- const sp = 0.6 * c.k
556
- glowBlob(ctx, c.x - sp, c.y, Math.max(3, 1.3 * c.k), '#eaf4ff', 0.95)
557
- glowBlob(ctx, c.x + sp, c.y, Math.max(3, 1.3 * c.k), '#eaf4ff', 0.95)
558
- const c2 = proj(X, 0.7, camZ + zr + 14)
559
- ctx.strokeStyle = 'rgba(220,235,255,0.35)'
560
- ctx.lineWidth = Math.max(1, 0.25 * c.k)
561
- ctx.beginPath()
562
- ctx.moveTo(c.x - sp, c.y)
563
- ctx.lineTo(c2.x - sp * (c2.k / c.k), c2.y)
564
- ctx.moveTo(c.x + sp, c.y)
565
- ctx.lineTo(c2.x + sp * (c2.k / c.k), c2.y)
566
- ctx.stroke()
567
- }
568
- ctx.restore()
569
- resetCam(s)
570
- speedLines(ctx, W / 2, hy, Math.max(W, H) * 0.9, t, 100, '#ffffff', 0.05 + a.kick * 0.12, 0.3)
571
- // a big truck thundering along in the right lane (as in the reference)
572
- {
573
- const tz = 7 + 9 * (0.5 + 0.5 * Math.sin(lt * 0.35 + shot * 2))
574
- const TX0 = 2.9
575
- const TX1 = 6.2
576
- const TH = 4.3
577
- const back0 = proj(TX0, 0.6, camZ + tz)
578
- const back1 = proj(TX1, TH, camZ + tz)
579
- const side0 = proj(TX0, 0.6, camZ + tz + 14)
580
- const side1 = proj(TX0, TH, camZ + tz + 14)
581
- ctx.save()
582
- camera(s, 1 + a.kick * 0.02, W / 2, H / 2, lean)
583
- // side panel
584
- ctx.fillStyle = '#2a2d33'
585
- ctx.beginPath()
586
- ctx.moveTo(back0.x, back0.y)
587
- ctx.lineTo(side0.x, side0.y)
588
- ctx.lineTo(side1.x, side1.y)
589
- ctx.lineTo(back0.x, back1.y)
590
- ctx.closePath()
591
- ctx.fill()
592
- // rear doors
593
- ctx.fillStyle = '#5a5e66'
594
- ctx.fillRect(back0.x, back1.y, back1.x - back0.x, back0.y - back1.y)
595
- ctx.strokeStyle = '#2a2d33'
596
- ctx.lineWidth = Math.max(1, (back1.x - back0.x) * 0.02)
597
- ctx.strokeRect(back0.x, back1.y, back1.x - back0.x, back0.y - back1.y)
598
- ctx.beginPath()
599
- ctx.moveTo((back0.x + back1.x) / 2, back1.y)
600
- ctx.lineTo((back0.x + back1.x) / 2, back0.y)
601
- ctx.stroke()
602
- const tw = back1.x - back0.x
603
- glowBlob(ctx, back0.x + tw * 0.08, back0.y - tw * 0.05, tw * 0.12, PALETTE.red, 1)
604
- glowBlob(ctx, back1.x - tw * 0.08, back0.y - tw * 0.05, tw * 0.12, PALETTE.red, 1)
605
- // wheels
606
- ctx.fillStyle = '#050507'
607
- ctx.fillRect(back0.x + tw * 0.05, back0.y, tw * 0.25, tw * 0.12)
608
- ctx.fillRect(back1.x - tw * 0.3, back0.y, tw * 0.25, tw * 0.12)
609
- ctx.restore()
610
- }
611
- // 阿飞 (rear view) at bottom centre — curls flying in the wind
612
- const rs = P ? W * 0.5 : H * 0.55
613
- heroRideRear(ctx, W / 2, H * 1.0 + a.kick * u * 6, rs * 1.15, -curve * 0.14, t, 1)
614
- 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) })
615
- }
616
-
617
- function sideShot(s: SceneCtx) {
618
- const { ctx, W, H, P, lt, u, t, a } = s
619
- const gy = P ? H * 0.64 : H * 0.72
620
- vGradient(ctx, 0, 0, W, gy, [
621
- [0, '#0a0818'],
622
- [0.6, '#3a1440'],
623
- [1, '#a0305a'],
624
- ])
625
- glowBlob(ctx, W * 0.5, gy - H * 0.2, Math.max(W, H) * 0.5, '#ff6a8a', 0.3)
626
- skyline(ctx, { W, seed: 13, baseY: gy - H * 0.06, scroll: lt * u * 120, cell: u * 60, minH: H * 0.1, maxH: H * 0.4, color: '#0a0812', t, density: 0.2, winAlpha: 0.5 })
627
- // fast mid layer → motion blurred streak lights
628
- ctx.save()
629
- ctx.globalCompositeOperation = 'lighter'
630
- for (let i = 0; i < 110; i++) {
631
- const y = gy - H * (0.05 + 0.5 * hash(i * 1.7))
632
- const len = u * (120 + 380 * hash(i * 3.1))
633
- const x = fract(hash(i * 2.3) - lt * (1.4 + hash(i) * 1.2)) * (W + len * 2) - len
634
- const col = [PALETTE.sodium, PALETTE.cyan, PALETTE.red, '#ff5fa2'][i % 4]
635
- const g = ctx.createLinearGradient(x, 0, x + len, 0)
636
- g.addColorStop(0, rgba(col, 0))
637
- g.addColorStop(0.7, rgba(col, 0.5))
638
- g.addColorStop(1, rgba(col, 0.9))
639
- ctx.fillStyle = g
640
- ctx.fillRect(x, y, len, Math.max(1.5, u * (3 + 6 * hash(i * 5))))
641
- }
642
- ctx.restore()
643
- // road
644
- ctx.fillStyle = '#050507'
645
- ctx.fillRect(0, gy, W, H - gy)
646
- ctx.fillStyle = rgba(PALETTE.bone, 0.6)
647
- for (let i = 0; i < 8; i++) {
648
- const x = fract(i / 8 - lt * 3) * (W + u * 300) - u * 300
649
- ctx.fillRect(x, gy + (H - gy) * 0.45, u * 200, u * 6)
650
- }
651
- wetReflection(ctx, s.scratch, W, H, gy, t, 0.35, u * 2)
652
- // 阿飞 on his bike, side view, hair streaming back
653
- const bx = W * 0.5 + Math.sin(lt * 1.3) * u * 20
654
- const bs = P ? W * 0.5 : H * 0.4
655
- const by = gy + a.kick * u * 4
656
- const tg = ctx.createLinearGradient(bx - bs * 2.6, 0, bx - bs * 0.6, 0)
657
- tg.addColorStop(0, 'rgba(255,45,85,0)')
658
- tg.addColorStop(1, 'rgba(255,45,85,0.85)')
659
- ctx.fillStyle = tg
660
- ctx.fillRect(bx - bs * 2.6, by - bs * 0.46, bs * 2, Math.max(2, bs * 0.03))
661
- heroRide(ctx, bx, by, bs, { facing: 1, wind: 1, t, spin: lt * 40, beam: true, eyes: 'open', tuck: 1, rim: rgba(PALETTE.cyan, 0.85) })
662
- // horizontal speed lines
663
- ctx.fillStyle = 'rgba(255,255,255,0.18)'
664
- for (let i = 0; i < 30; i++) {
665
- const y = hash(i * 7.7) * H
666
- const x = fract(hash(i) - lt * 4) * W * 1.5 - W * 0.25
667
- ctx.fillRect(x, y, u * (200 + 300 * hash(i * 2)), Math.max(1, u * 1.5))
668
- }
669
- void fogBand
670
- }
671
-
672
  // =====================================================================
673
  // S9 — 终章·黑街之王 (127.64 – 144.3s)
674
  // =====================================================================
 
16
  wetReflection,
17
  } from './draw'
18
  import { camera, resetCam, type SceneCtx } from './types'
19
+ import { HERO_H, bike, heroPortrait, heroRide, heroSitPaper } 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)
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  // =====================================================================
25
  // S7 — 暗场·心跳 (92 – 109.436s)
26
  // =====================================================================
 
96
  ctx.clip()
97
  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) })
98
  ctx.restore()
99
+ // 阿飞 sits on the ground in front of his parked bike, reading the evening paper
100
+ // under the lamp … pulls out a lighter, sets the corner alight, lets it burn, drops it.
101
  const fh = P ? H * 0.2 : H * 0.3
102
  const hh = fh * 1.3
103
+ bike(ctx, lx + hh * 0.05, floorY - hh * 0.01, hh / HERO_H, { facing: -1, light: 0, parked: true })
104
+ const lighter = smoothstep(9.3, 10.5, lt)
105
+ const lit = lt > 10.25
106
+ const burn = lt < 10.6 ? 0 : lt < 13.8 ? lerp(0, 0.55, (lt - 10.6) / 3.2) : lt < 14.4 ? 0.55 : clamp(lerp(0.55, 1, (lt - 14.4) / 1.8), 0, 1)
107
+ const drop = smoothstep(13.8, 14.4, lt)
108
+ heroSitPaper(ctx, lx, floorY, hh, t, { lighter, lit, burn, drop })
109
+ if (burn > 0 && burn < 1) {
110
+ // warm firelight on him and the floor
111
  ctx.save()
112
  ctx.globalCompositeOperation = 'lighter'
113
+ glowBlob(ctx, lx, floorY - hh * (0.45 - drop * 0.4), hh * 1.2, '#ff7a2e', 0.35 * (0.85 + 0.15 * Math.sin(t * 13)))
114
  ctx.restore()
115
  }
116
  if (lt > 5.0 && lt < 9.3) {
 
157
  }
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  // =====================================================================
161
  // S9 — 终章·黑街之王 (127.64 – 144.3s)
162
  // =====================================================================
src/mv/engine/scenesCar.ts ADDED
@@ -0,0 +1,766 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Two highway duels (inspired by the second reference video):
2
+ // S5 「倒车闪灯」: the red car provokes → 阿飞 overtakes → handbrake 180° →
3
+ // drives in reverse and flashes his high beams at the rival → handbrake
4
+ // back → floors it and leaves.
5
+ // S8 「喷射飞越」: stuck behind the red car → JET switch → under-body jets
6
+ // lift the hatchback over the rival → jets cushion the landing →
7
+ // nozzles swivel backwards → boost away.
8
+ import { BAR, BEAT } from './audio'
9
+ import { carRear, carSide, carTop, heroCarFront } from './cars'
10
+ import { glowBlob, lightCone, skyline, speedLines, splitText, vGradient } from './draw'
11
+ import { HERO, HERO_H, armPiece, capsule, circle, heroHead, ik, ink, torso, withPalette, RIVAL } from './hero'
12
+ import { resetCam, type SceneCtx } from './types'
13
+ import { FONT, PALETTE, clamp, easeInOutCubic, easeOutCubic, fract, hash, lerp, rgba, smoothstep } from './util'
14
+
15
+ type C2D = CanvasRenderingContext2D
16
+ const ease = easeInOutCubic
17
+ const seg = (x: number, a: number, b: number) => ease(clamp((x - a) / (b - a)))
18
+
19
+ // =====================================================================
20
+ // shared: top-down highway
21
+ // =====================================================================
22
+ interface CarState {
23
+ x: number // lateral metres (+ = right)
24
+ z: number // forward metres
25
+ h: number // heading (0 forward, π = backwards)
26
+ brake?: number
27
+ high?: number
28
+ }
29
+
30
+ function drawTopRoad(s: SceneCtx, zc: number, k: number) {
31
+ const { ctx, W, H } = s
32
+ const span = Math.max(W, H) / k / 2 + 8
33
+ // ground beyond the road
34
+ ctx.fillStyle = '#07090c'
35
+ ctx.fillRect(-span * k, -span * k, span * 2 * k, span * 2 * k)
36
+ // asphalt
37
+ ctx.fillStyle = '#16181d'
38
+ ctx.fillRect(-7.2 * k, -span * k, 14.4 * k, span * 2 * k)
39
+ // asphalt grain
40
+ ctx.fillStyle = 'rgba(255,255,255,0.025)'
41
+ const z0 = Math.floor((zc - span) / 2) * 2
42
+ for (let z = z0; z < zc + span; z += 2) {
43
+ for (let i = 0; i < 6; i++) {
44
+ const xx = (hash(z * 3.1 + i) - 0.5) * 14
45
+ ctx.fillRect(xx * k, -(z + hash(z + i * 7) * 2 - zc) * k, k * 0.15, k * 0.15)
46
+ }
47
+ }
48
+ // edge lines
49
+ ctx.fillStyle = 'rgba(240,235,220,0.85)'
50
+ ctx.fillRect(-5.55 * k, -span * k, 0.15 * k, span * 2 * k)
51
+ ctx.fillRect(5.4 * k, -span * k, 0.15 * k, span * 2 * k)
52
+ // lane dashes
53
+ const d0 = Math.floor((zc - span) / 12) * 12
54
+ for (let z = d0; z < zc + span; z += 12) {
55
+ for (const lx of [-1.8, 1.8]) ctx.fillRect((lx - 0.075) * k, -(z + 6 - zc) * k, 0.15 * k, 6 * k)
56
+ }
57
+ // guard rails + lamp posts with light pools
58
+ ctx.fillStyle = '#3a3f48'
59
+ ctx.fillRect(-7.6 * k, -span * k, 0.25 * k, span * 2 * k)
60
+ ctx.fillRect(7.35 * k, -span * k, 0.25 * k, span * 2 * k)
61
+ const l0 = Math.floor((zc - span) / 30) * 30
62
+ for (let z = l0; z < zc + span; z += 30) {
63
+ for (const sd of [-1, 1]) {
64
+ const px = sd * 8.2 * k
65
+ const py = -(z - zc) * k
66
+ ctx.save()
67
+ ctx.globalCompositeOperation = 'lighter'
68
+ glowBlob(ctx, sd * 5 * k, py, 7 * k, PALETTE.sodium, 0.16)
69
+ ctx.restore()
70
+ ctx.fillStyle = '#2a2d33'
71
+ ctx.fillRect(px - 0.2 * k, py - 0.2 * k, 0.4 * k, 0.4 * k)
72
+ ctx.fillRect(sd > 0 ? px - 3 * k : px, py - 0.08 * k, 3 * k, 0.16 * k)
73
+ glowBlob(ctx, sd * 5.4 * k, py, 0.9 * k, '#fff0c8', 0.9)
74
+ }
75
+ }
76
+ }
77
+
78
+ function carCorners(c: CarState, back = 1.3, half = 0.75) {
79
+ const fx = Math.sin(c.h)
80
+ const fz = Math.cos(c.h)
81
+ const lx = Math.cos(c.h)
82
+ const lz = -Math.sin(c.h)
83
+ return [-1, 1].map((sd) => ({ x: c.x - fx * back + lx * half * sd, z: c.z - fz * back + lz * half * sd }))
84
+ }
85
+
86
+ /** smoke + skid marks for spins, sampled from the (deterministic) car history */
87
+ function spinFx(ctx: C2D, hist: (tau: number) => CarState, tau: number, a: number, b: number, zc: number, k: number) {
88
+ if (tau < a) return
89
+ // skid marks
90
+ ctx.strokeStyle = 'rgba(5,5,6,0.75)'
91
+ ctx.lineWidth = Math.max(1, k * 0.22)
92
+ ctx.lineCap = 'round'
93
+ for (const w of [0, 1]) {
94
+ ctx.beginPath()
95
+ let first = true
96
+ for (let tt = a; tt <= Math.min(tau, b); tt += 0.03) {
97
+ const p = carCorners(hist(tt))[w]
98
+ const X = p.x * k
99
+ const Y = -(p.z - zc) * k
100
+ if (first) ctx.moveTo(X, Y)
101
+ else ctx.lineTo(X, Y)
102
+ first = false
103
+ }
104
+ ctx.stroke()
105
+ }
106
+ // tyre smoke
107
+ for (let tt = a; tt <= Math.min(tau, b + 0.2); tt += 0.045) {
108
+ const age = tau - tt
109
+ if (age > 2.6) continue
110
+ const ps = carCorners(hist(tt))
111
+ for (let w = 0; w < 2; w++) {
112
+ const p = ps[w]
113
+ const jx = (hash(tt * 31 + w) - 0.5) * 1.2
114
+ const jz = (hash(tt * 17 + w * 3) - 0.5) * 1.2 + age * 2.5
115
+ const r = (0.5 + age * 1.6) * k
116
+ ctx.fillStyle = `rgba(205,210,220,${0.32 * (1 - age / 2.6)})`
117
+ ctx.beginPath()
118
+ ctx.arc((p.x + jx) * k, -(p.z + jz - zc) * k, r, 0, Math.PI * 2)
119
+ ctx.fill()
120
+ }
121
+ }
122
+ }
123
+
124
+ // =====================================================================
125
+ // shared: interior / POV
126
+ // =====================================================================
127
+ function povRoad(s: SceneCtx, speed: number, tint: string) {
128
+ const { ctx, W, H, t, P } = s
129
+ const hy = H * (P ? 0.42 : 0.44)
130
+ vGradient(ctx, 0, 0, W, hy, [
131
+ [0, '#05060e'],
132
+ [0.7, '#141a36'],
133
+ [1, tint],
134
+ ])
135
+ glowBlob(ctx, W / 2, hy, Math.max(W, H) * 0.5, '#ff4a6a', 0.18)
136
+ skyline(ctx, { W, seed: 31, baseY: hy + 2, scroll: t * 8, cell: Math.min(W, H) * 0.04, minH: H * 0.02, maxH: H * 0.12, color: '#06060c', t, density: 0.25, winAlpha: 0.7 })
137
+ ctx.fillStyle = '#101216'
138
+ ctx.beginPath()
139
+ ctx.moveTo(W / 2 - W * 0.02, hy)
140
+ ctx.lineTo(W / 2 + W * 0.02, hy)
141
+ ctx.lineTo(W * 1.6, H)
142
+ ctx.lineTo(-W * 0.6, H)
143
+ ctx.closePath()
144
+ ctx.fill()
145
+ const f = P ? W * 1.3 : W * 0.9
146
+ // lane dashes + lamps rushing toward the camera
147
+ const zOff = (t * speed) % 12
148
+ ctx.fillStyle = 'rgba(235,230,215,0.85)'
149
+ for (let i = 0; i < 14; i++) {
150
+ const z = 3 + i * 12 - zOff
151
+ const z2 = z + 5
152
+ for (const lx of [-1.8, 1.8]) {
153
+ const x1 = W / 2 + (lx * f) / z
154
+ const x2 = W / 2 + (lx * f) / z2
155
+ const y1 = hy + (1.2 * f) / z
156
+ const y2 = hy + (1.2 * f) / z2
157
+ const w1 = (0.15 * f) / z
158
+ const w2 = (0.15 * f) / z2
159
+ ctx.beginPath()
160
+ ctx.moveTo(x1 - w1, y1)
161
+ ctx.lineTo(x1 + w1, y1)
162
+ ctx.lineTo(x2 + w2, y2)
163
+ ctx.lineTo(x2 - w2, y2)
164
+ ctx.fill()
165
+ }
166
+ }
167
+ const lOff = (t * speed) % 30
168
+ for (let i = 0; i < 8; i++) {
169
+ const z = 2 + i * 30 - lOff
170
+ if (z < 1) continue
171
+ for (const sd of [-1, 1]) {
172
+ const x = W / 2 + (sd * 8 * f) / z
173
+ const yTop = hy - (6 * f) / z
174
+ const yBot = hy + (1.2 * f) / z
175
+ ctx.strokeStyle = '#1c1f26'
176
+ ctx.lineWidth = Math.max(1, (0.25 * f) / z)
177
+ ctx.beginPath()
178
+ ctx.moveTo(x, yBot)
179
+ ctx.lineTo(x, yTop)
180
+ ctx.lineTo(x - (sd * 2.5 * f) / z, yTop)
181
+ ctx.stroke()
182
+ glowBlob(ctx, x - (sd * 2.5 * f) / z, yTop, Math.max(3, (2.2 * f) / z), PALETTE.sodium, 0.9)
183
+ }
184
+ }
185
+ return { hy, f }
186
+ }
187
+
188
+ function windshield(s: SceneCtx, rival: boolean) {
189
+ const { ctx, W, H, t, P } = s
190
+ // light sweeping across the glass
191
+ const sweep = fract(t * 1.1)
192
+ ctx.save()
193
+ ctx.globalCompositeOperation = 'lighter'
194
+ const g = ctx.createLinearGradient(W * (sweep * 1.6 - 0.3), 0, W * (sweep * 1.6 - 0.1), H)
195
+ g.addColorStop(0, 'rgba(255,200,140,0)')
196
+ g.addColorStop(0.5, 'rgba(255,200,140,0.07)')
197
+ g.addColorStop(1, 'rgba(255,200,140,0)')
198
+ ctx.fillStyle = g
199
+ ctx.fillRect(0, 0, W, H)
200
+ ctx.restore()
201
+ // A-pillars + roof header
202
+ ctx.fillStyle = '#050608'
203
+ ctx.beginPath()
204
+ ctx.moveTo(0, 0)
205
+ ctx.lineTo(W * 0.1, 0)
206
+ ctx.lineTo(0, H * 0.75)
207
+ ctx.closePath()
208
+ ctx.fill()
209
+ ctx.beginPath()
210
+ ctx.moveTo(W, 0)
211
+ ctx.lineTo(W * 0.9, 0)
212
+ ctx.lineTo(W, H * 0.75)
213
+ ctx.closePath()
214
+ ctx.fill()
215
+ ctx.fillRect(0, 0, W, H * 0.05)
216
+ // mirror
217
+ ctx.beginPath()
218
+ ctx.roundRect(W * 0.42, H * 0.05, W * 0.16, H * 0.06, H * 0.015)
219
+ ink(ctx, '#15171c', Math.max(1, H * 0.003))
220
+ ctx.fillStyle = '#2a3546'
221
+ ctx.fillRect(W * 0.43, H * 0.06, W * 0.14, H * 0.04)
222
+ if (rival) {
223
+ // a dangling skull charm — the rival's taste
224
+ const sw = Math.sin(t * 3) * 0.3
225
+ const mx = W * 0.5 + Math.sin(sw) * H * 0.08
226
+ const my = H * 0.11 + Math.cos(sw) * H * 0.08
227
+ ctx.strokeStyle = '#555'
228
+ ctx.lineWidth = 1
229
+ ctx.beginPath()
230
+ ctx.moveTo(W * 0.5, H * 0.11)
231
+ ctx.lineTo(mx, my)
232
+ ctx.stroke()
233
+ circle(ctx, { x: mx, y: my + H * 0.015 }, H * 0.018, '#e8e2d6', 1)
234
+ }
235
+ // dashboard
236
+ const dy = H * (P ? 0.8 : 0.78)
237
+ ctx.fillStyle = rival ? '#140608' : '#07080b'
238
+ ctx.beginPath()
239
+ ctx.moveTo(0, dy + H * 0.03)
240
+ ctx.quadraticCurveTo(W / 2, dy - H * 0.04, W, dy + H * 0.03)
241
+ ctx.lineTo(W, H)
242
+ ctx.lineTo(0, H)
243
+ ctx.closePath()
244
+ ctx.fill()
245
+ // gauges glow
246
+ for (let i = 0; i < 2; i++) {
247
+ const gx = W * (0.27 + i * 0.09)
248
+ const gy = dy + H * 0.07
249
+ glowBlob(ctx, gx, gy, H * 0.05, rival ? '#ff3a3a' : '#3de0ff', 0.6)
250
+ ctx.strokeStyle = rival ? '#ff6a6a' : '#7feaff'
251
+ ctx.lineWidth = Math.max(1, H * 0.003)
252
+ ctx.beginPath()
253
+ ctx.arc(gx, gy, H * 0.03, Math.PI * 0.8, Math.PI * 2.2)
254
+ ctx.stroke()
255
+ const a = Math.PI * 0.9 + (0.6 + 0.3 * Math.sin(t * 2 + i)) * Math.PI * 1.2
256
+ ctx.beginPath()
257
+ ctx.moveTo(gx, gy)
258
+ ctx.lineTo(gx + Math.cos(a) * H * 0.028, gy + Math.sin(a) * H * 0.028)
259
+ ctx.stroke()
260
+ }
261
+ // steering wheel + hands
262
+ const wx = W * (P ? 0.36 : 0.31)
263
+ const wy = H * 1.02
264
+ const wr = Math.min(W * (P ? 0.36 : 0.2), H * 0.3)
265
+ const turn = Math.sin(t * 0.9) * 0.08
266
+ ctx.save()
267
+ ctx.translate(wx, wy)
268
+ ctx.rotate(turn)
269
+ ctx.strokeStyle = '#0b0c0f'
270
+ ctx.lineWidth = wr * 0.13
271
+ ctx.beginPath()
272
+ ctx.arc(0, 0, wr, Math.PI, Math.PI * 2)
273
+ ctx.stroke()
274
+ ctx.strokeStyle = '#2a2d34'
275
+ ctx.lineWidth = wr * 0.03
276
+ ctx.beginPath()
277
+ ctx.arc(0, 0, wr * 1.04, Math.PI * 1.1, Math.PI * 1.4)
278
+ ctx.stroke()
279
+ ctx.restore()
280
+ const sleeve = rival ? '#15161a' : HERO.sweater
281
+ const lw = Math.max(1, H * 0.003)
282
+ for (const sd of [-1, 1]) {
283
+ const a = turn + Math.PI * (sd < 0 ? 1.18 : 1.82)
284
+ const hand = { x: wx + Math.cos(a) * wr, y: wy + Math.sin(a) * wr }
285
+ const base = { x: wx + sd * wr * 0.9, y: H * 1.15 }
286
+ capsule(ctx, base, hand, wr * 0.13, wr * 0.11, sleeve, lw)
287
+ circle(ctx, hand, wr * 0.1, rival ? '#c99a74' : HERO.skin, lw)
288
+ }
289
+ }
290
+
291
+ /** hero's car interior, side-on: 阿飞 driving, looking ahead. glare = rival's high beams from behind */
292
+ function driverProfile(s: SceneCtx, glare: number, look: number) {
293
+ const { ctx, W, H, t, P, u } = s
294
+ // outside the window: the night rushing past
295
+ vGradient(ctx, 0, 0, W, H, [
296
+ [0, '#060812'],
297
+ [0.6, '#1a1530'],
298
+ [1, '#0a0a10'],
299
+ ])
300
+ ctx.save()
301
+ ctx.globalCompositeOperation = 'lighter'
302
+ for (let i = 0; i < 40; i++) {
303
+ const y = H * (0.15 + 0.5 * hash(i * 1.7))
304
+ const len = W * (0.1 + 0.3 * hash(i * 3.1))
305
+ const x = W - fract(hash(i * 2.3) + t * (1.2 + hash(i))) * (W + len * 2) + len
306
+ ctx.fillStyle = rgba([PALETTE.sodium, PALETTE.cyan, '#ff5fa2'][i % 3], 0.35)
307
+ ctx.fillRect(x, y, len, Math.max(1, u * (2 + 3 * hash(i * 5))))
308
+ }
309
+ ctx.restore()
310
+ // rival's high beams flooding in from behind
311
+ if (glare > 0.01) {
312
+ ctx.save()
313
+ ctx.globalCompositeOperation = 'lighter'
314
+ glowBlob(ctx, -W * 0.05, H * 0.45, Math.max(W, H) * 0.7, '#ffffff', 0.55 * glare)
315
+ ctx.restore()
316
+ }
317
+ // car interior frame: door, window opening
318
+ ctx.fillStyle = '#0a0b0f'
319
+ ctx.beginPath()
320
+ ctx.rect(0, 0, W, H)
321
+ ctx.moveTo(W * 0.04, H * 0.14)
322
+ ctx.lineTo(W * 0.04, H * (P ? 0.66 : 0.62))
323
+ ctx.lineTo(W * 0.96, H * (P ? 0.66 : 0.62))
324
+ ctx.lineTo(W * 0.96, H * 0.3)
325
+ ctx.quadraticCurveTo(W * 0.8, H * 0.12, W * 0.6, H * 0.1)
326
+ ctx.lineTo(W * 0.1, H * 0.1)
327
+ ctx.closePath()
328
+ ctx.fill('evenodd')
329
+ // seat
330
+ const h = P ? H * 0.75 : H * 1.25
331
+ const hip = { x: W * (P ? 0.36 : 0.4), y: H * (P ? 0.92 : 1.02) }
332
+ ctx.beginPath()
333
+ ctx.roundRect(hip.x - h * 0.2, hip.y - h * 0.48, h * 0.13, h * 0.5, h * 0.04)
334
+ ink(ctx, '#18161a', Math.max(1, h * 0.004))
335
+ // body
336
+ const lean = -0.18
337
+ const sh = { x: hip.x + Math.sin(lean) * h * 0.25, y: hip.y - Math.cos(lean) * h * 0.25 }
338
+ const wheel = { x: hip.x + h * 0.3, y: hip.y - h * 0.24 }
339
+ const lw = Math.max(1, h * 0.006)
340
+ const far = ik(sh, { x: wheel.x + h * 0.01, y: wheel.y - h * 0.06 }, h * 0.15, h * 0.14, 1)
341
+ armPiece(ctx, sh, far.j, far.e, h, false, lw)
342
+ torso(ctx, hip, sh, h, 1, lw)
343
+ // seat belt
344
+ ctx.strokeStyle = '#2a2a2e'
345
+ ctx.lineWidth = h * 0.018
346
+ ctx.beginPath()
347
+ ctx.moveTo(sh.x - h * 0.05, sh.y - h * 0.01)
348
+ ctx.lineTo(hip.x + h * 0.06, hip.y - h * 0.04)
349
+ ctx.stroke()
350
+ capsule(ctx, sh, { x: sh.x + h * 0.02, y: sh.y - h * 0.06 }, h * 0.034, h * 0.032, HERO.skinShade, lw)
351
+ heroHead(ctx, sh.x + h * 0.04, sh.y - h * 0.035 - h * 0.14 * 0.95, h * 0.14, 1, { t, eyes: 'open', wind: 0.05, tilt: look * -0.12, rim: glare > 0.1 ? rgba('#ffffff', 0.8 * glare) : rgba(PALETTE.cyan, 0.5) })
352
+ // steering wheel (edge-on) + near arm
353
+ ctx.save()
354
+ ctx.translate(wheel.x, wheel.y)
355
+ ctx.rotate(-0.35)
356
+ ctx.beginPath()
357
+ ctx.ellipse(0, 0, h * 0.035, h * 0.14, 0, 0, Math.PI * 2)
358
+ ctx.strokeStyle = '#08090c'
359
+ ctx.lineWidth = h * 0.025
360
+ ctx.stroke()
361
+ ctx.restore()
362
+ const near = ik(sh, { x: wheel.x - h * 0.01, y: wheel.y + h * 0.02 }, h * 0.15, h * 0.14, 1)
363
+ armPiece(ctx, sh, near.j, near.e, h, true, lw)
364
+ // dashboard edge
365
+ ctx.fillStyle = '#060709'
366
+ ctx.fillRect(wheel.x + h * 0.02, H * (P ? 0.66 : 0.62), W, H)
367
+ glowBlob(ctx, wheel.x + h * 0.08, wheel.y + h * 0.02, h * 0.06, PALETTE.cyan, 0.5)
368
+ }
369
+
370
+ function handbrakeCU(s: SceneCtx, pull: number) {
371
+ const { ctx, W, H, t } = s
372
+ vGradient(ctx, 0, 0, W, H, [
373
+ [0, '#0c0d12'],
374
+ [1, '#030304'],
375
+ ])
376
+ const m = Math.min(W, H)
377
+ // console + seat edges
378
+ ctx.fillStyle = '#16171c'
379
+ ctx.beginPath()
380
+ ctx.roundRect(W / 2 - m * 0.3, H * 0.1, m * 0.6, H * 1.0, m * 0.06)
381
+ ctx.fill()
382
+ ctx.fillStyle = '#0c0d10'
383
+ ctx.fillRect(0, 0, W / 2 - m * 0.34, H)
384
+ ctx.fillRect(W / 2 + m * 0.34, 0, W, H)
385
+ // boot + lever
386
+ const pv = { x: W / 2 + m * 0.12, y: H * 0.86 }
387
+ ctx.beginPath()
388
+ ctx.ellipse(pv.x, pv.y, m * 0.12, m * 0.05, 0, 0, Math.PI * 2)
389
+ ink(ctx, '#0a0a0d', 2)
390
+ const ang = -Math.PI / 2 - 0.55 + pull * 0.75
391
+ const len = m * 0.6
392
+ const tip = { x: pv.x + Math.cos(ang) * len, y: pv.y + Math.sin(ang) * len }
393
+ capsule(ctx, pv, tip, m * 0.045, m * 0.05, '#1f2127', 2)
394
+ ctx.strokeStyle = 'rgba(255,255,255,0.12)'
395
+ ctx.lineWidth = m * 0.01
396
+ ctx.beginPath()
397
+ ctx.moveTo(pv.x + m * 0.02, pv.y - m * 0.05)
398
+ ctx.lineTo(tip.x + m * 0.02, tip.y + m * 0.04)
399
+ ctx.stroke()
400
+ circle(ctx, tip, m * 0.03, '#9aa3ad', 2)
401
+ // hand gripping (fist) + sleeve
402
+ const grip = { x: pv.x + Math.cos(ang) * len * 0.72, y: pv.y + Math.sin(ang) * len * 0.72 }
403
+ capsule(ctx, { x: W * 1.05, y: H * 0.35 + pull * H * 0.12 }, grip, m * 0.1, m * 0.085, HERO.sweater, 2)
404
+ capsule(ctx, { x: grip.x + m * 0.12, y: grip.y + m * 0.02 }, { x: grip.x + m * 0.06, y: grip.y + m * 0.01 }, m * 0.09, m * 0.09, HERO.rib, 2)
405
+ ctx.beginPath()
406
+ ctx.roundRect(grip.x - m * 0.07, grip.y - m * 0.08, m * 0.14, m * 0.16, m * 0.05)
407
+ ink(ctx, HERO.skin, 2)
408
+ ctx.strokeStyle = HERO.skinShade
409
+ ctx.lineWidth = m * 0.008
410
+ ctx.beginPath()
411
+ for (let k = 0; k < 3; k++) {
412
+ ctx.moveTo(grip.x - m * 0.07, grip.y - m * 0.04 + k * m * 0.04)
413
+ ctx.lineTo(grip.x - m * 0.01, grip.y - m * 0.04 + k * m * 0.04)
414
+ }
415
+ ctx.stroke()
416
+ // brake warning lamp
417
+ glowBlob(ctx, W / 2 - m * 0.2, H * 0.2, m * 0.08, '#ff2d55', 0.3 + 0.7 * pull)
418
+ ctx.save()
419
+ ctx.font = `${m * 0.05}px ${FONT.latin}`
420
+ ctx.fillStyle = pull > 0.5 ? '#ff6a80' : '#552028'
421
+ ctx.textAlign = 'center'
422
+ ctx.fillText('(!) BRAKE', W / 2 - m * 0.2, H * 0.215)
423
+ ctx.restore()
424
+ if (pull > 0.4) speedLines(ctx, grip.x, grip.y, m * 0.9, t, 60, '#ffffff', 0.12 * pull, 0.5)
425
+ }
426
+
427
+ function jetSwitchCU(s: SceneCtx, cover: number, press: number) {
428
+ const { ctx, W, H, t } = s
429
+ const m = Math.min(W, H)
430
+ vGradient(ctx, 0, 0, W, H, [
431
+ [0, '#0a0c12'],
432
+ [1, '#020203'],
433
+ ])
434
+ const on = smoothstep(0.5, 1, press)
435
+ // panel
436
+ const px = W / 2
437
+ const py = H / 2
438
+ ctx.beginPath()
439
+ ctx.roundRect(px - m * 0.42, py - m * 0.3, m * 0.84, m * 0.6, m * 0.04)
440
+ ink(ctx, '#2a2e36', 2)
441
+ ctx.fillStyle = '#9aa3ad'
442
+ for (const [sx, sy] of [
443
+ [-1, -1],
444
+ [1, -1],
445
+ [-1, 1],
446
+ [1, 1],
447
+ ])
448
+ ctx.fillRect(px + sx * m * 0.38 - m * 0.01, py + sy * m * 0.26 - m * 0.01, m * 0.02, m * 0.02)
449
+ ctx.save()
450
+ ctx.textAlign = 'center'
451
+ ctx.font = `${m * 0.08}px ${FONT.latin}`
452
+ ctx.fillStyle = on > 0.5 ? '#9ff0ff' : '#5a6270'
453
+ ctx.fillText('J E T', px, py - m * 0.17)
454
+ ctx.font = `${m * 0.05}px ${FONT.black}`
455
+ ctx.fillText('喷射', px, py + m * 0.24)
456
+ ctx.restore()
457
+ // LED ring
458
+ glowBlob(ctx, px, py, m * 0.25, '#3de0ff', 0.15 + 0.7 * on)
459
+ ctx.strokeStyle = on > 0.5 ? '#7feaff' : '#2a3a44'
460
+ ctx.lineWidth = m * 0.015
461
+ ctx.beginPath()
462
+ ctx.arc(px, py + m * 0.03, m * 0.13, 0, Math.PI * 2 * Math.max(0.02, on))
463
+ ctx.stroke()
464
+ // toggle
465
+ capsule(ctx, { x: px, y: py + m * 0.05 }, { x: px, y: py + m * 0.05 - m * (press > 0.5 ? -0.06 : 0.08) }, m * 0.02, m * 0.025, '#c9d0d8', 2)
466
+ // red flip cover (hinged at the top)
467
+ const ca = cover * 1.9
468
+ ctx.save()
469
+ ctx.translate(px, py - m * 0.07)
470
+ ctx.scale(1, Math.cos(ca))
471
+ ctx.beginPath()
472
+ ctx.roundRect(-m * 0.07, 0, m * 0.14, m * 0.2, m * 0.02)
473
+ ink(ctx, rgba('#d01830', 0.92), 2)
474
+ ctx.restore()
475
+ // finger
476
+ if (cover > 0.05 || press > 0) {
477
+ const fx = px + m * 0.05 - press * m * 0.04
478
+ const fy = py + m * 0.05 + (press > 0.5 ? m * 0.03 : -m * 0.06)
479
+ capsule(ctx, { x: W * 1.05, y: H * 0.95 }, { x: fx + m * 0.14, y: fy + m * 0.08 }, m * 0.12, m * 0.08, HERO.sweater, 2)
480
+ capsule(ctx, { x: fx + m * 0.14, y: fy + m * 0.08 }, { x: fx, y: fy }, m * 0.05, m * 0.03, HERO.skin, 2)
481
+ }
482
+ if (on > 0) {
483
+ ctx.save()
484
+ ctx.globalAlpha = on
485
+ speedLines(ctx, px, py, m, t, 80, '#7feaff', 0.15, 0.4)
486
+ ctx.restore()
487
+ }
488
+ }
489
+
490
+ // =====================================================================
491
+ // S5 — 倒车闪灯 (43.84 – 72.95s)
492
+ // =====================================================================
493
+ const vR = 32
494
+
495
+ export function duelState(tau: number): { hero: CarState; rival: CarState } {
496
+ const b = (n: number) => n * BEAT
497
+ const Bs = 2 * BAR
498
+ const Ds = 6 * BAR
499
+ const Fs = 10 * BAR
500
+ const Gs = 11 * BAR
501
+ const zR = vR * tau
502
+ // rival weaves once to block, brakes on some beats
503
+ const xR = -1.4 * Math.sin(Math.PI * clamp((tau - Bs - b(1)) / b(3))) * (tau > Bs ? 1 : 0)
504
+ let dz = -10
505
+ let xH = 0
506
+ let h = 0
507
+ // overtake
508
+ dz = lerp(-10, 10, seg(tau, Bs + b(2), Bs + b(9)))
509
+ xH = -3.6 * seg(tau, Bs + b(1), Bs + b(3)) + 3.6 * seg(tau, Bs + b(9), Bs + b(11))
510
+ // handbrake #1: 0 → π
511
+ h = Math.PI * seg(tau, Ds + b(0.5), Ds + b(2.5))
512
+ dz -= 2 * seg(tau, Ds + b(0.5), Ds + b(2.5))
513
+ xH += 0.8 * Math.sin(Math.PI * clamp((tau - Ds - b(0.5)) / b(2)))
514
+ // handbrake #2: π → 2π
515
+ h += Math.PI * seg(tau, Fs + b(0.5), Fs + b(2.5))
516
+ xH -= 0.8 * Math.sin(Math.PI * clamp((tau - Fs - b(0.5)) / b(2)))
517
+ // floor it
518
+ const g = Math.max(0, tau - Gs - b(0.5))
519
+ dz += 0.5 * 16 * g * g
520
+ return {
521
+ hero: { x: xH, z: zR + dz, h },
522
+ rival: { x: xR, z: zR, h: 0, brake: tau > Bs && tau < Ds && fract(tau / BEAT) < 0.3 && Math.floor(tau / BEAT) % 2 === 0 ? 1 : tau > Gs ? 0.8 : 0.1 },
523
+ }
524
+ }
525
+
526
+ function topDuel(s: SceneCtx, tau: number, follow: 'mid' | 'rival', high: number) {
527
+ const { ctx, W, H, P } = s
528
+ const k = Math.max(W, H) / 40
529
+ const st = duelState(tau)
530
+ const zc = follow === 'mid' ? (st.hero.z + st.rival.z) / 2 : st.rival.z + 8
531
+ ctx.save()
532
+ ctx.translate(W / 2, H / 2)
533
+ if (!P) ctx.rotate(Math.PI / 2)
534
+ drawTopRoad(s, zc, k)
535
+ const Ds = 6 * BAR
536
+ const Fs = 10 * BAR
537
+ const hist = (tt: number) => duelState(tt).hero
538
+ spinFx(ctx, hist, tau, Ds + 0.5 * BEAT, Ds + 2.7 * BEAT, zc, k)
539
+ spinFx(ctx, hist, tau, Fs + 0.5 * BEAT, Fs + 2.7 * BEAT, zc, k)
540
+ carTop(ctx, 'rival', st.rival.x * k, -(st.rival.z - zc) * k, k, 0, { head: 1, brake: st.rival.brake })
541
+ carTop(ctx, 'hero', st.hero.x * k, -(st.hero.z - zc) * k, k, st.hero.h, { head: 1, high })
542
+ ctx.restore()
543
+ }
544
+
545
+ export function sDuel(s: SceneCtx) {
546
+ const { ctx, W, H, lt, u, t, a, P } = s
547
+ const tau = lt
548
+ const bar = Math.floor(tau / BAR)
549
+ const inBar = tau - bar * BAR
550
+ if (bar === 0) {
551
+ // 阿飞 driving; the red car's high beams flood in from behind — provocation
552
+ const glare = a.beatPhase < 0.35 && a.beat % 2 === 0 ? 1 - a.beatPhase / 0.35 : 0
553
+ driverProfile(s, glare, inBar > BAR * 0.6 ? 1 : 0)
554
+ return
555
+ }
556
+ if (bar === 1) {
557
+ // POV: the red car cuts in front, weaves and brake-checks, backfires on the kick
558
+ const { hy, f } = povRoad(s, 34, '#3a1530')
559
+ const dz = lerp(30, 11, easeOutCubic(inBar / BAR))
560
+ const weave = Math.sin(inBar * 3.2) * 1.4 - lerp(3.6, 0, easeOutCubic(inBar / (BAR * 0.5)))
561
+ const w = (1.88 * f) / dz
562
+ carRear(ctx, 'rival', W / 2 + (weave * f) / dz, hy + (1.2 * f) / dz, w, { brake: a.beatPhase < 0.3 ? 1 : 0.1, pop: a.kick, t })
563
+ windshield(s, false)
564
+ return
565
+ }
566
+ if (bar >= 2 && bar < 5) {
567
+ topDuel(s, tau, 'mid', 0)
568
+ return
569
+ }
570
+ if (bar === 5) {
571
+ // pull the handbrake on beat 2
572
+ handbrakeCU(s, seg(inBar, BEAT * 1.6, BEAT * 2.1))
573
+ return
574
+ }
575
+ if (bar >= 6 && bar < 8) {
576
+ topDuel(s, tau, 'mid', 0)
577
+ return
578
+ }
579
+ if (bar >= 8 && bar < 10) {
580
+ // high-beam flashes, synced to the beat
581
+ const flash = a.beatPhase < 0.45 ? 1 - a.beatPhase / 0.45 : 0
582
+ const view = Math.floor((tau - 8 * BAR) / (BEAT * 2)) % 2
583
+ if (view === 0) {
584
+ // the rival's POV: 阿飞's car ahead, driving backwards, facing them
585
+ const { hy, f } = povRoad(s, 32, '#40101c')
586
+ const dz = 9
587
+ const w = (1.72 * f) / dz
588
+ heroCarFront(ctx, W / 2 + Math.sin(t * 0.8) * u * 10, hy + (1.2 * f) / dz, w, { head: 0.6, high: flash, t })
589
+ windshield(s, true)
590
+ if (flash > 0.2) {
591
+ ctx.fillStyle = `rgba(255,255,255,${0.55 * flash})`
592
+ ctx.fillRect(0, 0, W, H)
593
+ }
594
+ } else topDuel(s, tau, 'mid', flash)
595
+ return
596
+ }
597
+ if (bar === 10) {
598
+ topDuel(s, tau, 'mid', 0)
599
+ return
600
+ }
601
+ // floor it and leave
602
+ topDuel(s, tau, inBar > BEAT && bar >= 11 ? 'rival' : 'mid', 0)
603
+ void P
604
+ }
605
+
606
+ // =====================================================================
607
+ // S8 — 喷射飞越 (109.436 – 127.64s)
608
+ // =====================================================================
609
+ interface JumpState {
610
+ dx: number // hero x relative to rival (m)
611
+ y: number // hero height above road (m)
612
+ pitch: number
613
+ jetPower: number
614
+ jetAngle: number // relative to the car: π/2 down, π backwards
615
+ compress: number
616
+ look: number
617
+ dist: number // distance travelled (for wheel spin)
618
+ }
619
+
620
+ export function jumpState(tj: number): JumpState {
621
+ const b = (n: number) => n * BEAT
622
+ const T0 = b(2)
623
+ const T1 = b(8)
624
+ const Sw0 = b(9)
625
+ const Sw1 = b(10.5)
626
+ const Bo = b(12)
627
+ let dx = lerp(-8, -6.4, seg(tj, 0, T0))
628
+ let y = 0
629
+ let pitch = 0
630
+ let jetPower = 0.15 + 0.5 * smoothstep(b(0.8), T0, tj)
631
+ let jetAngle = Math.PI / 2
632
+ let compress = 0
633
+ if (tj >= T0 && tj < T1) {
634
+ const q = (tj - T0) / (T1 - T0)
635
+ dx = lerp(-6.4, 6.6, ease(q))
636
+ y = 4 * 3.1 * q * (1 - q)
637
+ pitch = q < 0.5 ? lerp(-0.13, 0, q / 0.5) : q < 0.9 ? lerp(0, 0.09, (q - 0.5) / 0.4) : lerp(0.09, 0, (q - 0.9) / 0.1)
638
+ // full lift at take-off, cruise mid-air, full again to cushion the landing
639
+ jetPower = q < 0.22 ? 1 : q < 0.62 ? 0.35 : 1
640
+ } else if (tj >= T1) {
641
+ dx = 6.6
642
+ const k = tj - T1
643
+ compress = Math.exp(-k * 5) * Math.cos(k * 18) * 0.14
644
+ jetPower = tj < T1 + b(0.6) ? 0.8 : 0.25
645
+ jetAngle = Math.PI / 2 + (Math.PI / 2) * seg(tj, Sw0, Sw1)
646
+ if (tj >= Sw1) jetPower = tj < Bo ? 0.35 : 1
647
+ const g = Math.max(0, tj - Bo)
648
+ dx += 0.5 * 9 * g * g
649
+ }
650
+ const look = smoothstep(T0 + b(1), T0 + b(2.5), tj) * (1 - smoothstep(T1 - b(1), T1 + b(1), tj))
651
+ return { dx, y, pitch, jetPower, jetAngle, compress, look, dist: tj * 30 + dx }
652
+ }
653
+
654
+ function sideJump(s: SceneCtx, tj: number) {
655
+ const { ctx, W, H, t, P, a } = s
656
+ const k = P ? W / 12 : W / 22
657
+ const gy = H * (P ? 0.66 : 0.72)
658
+ const st = jumpState(tj)
659
+ const camX = clamp(st.dx * 0.45, -2, 6)
660
+ const toX = (mx: number) => W / 2 + (mx - camX) * k
661
+ const scroll = tj * 30 // background speed (m)
662
+ // sky + city
663
+ vGradient(ctx, 0, 0, W, gy, [
664
+ [0, '#05060f'],
665
+ [0.6, '#1c1640'],
666
+ [1, '#5a1f4a'],
667
+ ])
668
+ glowBlob(ctx, W * 0.5, gy, Math.max(W, H) * 0.5, '#ff5a7a', 0.22)
669
+ skyline(ctx, { W, seed: 57, baseY: gy - H * 0.08, scroll: scroll * k * 0.05, cell: k * 1.6, minH: H * 0.08, maxH: H * 0.32, color: '#0b0a18', t, density: 0.25, winAlpha: 0.6 })
670
+ // light poles passing
671
+ for (let i = -1; i < 6; i++) {
672
+ const wx = Math.floor(scroll / 25) * 25 + i * 25
673
+ const x = toX(wx - scroll)
674
+ if (x < -k * 4 || x > W + k * 4) continue
675
+ ctx.fillStyle = '#121318'
676
+ ctx.fillRect(x - k * 0.08, gy - k * 8, k * 0.16, k * 8)
677
+ ctx.fillRect(x - k * 2, gy - k * 8, k * 2, k * 0.12)
678
+ glowBlob(ctx, x - k * 1.9, gy - k * 7.9, k * 1.2, PALETTE.sodium, 0.9)
679
+ lightCone(ctx, x - k * 1.9, gy - k * 7.9, k * 8, 0.35, 0, PALETTE.sodium, 0.1)
680
+ }
681
+ // guard rail + road
682
+ ctx.fillStyle = '#2a2d34'
683
+ ctx.fillRect(0, gy - k * 0.9, W, k * 0.12)
684
+ for (let i = -1; i < 40; i++) {
685
+ const wx = Math.floor(scroll / 2.5) * 2.5 + i * 2.5
686
+ const x = toX(wx - scroll)
687
+ if (x < -10 || x > W + 10) continue
688
+ ctx.fillRect(x, gy - k * 0.9, k * 0.08, k * 0.9)
689
+ }
690
+ ctx.fillStyle = '#0d0e12'
691
+ ctx.fillRect(0, gy, W, H - gy)
692
+ ctx.fillStyle = 'rgba(235,230,215,0.8)'
693
+ for (let i = -1; i < 12; i++) {
694
+ const wx = Math.floor(scroll / 12) * 12 + i * 12
695
+ const x = toX(wx - scroll)
696
+ ctx.fillRect(x, gy + (H - gy) * 0.35, k * 5, k * 0.12)
697
+ }
698
+ // rival (always at x = 0)
699
+ carSide(ctx, 'rival', toX(0), gy, 4.5 * k, 0, { spin: -(scroll / 0.5), head: 1, brake: 0.1, t, look: st.look })
700
+ // hero
701
+ const hx = toX(st.dx)
702
+ const hy = gy - st.y * k + st.compress * k
703
+ // shadow under the hero while airborne
704
+ ctx.fillStyle = `rgba(0,0,0,${0.5 - Math.min(0.35, st.y * 0.1)})`
705
+ ctx.beginPath()
706
+ ctx.ellipse(hx, gy + 2, k * (2 - Math.min(1, st.y * 0.25)), k * 0.15, 0, 0, Math.PI * 2)
707
+ ctx.fill()
708
+ carSide(ctx, 'hero', hx, hy, 4.0 * k, st.pitch, { spin: -(st.dist / 0.46), head: 1, t, jetKit: true, jet: { power: st.jetPower, angle: st.jetAngle }, groundY: gy })
709
+ // landing sparks
710
+ const T1 = 8 * BEAT
711
+ if (tj > T1 && tj < T1 + 0.5) {
712
+ const q = (tj - T1) / 0.5
713
+ ctx.fillStyle = '#ffd27a'
714
+ for (let i = 0; i < 26; i++) {
715
+ const sx = hx + (hash(i) - 0.7) * k * 4 - q * k * 3 * hash(i * 2)
716
+ const sy = gy - q * k * 1.2 * hash(i * 3) + q * q * k
717
+ ctx.globalAlpha = 1 - q
718
+ ctx.fillRect(sx, sy, k * 0.08, k * 0.04)
719
+ }
720
+ ctx.globalAlpha = 1
721
+ }
722
+ void a
723
+ }
724
+
725
+ export function sJump(s: SceneCtx) {
726
+ const { ctx, W, H, lt, u, t, a } = s
727
+ const bar = Math.floor(lt / BAR)
728
+ const inBar = lt - bar * BAR
729
+ if (bar < 2) {
730
+ // stuck behind the red car: every time he moves, it moves to block
731
+ const { hy, f } = povRoad(s, 34, '#3a1530')
732
+ const tries = Math.sin(lt * 1.7)
733
+ const block = Math.sin(lt * 1.7 - 0.5)
734
+ const dz = 9 + Math.sin(lt * 0.8) * 1.5
735
+ const w = (1.88 * f) / dz
736
+ ctx.save()
737
+ ctx.translate(-tries * u * 60, 0)
738
+ carRear(ctx, 'rival', W / 2 + (block * 2.6 * f) / dz, hy + (1.2 * f) / dz, w, { brake: a.beatPhase < 0.3 && a.beat % 2 === 0 ? 1 : 0.15, pop: a.kick, t })
739
+ ctx.restore()
740
+ windshield(s, false)
741
+ return
742
+ }
743
+ if (bar === 2) {
744
+ jetSwitchCU(s, seg(inBar, BEAT * 0.3, BEAT * 1.2), seg(inBar, BEAT * 1.7, BEAT * 2.1))
745
+ return
746
+ }
747
+ if (bar < 7) {
748
+ sideJump(s, lt - 3 * BAR)
749
+ return
750
+ }
751
+ // the rival's POV: the hatchback rockets away on its jets
752
+ const { hy, f } = povRoad(s, 32, '#40101c')
753
+ const g = inBar
754
+ const dz = 12 + 0.5 * 30 * g * g
755
+ const w = (1.72 * f) / dz
756
+ carRear(ctx, 'hero', W / 2, hy + (1.2 * f) / dz, w, { jet: 1, t })
757
+ windshield(s, true)
758
+ void H
759
+ }
760
+
761
+ void withPalette
762
+ void RIVAL
763
+ void HERO_H
764
+ void hash
765
+ void resetCam
766
+ void smoothstep
src/mv/engine/scenesMarket.ts ADDED
@@ -0,0 +1,521 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // S6 — 葱姜蒜夜市 (rebuilt)
2
+ // shot 1: side-on panorama of a night market street, 阿飞 rides in slowly
3
+ // shot 2: the 葱姜蒜 stall up close — the auntie bags scallions, ginger and
4
+ // garlic and hands the red bag to 阿飞
5
+ // shot 3: he rides off through the market, the bag swinging on his handlebar
6
+ import { BAR } from './audio'
7
+ import { fogBand, glowBlob, lantern, neonSign, vGradient } from './draw'
8
+ import { AUNTIE, HERO_H, capsule, circle, heroRide, heroWalk, ink, ridePose, walkPose, withPalette } from './hero'
9
+ import type { SceneCtx } from './types'
10
+ import { FONT, PALETTE, clamp, easeInOutCubic, fract, hash, lerp, rgba, smoothstep } from './util'
11
+
12
+ type C2D = CanvasRenderingContext2D
13
+
14
+ const STALLS = ['葱姜蒜', '烧烤', '糖水', '鱼蛋', '水果', '炒粉'] as const
15
+ type Stall = (typeof STALLS)[number]
16
+ const AWNING: Record<Stall, [string, string]> = {
17
+ 葱姜蒜: ['#2a8a4a', '#efe9dc'],
18
+ 烧烤: ['#c4142f', '#efe9dc'],
19
+ 糖水: ['#2a6ac4', '#efe9dc'],
20
+ 鱼蛋: ['#e0a01c', '#3a2a14'],
21
+ 水果: ['#d0503a', '#f6e6c4'],
22
+ 炒粉: ['#8a1e1e', '#e8c890'],
23
+ }
24
+
25
+ // ------------------------------------------------------------------ goods
26
+ function basket(ctx: C2D, x: number, y: number, w: number) {
27
+ ctx.beginPath()
28
+ ctx.moveTo(x - w / 2, y - w * 0.28)
29
+ ctx.lineTo(x + w / 2, y - w * 0.28)
30
+ ctx.lineTo(x + w * 0.42, y)
31
+ ctx.lineTo(x - w * 0.42, y)
32
+ ctx.closePath()
33
+ ink(ctx, '#8a5a2a', Math.max(1, w * 0.02))
34
+ ctx.strokeStyle = 'rgba(40,24,10,0.5)'
35
+ ctx.lineWidth = Math.max(1, w * 0.012)
36
+ ctx.beginPath()
37
+ for (let k = 1; k < 4; k++) {
38
+ ctx.moveTo(x - w * (0.5 - k * 0.02), y - w * 0.28 + k * w * 0.07)
39
+ ctx.lineTo(x + w * (0.5 - k * 0.02), y - w * 0.28 + k * w * 0.07)
40
+ }
41
+ for (let k = -3; k <= 3; k++) {
42
+ ctx.moveTo(x + k * w * 0.13, y - w * 0.28)
43
+ ctx.lineTo(x + k * w * 0.11, y)
44
+ }
45
+ ctx.stroke()
46
+ }
47
+
48
+ function scallions(ctx: C2D, x: number, y: number, w: number, t: number) {
49
+ basket(ctx, x, y, w)
50
+ for (let i = 0; i < 16; i++) {
51
+ const bx = x + (i / 15 - 0.5) * w * 0.85
52
+ const sway = Math.sin(t * 1.5 + i) * w * 0.02
53
+ const top = y - w * (0.75 + 0.25 * hash(i * 3.1))
54
+ ctx.strokeStyle = i % 3 ? '#5fbf3a' : '#8fdc5a'
55
+ ctx.lineWidth = Math.max(1, w * 0.035)
56
+ ctx.beginPath()
57
+ ctx.moveTo(bx, y - w * 0.3)
58
+ ctx.quadraticCurveTo(bx + sway, (top + y) / 2, bx + sway * 2 + (hash(i) - 0.5) * w * 0.15, top)
59
+ ctx.stroke()
60
+ }
61
+ ctx.fillStyle = '#f2efe4'
62
+ ctx.fillRect(x - w * 0.42, y - w * 0.36, w * 0.84, w * 0.08)
63
+ ctx.fillStyle = '#c4142f'
64
+ ctx.fillRect(x - w * 0.42, y - w * 0.33, w * 0.84, w * 0.025)
65
+ }
66
+
67
+ function ginger(ctx: C2D, x: number, y: number, w: number) {
68
+ basket(ctx, x, y, w)
69
+ for (let i = 0; i < 9; i++) {
70
+ const gx = x + (hash(i * 1.7) - 0.5) * w * 0.75
71
+ const gy = y - w * (0.32 + 0.12 * hash(i * 2.9))
72
+ ctx.fillStyle = i % 2 ? '#d9a84a' : '#c8923a'
73
+ ctx.beginPath()
74
+ ctx.ellipse(gx, gy, w * 0.11, w * 0.06, hash(i) * 2, 0, Math.PI * 2)
75
+ ctx.ellipse(gx + w * 0.07, gy - w * 0.04, w * 0.05, w * 0.035, 0.6, 0, Math.PI * 2)
76
+ ctx.ellipse(gx - w * 0.06, gy - w * 0.035, w * 0.045, w * 0.03, -0.5, 0, Math.PI * 2)
77
+ ctx.fill()
78
+ ctx.strokeStyle = 'rgba(120,80,30,0.6)'
79
+ ctx.lineWidth = Math.max(1, w * 0.008)
80
+ ctx.beginPath()
81
+ ctx.moveTo(gx - w * 0.06, gy)
82
+ ctx.lineTo(gx + w * 0.05, gy + w * 0.01)
83
+ ctx.stroke()
84
+ }
85
+ }
86
+
87
+ function garlic(ctx: C2D, x: number, y: number, w: number) {
88
+ basket(ctx, x, y, w)
89
+ for (let i = 0; i < 8; i++) {
90
+ const gx = x + (hash(i * 4.3) - 0.5) * w * 0.7
91
+ const gy = y - w * (0.34 + 0.14 * hash(i * 1.1))
92
+ const r = w * 0.085
93
+ ctx.beginPath()
94
+ ctx.moveTo(gx, gy - r * 1.6)
95
+ ctx.quadraticCurveTo(gx + r * 1.3, gy - r * 0.6, gx + r, gy + r * 0.5)
96
+ ctx.quadraticCurveTo(gx, gy + r, gx - r, gy + r * 0.5)
97
+ ctx.quadraticCurveTo(gx - r * 1.3, gy - r * 0.6, gx, gy - r * 1.6)
98
+ ink(ctx, '#f2ece0', Math.max(1, w * 0.01))
99
+ ctx.strokeStyle = 'rgba(150,90,140,0.7)'
100
+ ctx.lineWidth = Math.max(1, w * 0.008)
101
+ ctx.beginPath()
102
+ ctx.moveTo(gx, gy - r * 1.4)
103
+ ctx.lineTo(gx, gy + r * 0.8)
104
+ ctx.moveTo(gx - r * 0.5, gy - r * 0.9)
105
+ ctx.quadraticCurveTo(gx - r * 0.7, gy, gx - r * 0.45, gy + r * 0.7)
106
+ ctx.moveTo(gx + r * 0.5, gy - r * 0.9)
107
+ ctx.quadraticCurveTo(gx + r * 0.7, gy, gx + r * 0.45, gy + r * 0.7)
108
+ ctx.stroke()
109
+ }
110
+ }
111
+
112
+ function priceCard(ctx: C2D, x: number, y: number, w: number, text: string, tilt: number) {
113
+ ctx.save()
114
+ ctx.translate(x, y)
115
+ ctx.rotate(tilt)
116
+ ctx.beginPath()
117
+ ctx.rect(-w / 2, -w * 0.32, w, w * 0.64)
118
+ ink(ctx, '#d9b47a', Math.max(1, w * 0.02))
119
+ ctx.fillStyle = '#1a1410'
120
+ ctx.font = `${w * 0.24}px ${FONT.black}`
121
+ ctx.textAlign = 'center'
122
+ ctx.textBaseline = 'middle'
123
+ ctx.fillText(text, 0, 0)
124
+ ctx.restore()
125
+ }
126
+
127
+ function steam(ctx: C2D, x: number, y: number, w: number, t: number, seed: number) {
128
+ for (let i = 0; i < 7; i++) {
129
+ const life = fract(t * 0.35 + i / 7 + hash(seed + i))
130
+ ctx.fillStyle = `rgba(255,240,225,${0.12 * (1 - life)})`
131
+ ctx.beginPath()
132
+ ctx.arc(x + Math.sin(t + i + seed) * w * 0.15, y - life * w * 1.4, w * (0.15 + life * 0.35), 0, Math.PI * 2)
133
+ ctx.fill()
134
+ }
135
+ }
136
+
137
+ function goods(ctx: C2D, kind: Stall, x: number, y: number, w: number, t: number, seed: number) {
138
+ switch (kind) {
139
+ case '葱姜蒜':
140
+ scallions(ctx, x - w * 0.3, y, w * 0.28, t)
141
+ ginger(ctx, x, y, w * 0.26)
142
+ garlic(ctx, x + w * 0.3, y, w * 0.26)
143
+ break
144
+ case '烧烤': {
145
+ ctx.fillStyle = '#1a1a1c'
146
+ ctx.fillRect(x - w * 0.4, y - w * 0.08, w * 0.8, w * 0.08)
147
+ glowBlob(ctx, x, y - w * 0.06, w * 0.5, '#ff5a1c', 0.6 + 0.2 * Math.sin(t * 8 + seed))
148
+ for (let i = 0; i < 9; i++) {
149
+ const sx = x + (i / 8 - 0.5) * w * 0.7
150
+ ctx.strokeStyle = '#d8b07a'
151
+ ctx.lineWidth = Math.max(1, w * 0.008)
152
+ ctx.beginPath()
153
+ ctx.moveTo(sx - w * 0.06, y - w * 0.12)
154
+ ctx.lineTo(sx + w * 0.06, y - w * 0.07)
155
+ ctx.stroke()
156
+ ctx.fillStyle = '#7a3a1a'
157
+ for (let k = 0; k < 3; k++) ctx.fillRect(sx - w * 0.04 + k * w * 0.03, y - w * 0.115 + k * w * 0.012, w * 0.022, w * 0.022)
158
+ }
159
+ steam(ctx, x, y - w * 0.15, w * 0.5, t, seed)
160
+ break
161
+ }
162
+ case '糖水':
163
+ case '鱼蛋': {
164
+ for (const dx of [-0.22, 0.22]) {
165
+ ctx.beginPath()
166
+ ctx.roundRect(x + dx * w - w * 0.16, y - w * 0.22, w * 0.32, w * 0.22, w * 0.03)
167
+ ink(ctx, '#b8c0c8', Math.max(1, w * 0.01))
168
+ ctx.fillStyle = kind === '糖水' ? '#e8c890' : '#d8a84a'
169
+ ctx.fillRect(x + dx * w - w * 0.14, y - w * 0.22, w * 0.28, w * 0.03)
170
+ steam(ctx, x + dx * w, y - w * 0.25, w * 0.35, t, seed + dx * 10)
171
+ }
172
+ if (kind === '鱼蛋')
173
+ for (let i = 0; i < 5; i++) {
174
+ ctx.strokeStyle = '#d8b07a'
175
+ ctx.beginPath()
176
+ ctx.moveTo(x - w * 0.25 + i * w * 0.03, y - w * 0.2)
177
+ ctx.lineTo(x - w * 0.27 + i * w * 0.03, y - w * 0.4)
178
+ ctx.stroke()
179
+ ctx.fillStyle = '#e8b04a'
180
+ for (let k = 0; k < 3; k++) {
181
+ ctx.beginPath()
182
+ ctx.arc(x - w * 0.265 + i * w * 0.03, y - w * (0.3 + k * 0.035), w * 0.016, 0, Math.PI * 2)
183
+ ctx.fill()
184
+ }
185
+ }
186
+ break
187
+ }
188
+ case '水果': {
189
+ const cols = ['#ff8a1c', '#ffd23a', '#c4142f', '#5fbf3a']
190
+ for (let r = 0; r < 4; r++)
191
+ for (let c = 0; c <= 6 - r * 2; c++) {
192
+ ctx.fillStyle = cols[(c + r + seed) % 4]
193
+ ctx.beginPath()
194
+ ctx.arc(x + (c - (6 - r * 2) / 2) * w * 0.07, y - w * (0.035 + r * 0.06), w * 0.035, 0, Math.PI * 2)
195
+ ctx.fill()
196
+ }
197
+ break
198
+ }
199
+ case '炒粉': {
200
+ // wok with fire bursts
201
+ ctx.beginPath()
202
+ ctx.arc(x, y - w * 0.12, w * 0.2, 0, Math.PI)
203
+ ink(ctx, '#202228', Math.max(1, w * 0.01))
204
+ const burst = Math.max(0, Math.sin(t * 2.3 + seed))
205
+ if (burst > 0.4) {
206
+ ctx.save()
207
+ ctx.globalCompositeOperation = 'lighter'
208
+ glowBlob(ctx, x, y - w * 0.2, w * 0.5 * burst, '#ff7a2e', 0.9)
209
+ glowBlob(ctx, x, y - w * 0.3, w * 0.25 * burst, '#ffe08a', 0.9)
210
+ ctx.restore()
211
+ }
212
+ steam(ctx, x, y - w * 0.2, w * 0.4, t, seed)
213
+ break
214
+ }
215
+ }
216
+ }
217
+
218
+ // ------------------------------------------------------------------ one stall
219
+ function stall(ctx: C2D, kind: Stall, x: number, groundY: number, w: number, u: number, t: number, seed: number, vendor = true) {
220
+ const h = w * 0.95
221
+ const counterY = groundY - h * 0.38
222
+ const roofY = groundY - h * 0.95
223
+ const [c1, c2] = AWNING[kind]
224
+ // back wall glow
225
+ ctx.fillStyle = '#2a1a10'
226
+ ctx.fillRect(x - w / 2, roofY, w, counterY - roofY)
227
+ glowBlob(ctx, x, counterY - h * 0.25, w * 0.7, PALETTE.amber, 0.3)
228
+ // vendor behind the counter
229
+ if (vendor) {
230
+ withPalette(AUNTIE, () => {
231
+ heroWalk(ctx, x + w * 0.05, counterY + h * 0.28, h * 0.62, 0, { facing: -1, stand: true, t, eyes: 'open', scarf: seed % 2 ? '#c4142f' : '#2a6ac4' })
232
+ })
233
+ }
234
+ // poles
235
+ ctx.fillStyle = '#1a1410'
236
+ ctx.fillRect(x - w / 2, roofY, w * 0.025, groundY - roofY)
237
+ ctx.fillRect(x + w / 2 - w * 0.025, roofY, w * 0.025, groundY - roofY)
238
+ // counter
239
+ ctx.beginPath()
240
+ ctx.rect(x - w * 0.48, counterY, w * 0.96, groundY - counterY)
241
+ ink(ctx, '#3a2414', Math.max(1, u * 2))
242
+ ctx.fillStyle = '#5a3a20'
243
+ ctx.fillRect(x - w * 0.5, counterY - u * 6, w, u * 8)
244
+ goods(ctx, kind, x, counterY, w, t, seed)
245
+ // striped awning (scalloped edge)
246
+ const n = 8
247
+ for (let i = 0; i < n; i++) {
248
+ ctx.fillStyle = i % 2 ? c2 : c1
249
+ ctx.beginPath()
250
+ ctx.moveTo(x - w * 0.56 + (i / n) * w * 1.12, roofY - h * 0.12)
251
+ ctx.lineTo(x - w * 0.56 + ((i + 1) / n) * w * 1.12, roofY - h * 0.12)
252
+ ctx.lineTo(x - w * 0.56 + ((i + 1) / n) * w * 1.12, roofY + h * 0.04)
253
+ ctx.arc(x - w * 0.56 + ((i + 0.5) / n) * w * 1.12, roofY + h * 0.04, (w * 0.56) / n, 0, Math.PI)
254
+ ctx.closePath()
255
+ ctx.fill()
256
+ }
257
+ ctx.strokeStyle = '#120c08'
258
+ ctx.lineWidth = Math.max(1, u * 2)
259
+ ctx.strokeRect(x - w * 0.56, roofY - h * 0.12, w * 1.12, h * 0.16)
260
+ // hanging bulbs
261
+ for (let i = 0; i < 3; i++) {
262
+ const bx = x + (i - 1) * w * 0.3
263
+ const sw = Math.sin(t * 1.4 + i + seed) * u * 4
264
+ ctx.strokeStyle = '#120c08'
265
+ ctx.beginPath()
266
+ ctx.moveTo(bx, roofY + h * 0.04)
267
+ ctx.lineTo(bx + sw, roofY + h * 0.14)
268
+ ctx.stroke()
269
+ glowBlob(ctx, bx + sw, roofY + h * 0.16, w * 0.22, '#ffd08a', 0.75)
270
+ circle(ctx, { x: bx + sw, y: roofY + h * 0.16 }, w * 0.025, '#fff1c8', 0)
271
+ }
272
+ // painted sign board on top
273
+ ctx.beginPath()
274
+ ctx.rect(x - w * 0.3, roofY - h * 0.3, w * 0.6, h * 0.17)
275
+ ink(ctx, '#f2e6c8', Math.max(1, u * 2))
276
+ ctx.fillStyle = kind === '葱姜蒜' ? '#2a7a3a' : '#a01020'
277
+ ctx.font = `${h * 0.12}px ${FONT.neon}`
278
+ ctx.textAlign = 'center'
279
+ ctx.textBaseline = 'middle'
280
+ ctx.fillText(kind, x, roofY - h * 0.215)
281
+ }
282
+
283
+ // ------------------------------------------------------------------ backdrop
284
+ function tenements(s: SceneCtx, scroll: number, baseY: number) {
285
+ const { ctx, W, H, u, t } = s
286
+ const cell = u * 260
287
+ const sc = scroll * 0.35
288
+ const k0 = Math.floor(sc / cell) - 1
289
+ for (let k = k0; k < k0 + Math.ceil(W / cell) + 3; k++) {
290
+ const x = k * cell - sc
291
+ const top = baseY - H * (0.55 + 0.25 * hash(k * 3.3))
292
+ ctx.fillStyle = k % 2 ? '#1a1418' : '#16121a'
293
+ ctx.fillRect(x, top, cell + 1, baseY - top)
294
+ // windows + balconies
295
+ for (let r = 0; r < 8; r++) {
296
+ const wy = top + u * 30 + r * u * 70
297
+ if (wy > baseY - u * 60) break
298
+ for (let c = 0; c < 3; c++) {
299
+ const lit = hash(k * 7 + r * 3 + c) > 0.35
300
+ ctx.fillStyle = lit ? (hash(k + r + c) > 0.8 ? '#7fc8d8' : '#e8a050') : '#0c0a0e'
301
+ ctx.globalAlpha = lit ? 0.8 : 1
302
+ ctx.fillRect(x + u * 20 + c * u * 80, wy, u * 50, u * 36)
303
+ ctx.globalAlpha = 1
304
+ }
305
+ ctx.fillStyle = '#0a080c'
306
+ ctx.fillRect(x + u * 10, wy + u * 40, cell - u * 20, u * 6)
307
+ // laundry on poles
308
+ if (hash(k * 5 + r) > 0.6) {
309
+ ctx.strokeStyle = '#3a3036'
310
+ ctx.beginPath()
311
+ ctx.moveTo(x + u * 10, wy + u * 48)
312
+ ctx.lineTo(x + cell - u * 10, wy + u * 48)
313
+ ctx.stroke()
314
+ for (let i = 0; i < 5; i++) {
315
+ ctx.fillStyle = ['#c4142f', '#e8e2d6', '#2a6ac4', '#e8a01c'][(i + r) % 4]
316
+ ctx.fillRect(x + u * 20 + i * u * 45, wy + u * 48, u * 26, u * (22 + 10 * Math.sin(t + i)))
317
+ }
318
+ }
319
+ }
320
+ // vertical neon
321
+ if (hash(k * 1.9) > 0.45) {
322
+ const words = ['夜市', '糖水', '牛杂', '粥面', '凉茶', '冰室']
323
+ const word = words[((k % words.length) + words.length) % words.length]
324
+ neonSign(ctx, x + cell * 0.78, top + u * 40, u * 46, u * 120, word, [PALETTE.red, PALETTE.cyan, PALETTE.sodium, '#ff5fa2'][((k % 4) + 4) % 4], 0.9 + 0.1 * Math.sin(t * 3 + k), true)
325
+ }
326
+ }
327
+ }
328
+
329
+ function stringLights(s: SceneCtx, scroll: number, y0: number) {
330
+ const { ctx, W, u, t } = s
331
+ const span = u * 420
332
+ const sc = scroll * 0.7
333
+ const k0 = Math.floor(sc / span) - 1
334
+ for (let k = k0; k < k0 + Math.ceil(W / span) + 2; k++) {
335
+ const x0 = k * span - sc
336
+ ctx.strokeStyle = '#1a120c'
337
+ ctx.lineWidth = Math.max(1, u * 2)
338
+ ctx.beginPath()
339
+ for (let i = 0; i <= 20; i++) {
340
+ const q = i / 20
341
+ const x = x0 + q * span
342
+ const y = y0 + Math.sin(q * Math.PI) * u * 60
343
+ if (i) ctx.lineTo(x, y)
344
+ else ctx.moveTo(x, y)
345
+ }
346
+ ctx.stroke()
347
+ for (let i = 1; i < 10; i++) {
348
+ const q = i / 10
349
+ const x = x0 + q * span
350
+ const y = y0 + Math.sin(q * Math.PI) * u * 60 + u * 6
351
+ const on = 0.7 + 0.3 * Math.sin(t * 3 + i + k)
352
+ glowBlob(ctx, x, y, u * 26, i % 3 ? '#ffd08a' : '#ff8a6a', 0.7 * on)
353
+ circle(ctx, { x, y }, u * 5, '#fff1c8', 0)
354
+ }
355
+ if (k % 2 === 0) lantern(ctx, x0 + span * 0.5, y0 + u * 120, u * 28, Math.sin(t * 1.2 + k) * 0.1, 1)
356
+ }
357
+ }
358
+
359
+ function crowd(s: SceneCtx, scroll: number, groundY: number, h: number) {
360
+ const { ctx, W, t } = s
361
+ // passers-by in the foreground (dark silhouettes, some walking each way)
362
+ for (let i = 0; i < 8; i++) {
363
+ const dir = i % 2 ? 1 : -1
364
+ const speed = (0.6 + 0.4 * hash(i)) * h * 0.6
365
+ const span = W + h * 2
366
+ const x = ((hash(i * 3.7) * span + dir * t * speed - scroll * 1.25) % span + span) % span - h
367
+ withPalette({ sweater: '#141218', sweaterShade: '#0c0b10', sweaterHi: '#24222a', rib: '#141218', pants: '#121014', pantsShade: '#0c0b0e', skin: '#2a2024', skinShade: '#1e181a', hair: '#0a0a0a', hairHi: '#1a1a1c', shoe: '#0a0a0a', sole: '#2a2a2a' }, () => {
368
+ heroWalk(ctx, x, groundY + h * 0.18, h * (0.95 + 0.15 * hash(i * 5)), fract(t * 0.9 + hash(i)), { facing: dir, t, eyes: 'closed' })
369
+ })
370
+ }
371
+ }
372
+
373
+ function marketStreet(s: SceneCtx, scroll: number, opts: { crowd: boolean }) {
374
+ const { ctx, W, H, P, u, t } = s
375
+ const groundY = H * (P ? 0.8 : 0.82)
376
+ vGradient(ctx, 0, 0, W, H, [
377
+ [0, '#080610'],
378
+ [0.5, '#1e1018'],
379
+ [1, '#120a08'],
380
+ ])
381
+ tenements(s, scroll, groundY - H * 0.05)
382
+ fogBand(ctx, W, groundY - H * 0.3, H * 0.12, '#ff9a4a', 0.12)
383
+ stringLights(s, scroll, H * 0.08)
384
+ // stalls row
385
+ const w = P ? W * 0.62 : H * 0.62
386
+ const k0 = Math.floor(scroll / w) - 1
387
+ for (let k = k0; k < k0 + Math.ceil(W / w) + 2; k++) {
388
+ const kind = STALLS[((k % STALLS.length) + STALLS.length) % STALLS.length]
389
+ stall(ctx, kind, k * w - scroll + w / 2, groundY - H * 0.02, w * 0.92, u, t, k)
390
+ }
391
+ // wet ground with warm reflections
392
+ vGradient(ctx, 0, groundY, W, H - groundY, [
393
+ [0, '#1a120c'],
394
+ [1, '#080605'],
395
+ ])
396
+ ctx.save()
397
+ ctx.globalCompositeOperation = 'lighter'
398
+ for (let k = k0; k < k0 + Math.ceil(W / w) + 2; k++) {
399
+ const x = k * w - scroll + w / 2
400
+ const g = ctx.createLinearGradient(0, groundY, 0, H)
401
+ g.addColorStop(0, 'rgba(255,170,90,0.22)')
402
+ g.addColorStop(1, 'rgba(255,170,90,0)')
403
+ ctx.fillStyle = g
404
+ ctx.fillRect(x - w * 0.35, groundY, w * 0.7, H - groundY)
405
+ }
406
+ ctx.restore()
407
+ if (opts.crowd) crowd(s, scroll, groundY + H * 0.08, P ? H * 0.3 : H * 0.48)
408
+ return groundY
409
+ }
410
+
411
+ function redBag(ctx: C2D, x: number, y: number, sz: number, swing: number, t: number) {
412
+ ctx.save()
413
+ ctx.translate(x, y)
414
+ ctx.rotate(swing)
415
+ // handles
416
+ ctx.strokeStyle = '#b01028'
417
+ ctx.lineWidth = Math.max(1, sz * 0.08)
418
+ ctx.beginPath()
419
+ ctx.arc(0, sz * 0.25, sz * 0.22, Math.PI * 1.1, Math.PI * 1.9)
420
+ ctx.stroke()
421
+ // scallion tips sticking out
422
+ ctx.strokeStyle = '#6fcf4a'
423
+ ctx.lineWidth = Math.max(1, sz * 0.06)
424
+ ctx.beginPath()
425
+ for (let i = 0; i < 4; i++) {
426
+ ctx.moveTo(-sz * 0.15 + i * sz * 0.1, sz * 0.4)
427
+ ctx.lineTo(-sz * 0.25 + i * sz * 0.12 + Math.sin(t * 2 + i) * sz * 0.03, sz * 0.05)
428
+ }
429
+ ctx.stroke()
430
+ // bag body
431
+ ctx.beginPath()
432
+ ctx.moveTo(-sz * 0.35, sz * 0.32)
433
+ ctx.lineTo(sz * 0.35, sz * 0.32)
434
+ ctx.quadraticCurveTo(sz * 0.45, sz * 0.95, sz * 0.2, sz * 1.05)
435
+ ctx.lineTo(-sz * 0.2, sz * 1.05)
436
+ ctx.quadraticCurveTo(-sz * 0.45, sz * 0.95, -sz * 0.35, sz * 0.32)
437
+ ctx.closePath()
438
+ ink(ctx, '#d6142f', Math.max(1, sz * 0.03))
439
+ ctx.fillStyle = 'rgba(255,255,255,0.25)'
440
+ ctx.fillRect(-sz * 0.2, sz * 0.45, sz * 0.06, sz * 0.4)
441
+ ctx.restore()
442
+ }
443
+
444
+ export function sMarket(s: SceneCtx) {
445
+ const { ctx, W, H, P, lt, t, u } = s
446
+ const shot = lt < 3 * BAR ? 0 : lt < 5 * BAR ? 1 : 2
447
+ if (shot === 0) {
448
+ // ---- panorama: he rides in slowly, the market drifting past
449
+ const scroll = lt * u * 70
450
+ const groundY = marketStreet(s, scroll, { crowd: false })
451
+ const bs = P ? W * 0.32 : H * 0.26
452
+ const x = lerp(-bs, P ? W * 0.5 : W * 0.4, easeInOutCubic(clamp(lt / (2.6 * BAR))))
453
+ heroRide(ctx, x, groundY + H * 0.06, bs, { facing: 1, t, spin: (lt * u * 90) / (bs * 0.23), light: 1, beam: true, wind: 0.15, eyes: 'open', tuck: 0, rim: rgba(PALETTE.amber, 0.7) })
454
+ crowd(s, scroll, groundY + H * 0.16, P ? H * 0.32 : H * 0.5)
455
+ return
456
+ }
457
+ if (shot === 1) {
458
+ // ---- the 葱姜蒜 stall up close
459
+ const k = lt - 3 * BAR
460
+ const groundY = H * (P ? 0.86 : 0.9)
461
+ vGradient(ctx, 0, 0, W, H, [
462
+ [0, '#120a0c'],
463
+ [1, '#2a160c'],
464
+ ])
465
+ const w = P ? W * 1.1 : H * 1.25
466
+ const sx = P ? W * 0.42 : W * 0.42
467
+ // auntie (drawn by the stall) + counter goods
468
+ stall(ctx, '葱姜蒜', sx, groundY, w, u, t, 0, false)
469
+ const counterY = groundY - w * 0.95 * 0.38
470
+ // auntie hands the bag over the counter; 阿飞 takes it.
471
+ // The hand-off point is solved from both shoulders so both arms really reach it.
472
+ const ah = w * 0.95 * 0.62
473
+ const ax = sx + w * 0.16
474
+ const ay = counterY + ah * 0.45
475
+ const hh = P ? H * 0.46 : H * 0.8
476
+ const hx = sx + w * (P ? 0.5 : 0.52)
477
+ const hy = groundY + hh * 0.02
478
+ const aP = walkPose(ax, ay, ah, 0, { facing: 1, stand: true })
479
+ const hP = walkPose(hx, hy, hh, 0, { facing: -1, stand: true })
480
+ const mid = { x: (aP.sh.x + hP.sh.x) / 2, y: Math.max(aP.sh.y, hP.sh.y) + Math.min(ah, hh) * 0.06 }
481
+ const handOut = smoothstep(BAR * 0.4, BAR * 1.0, k)
482
+ const taken = smoothstep(BAR * 1.15, BAR * 1.35, k)
483
+ const back = smoothstep(BAR * 1.35, BAR * 1.9, k)
484
+ const bagStart = { x: aP.sh.x + ah * 0.12, y: aP.sh.y + ah * 0.22 }
485
+ let bag = { x: lerp(bagStart.x, mid.x, handOut), y: lerp(bagStart.y, mid.y, handOut) }
486
+ const rest = { x: hP.sh.x - hh * 0.1, y: hP.sh.y + hh * 0.26 }
487
+ if (taken > 0.5) bag = { x: lerp(mid.x, rest.x, back), y: lerp(mid.y, rest.y, back) }
488
+ withPalette(AUNTIE, () => {
489
+ heroWalk(ctx, ax, ay, ah, 0, { facing: 1, stand: true, t, eyes: 'open', scarf: '#c4142f', gripN: taken < 0.5 ? bag : undefined })
490
+ })
491
+ // counter front again so she stands behind it
492
+ ctx.beginPath()
493
+ ctx.rect(sx - w * 0.48, counterY, w * 0.96, groundY - counterY)
494
+ ink(ctx, '#3a2414', Math.max(1, u * 2))
495
+ ctx.fillStyle = '#5a3a20'
496
+ ctx.fillRect(sx - w * 0.5, counterY - u * 6, w, u * 8)
497
+ goods(ctx, '葱姜蒜', sx, counterY, w, t, 0)
498
+ priceCard(ctx, sx - w * 0.3, counterY + w * 0.05, w * 0.12, '葱2元', -0.08)
499
+ priceCard(ctx, sx, counterY + w * 0.05, w * 0.12, '姜8��', 0.05)
500
+ priceCard(ctx, sx + w * 0.3, counterY + w * 0.05, w * 0.12, '蒜6元', -0.04)
501
+ // 阿飞 in front of the counter, reaching for the bag
502
+ const reach = handOut > 0.7 || taken > 0.5 ? bag : undefined
503
+ const p = heroWalk(ctx, hx, hy, hh, 0, { facing: -1, stand: true, t, eyes: 'open', gripN: reach })
504
+ const bagPos = reach ? p.handN : bag
505
+ redBag(ctx, bagPos.x, bagPos.y, P ? W * 0.07 : H * 0.075, Math.sin(t * 3) * 0.08, t)
506
+ return
507
+ }
508
+ // ---- riding off through the market with the bag on the bars
509
+ const k = lt - 5 * BAR
510
+ const scroll = (lt + 30) * u * 90
511
+ const groundY = marketStreet(s, scroll, { crowd: false })
512
+ const bs = P ? W * 0.32 : H * 0.26
513
+ const x = lerp(P ? W * 0.45 : W * 0.35, W + bs, smoothstep(BAR * 1.2, s.dur - 5 * BAR, k))
514
+ const by = groundY + H * 0.06
515
+ heroRide(ctx, x, by, bs, { facing: 1, t, spin: (lt * u * 110) / (bs * 0.23), light: 1, beam: true, wind: 0.3, smile: true, eyes: 'open', tuck: 0, rim: rgba(PALETTE.amber, 0.7) })
516
+ const pose = ridePose(x, by, bs, { facing: 1, t, tuck: 0 })
517
+ redBag(ctx, pose.handN.x + u * 4, pose.handN.y + u * 6, bs * 0.16, Math.sin(t * 4.5) * 0.25, t)
518
+ crowd(s, scroll, groundY + H * 0.16, P ? H * 0.32 : H * 0.5)
519
+ void HERO_H
520
+ void capsule
521
+ }
src/mv/engine/timeline.ts CHANGED
@@ -1,6 +1,8 @@
1
  import { BAR, BEAT, BREAK, DROP1, DROP2, DURATION } from './audio'
2
- import { sDrop1, sIgnite, sRooftop, sStreet, sTunnel } from './scenesA'
3
- import { sFinale, sHeartbeat, sHighway, sMarket } from './scenesB'
 
 
4
  import type { SceneFn } from './types'
5
 
6
  export interface SceneDef {
@@ -16,14 +18,14 @@ const b1 = (k: number) => DROP1 + k * BEAT
16
  const b2 = (k: number) => DROP2 + k * BEAT
17
 
18
  export const SCENES: SceneDef[] = [
19
- { id: 'ignite', name: '开场·霓虹与摩托', start: 0, end: b1(-51), fn: sIgnite, color: '#ff2d55' },
20
- { id: 'street', name: '雨夜·推车少年', start: b1(-51), end: b1(-25), fn: sStreet, color: '#3de0ff' },
21
  { id: 'tunnel', name: '蓄力·隧道', start: b1(-25), end: DROP1, fn: sTunnel, color: '#ffb35c' },
22
- { id: 'drop1', name: 'Drop1·霓虹爆裂', start: DROP1, end: DROP1 + 8 * BAR, fn: sDrop1, color: '#ff2d55' },
23
- { id: 'rooftop', name: '山顶·红月', start: DROP1 + 8 * BAR, end: BREAK, fn: sRooftop, color: '#ff7a4a' },
24
  { id: 'market', name: '葱姜蒜夜市', start: BREAK, end: b2(-32), fn: sMarket, color: '#ffb35c' },
25
- { id: 'heart', name: '灯下·烧掉的信', start: b2(-32), end: DROP2, fn: sHeartbeat, color: '#9b1530' },
26
- { id: 'highway', name: 'Drop2·公路之王', start: DROP2, end: DROP2 + 8 * BAR, fn: sHighway, color: '#3de0ff' },
27
  { id: 'finale', name: '终章·星空与火车', start: DROP2 + 8 * BAR, end: DURATION, fn: sFinale, color: '#ff2d55' },
28
  ]
29
 
@@ -64,7 +66,9 @@ export function captionAt(t: number): Caption | null {
64
  /** Hard cuts that get a flash + glitch accent. */
65
  export const CUTS: number[] = (() => {
66
  const cuts = SCENES.slice(1).map((s) => s.start)
67
- for (let k = 1; k < 8; k++) cuts.push(DROP1 + k * BAR)
68
- for (let k = 1; k < 4; k++) cuts.push(DROP2 + k * 2 * BAR)
 
 
69
  return cuts.sort((a, b) => a - b)
70
  })()
 
1
  import { BAR, BEAT, BREAK, DROP1, DROP2, DURATION } from './audio'
2
+ import { sDrop1, sIgnite, sStreet, sTunnel } from './scenesA'
3
+ import { sFinale, sHeartbeat } from './scenesB'
4
+ import { sDuel, sJump } from './scenesCar'
5
+ import { sMarket } from './scenesMarket'
6
  import type { SceneFn } from './types'
7
 
8
  export interface SceneDef {
 
18
  const b2 = (k: number) => DROP2 + k * BEAT
19
 
20
  export const SCENES: SceneDef[] = [
21
+ { id: 'ignite', name: '开场·篝火与摩托', start: 0, end: b1(-51), fn: sIgnite, color: '#ff2d55' },
22
+ { id: 'street', name: '雨夜·骑车穿街', start: b1(-51), end: b1(-25), fn: sStreet, color: '#3de0ff' },
23
  { id: 'tunnel', name: '蓄力·隧道', start: b1(-25), end: DROP1, fn: sTunnel, color: '#ffb35c' },
24
+ { id: 'drop1', name: 'Drop1·霓虹爆裂', start: DROP1, end: b1(10), fn: sDrop1, color: '#ff2d55' },
25
+ { id: 'duel', name: '公路·倒车闪灯', start: b1(10), end: BREAK, fn: sDuel, color: '#ff7a4a' },
26
  { id: 'market', name: '葱姜蒜夜市', start: BREAK, end: b2(-32), fn: sMarket, color: '#ffb35c' },
27
+ { id: 'heart', name: '灯下·烧报纸', start: b2(-32), end: DROP2, fn: sHeartbeat, color: '#9b1530' },
28
+ { id: 'jump', name: 'Drop2·喷射飞越', start: DROP2, end: DROP2 + 8 * BAR, fn: sJump, color: '#3de0ff' },
29
  { id: 'finale', name: '终章·星空与火车', start: DROP2 + 8 * BAR, end: DURATION, fn: sFinale, color: '#ff2d55' },
30
  ]
31
 
 
66
  /** Hard cuts that get a flash + glitch accent. */
67
  export const CUTS: number[] = (() => {
68
  const cuts = SCENES.slice(1).map((s) => s.start)
69
+ cuts.push(b1(4), b1(8))
70
+ const duel = b1(10)
71
+ for (const bar of [1, 2, 5, 6, 8, 10, 11]) cuts.push(duel + bar * BAR)
72
+ for (const bar of [2, 3, 7]) cuts.push(DROP2 + bar * BAR)
73
  return cuts.sort((a, b) => a - b)
74
  })()