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

v3:去掉描述性字幕和场景角标;重画人物与机车,IK 骨骼对位解决穿模

Browse files
README.md CHANGED
@@ -28,7 +28,7 @@ pinned: false
28
  |---|------|----------|
29
  | 1 | 参考 `素材/` 中两个视频的画面风格,做出**原创风格**的《黑街》MV 动画 | 按 2 秒/5 秒间隔抽帧 → 分析色彩、亮度、构图 → 提炼风格关键词 → 全新程序化绘制 |
30
  | 2 | 删除仓库原有代码,**全新**新建项目 | 删除旧的 `Dockerfile`(`FROM kuekhaoyang/kvideo`),新建 Vite + React + TypeScript 项目 |
31
- | 3 | 在网页上直接看到视频效果 | Canvas 2D 绘制场景 + WebGL2 后期(辉光 / 色差 / 胶片颗粒 / 扫描线 / 暗角),与音乐同步播放 |
32
  | 4 | 网页导出 **MP4**(浏览器本地渲染) | WebCodecs `VideoEncoder`(H.264) + `AudioEncoder`(AAC) + `mp4-muxer`,逐帧离线渲染,不依赖服务器 |
33
  | 5 | 适配**手机竖屏** | 横屏 16:9 / 竖屏 9:16 两套构图;所有场景按画布宽高自适应排版;手机端默认竖屏 |
34
  | 6 | 导出帧率 **24 / 30 / 60** 可选 | 在导出面板中单选;第 i 帧的时间 = i / fps,保证和音频严格对齐 |
@@ -81,7 +81,7 @@ pinned: false
81
  - 元素:雨丝、积水倒影、霓虹招牌(中文字)、楼宇剪影、卷帘门、电线杆、雾气、探照灯、车灯光轨
82
  - 主角:~~穿连帽衫的剪影「夜行者」~~ → v2 改为参考视频里的卷发少年「阿飞」和他的黑色摩托(见 2.5)
83
  - 质感:WebGL 后期 → 辉光 + RGB 色差 + 胶片颗粒 + 扫描线 + 暗角,加上底鼓触发的闪白、震屏、故障效果
84
- - 文字:原创动态字幕(不使用歌词原文),中文大字排版跟着节拍弹出
85
 
86
  ### 2.5 主角重绘:卷发少年「阿飞」(v2 新增)
87
 
@@ -101,7 +101,8 @@ pinned: false
101
  | 脸 | 暖米色皮肤,常闭眼、粗眉、略带忧伤;特写可睁眼、浅笑、落泪 |
102
  | 衣服 | 深蓝色长袖毛衣(罗纹领口和下摆),灰色长裤,黑色运动鞋白鞋底 |
103
  | 摩托 | 黑色复古摩托:圆形车头灯(带光束)、两个圆后视镜、水滴油箱、镀铬排气管、辐条轮、红色尾灯 |
104
- | 画法 | 侧面走路(可推车)、背影、侧面骑车、后视角骑车、坐地读信 / 烧信、正面特写,共 6 种画法 |
 
105
 
106
  **校验:** 把渲染出来的画面再交给同一个识别模型描述,得到例如 *"一个穿蓝色上衣、卷发的人骑着黑色摩托,背后是巨大的红色太阳"*、*"一个人坐在摩托旁,手里拿着火光"*、*"头发是蓬松卷发、闭着眼、表情忧伤"*,和参考视频主角的描述一致。
107
 
@@ -215,3 +216,8 @@ npm run dev # 开发
215
  npm run build && npm start # 生产(http://localhost:3000)
216
  ```
217
  - **步骤 7(v2:主角重绘)** ✅ 按要求把参考视频里的主角画出来做新主角:用本地识别模型 Florence-2 描述 87 张截图、定位并分割人物、测量发色 / 肤色 / 衣服颜色和头身比例,新建 `hero.ts` 绘制卷发蓝毛衣少年「阿飞」和他的黑色复古摩托(6 种画法);9 个场景全部改成以他为主角的情节(雨夜推车、隧道骑行、红月山顶特写、灯下读信烧信、货车并行的公路、星空大树与火车);新增「阿飞特写」「灯下烧信」两款封面(每种比例 8 款,共 24 张);文案同步加入主角。再用识别模型回看渲染画面,确认能被描述为「蓝衣卷发少年骑黑色摩托」。全时间轴横竖屏逐 0.5 秒扫描无报错。
 
 
 
 
 
 
28
  |---|------|----------|
29
  | 1 | 参考 `素材/` 中两个视频的画面风格,做出**原创风格**的《黑街》MV 动画 | 按 2 秒/5 秒间隔抽帧 → 分析色彩、亮度、构图 → 提炼风格关键词 → 全新程序化绘制 |
30
  | 2 | 删除仓库原有代码,**全新**新建项目 | 删除旧的 `Dockerfile`(`FROM kuekhaoyang/kvideo`),新建 Vite + React + TypeScript 项目 |
31
+ | 3 | 在网页上直接看到视频效果(画面内无描述性字幕、无场景名角标) | Canvas 2D 绘制场景 + WebGL2 后期(辉光 / 色差 / 胶片颗粒 / 扫描线 / 暗角),与音乐同步播放 |
32
  | 4 | 网页导出 **MP4**(浏览器本地渲染) | WebCodecs `VideoEncoder`(H.264) + `AudioEncoder`(AAC) + `mp4-muxer`,逐帧离线渲染,不依赖服务器 |
33
  | 5 | 适配**手机竖屏** | 横屏 16:9 / 竖屏 9:16 两套构图;所有场景按画布宽高自适应排版;手机端默认竖屏 |
34
  | 6 | 导出帧率 **24 / 30 / 60** 可选 | 在导出面板中单选;第 i 帧的时间 = i / fps,保证和音频严格对齐 |
 
81
  - 元素:雨丝、积水倒影、霓虹招牌(中文字)、楼宇剪影、卷帘门、电线杆、雾气、探照灯、车灯光轨
82
  - 主角:~~穿连帽衫的剪影「夜行者」~~ → v2 改为参考视频里的卷发少年「阿飞」和他的黑色摩托(见 2.5)
83
  - 质感:WebGL 后期 → 辉光 + RGB 色差 + 胶片颗粒 + 扫描线 + 暗角,加上底鼓触发的闪白、震屏、故障效果
84
+ - 文字:~~原创动态字幕~~(v3 已去掉描述性字幕),只保留跟着节拍弹出的大字排版和片头片尾署名
85
 
86
  ### 2.5 主角重绘:卷发少年「阿飞」(v2 新增)
87
 
 
101
  | 脸 | 暖米色皮肤,常闭眼、粗眉、略带忧伤;特写可睁眼、浅笑、落泪 |
102
  | 衣服 | 深蓝色长袖毛衣(罗纹领口和下摆),灰色长裤,黑色运动鞋白鞋底 |
103
  | 摩托 | 黑色复古摩托:圆形车头灯(带光束)、两个圆后视镜、水滴油箱、镀铬排气管、辐条轮、红色尾灯 |
104
+ | 画法 | 侧面走路、推车、背影、侧面骑车、后视角骑车、坐地读信 / 烧信、正面特写,共 7 种画法 |
105
+ | 防穿模(v3) | 机车定义座垫 / 车把 / 脚踏锚点,人物四肢用两段式 IK 解算到锚点上:手一定握在车把上、脚一定踩在脚踏上、臀部落在座垫上;人和车共用一个比例(身高 = 1.4 × 轴距);绘制顺序固定为「远侧手脚 → 机车 → 身体 → 近侧手脚」 |
106
 
107
  **校验:** 把渲染出来的画面再交给同一个识别模型描述,得到例如 *"一个穿蓝色上衣、卷发的人骑着黑色摩托,背后是巨大的红色太阳"*、*"一个人坐在摩托旁,手里拿着火光"*、*"头发是蓬松卷发、闭着眼、表情忧伤"*,和参考视频主角的描述一致。
108
 
 
216
  npm run build && npm start # 生产(http://localhost:3000)
217
  ```
218
  - **步骤 7(v2:主角重绘)** ✅ 按要求把参考视频里的主角画出来做新主角:用本地识别模型 Florence-2 描述 87 张截图、定位并分割人物、测量发色 / 肤色 / 衣服颜色和头身比例,新建 `hero.ts` 绘制卷发蓝毛衣少年「阿飞」和他的黑色复古摩托(6 种画法);9 个场景全部改成以他为主角的情节(雨夜推车、隧道骑行、红月山顶特写、灯下读信烧信、货车并行的公路、星空大树与火车);新增「阿飞特写」「灯下烧信」两款封面(每种比例 8 款,共 24 张);文案同步加入主角。再用识别模型回看渲染画面,确认能被描述为「蓝衣卷发少年骑黑色摩托」。全时间轴横竖屏逐 0.5 秒扫描无报错。
219
+ - **步骤 8(v3:去字幕 + 人物 / 机车精修 + 防穿模)** ✅ 去掉画面里所有描述性字幕(如「凌晨两点,他推着车走在雨里」)和终章「画面|…」说明,去掉播放器左上角的场景名角标;`hero.ts` 重写:
220
+ - 人物:统一骨骼比例,四肢改为带描边的锥形胶囊(卡通线稿感),毛衣加罗纹袖口 / 下摆 / 针织纹理与背光阴影,头部重画侧脸轮廓、耳朵、粗眉、下颌阴影,卷发加描边和每个卷团的高光,鞋子加白色鞋底,脚下加接触阴影;
221
+ - 机车:重画为复古街车——辐条轮 + 镀铬轮圈 + 前刹车盘、摆臂、链条、双减震黄色弹簧、带散热片的气缸和曲轴箱盖、镀铬排气管和消音器、侧盖、带缝线的座垫、亮面水滴油箱(镀铬徽章 + 护膝垫)、前叉防尘套、镀铬灯碗车头灯 + 琥珀色转向灯、仪表、圆后视镜、牌照、侧支架(停车时放下)、地面阴影;后视角加双减震、双消音器和带胎纹的粗后胎;
222
+ - 防穿模:IK 解算,脚本实测手到车把、脚到脚踏的误差均为 0.00,膝盖不进入车轮,推车的每个步态阶段双手都在车把上;
223
+ - 识别模型复查:机车被描述为「黑色摩托、圆形车头灯、两个大圆后视镜、银色轮圈、棕色皮座垫」,人物为「穿蓝衣灰裤、爆炸卷发、表情忧伤的年轻男生」。全时间轴横竖屏逐 0.5 秒扫描无报错。
src/mv/MvApp.tsx CHANGED
@@ -88,10 +88,14 @@ export default function MvApp() {
88
  const s = Math.min(w, h)
89
  if (which === 'walk') H.heroWalk(g, w / 2, h * 0.95, h * 0.9, 0.2, { t: 1 })
90
  if (which === 'back') H.heroBack(g, w / 2, h * 0.95, h * 0.9, 0, { t: 1 })
91
- if (which === 'bike') H.bike(g, w / 2, h * 0.9, s * 0.8, { t: 1 })
92
- if (which === 'ride') H.heroRide(g, w / 2, h * 0.92, s * 0.75, { t: 1, smile: true })
93
- if (which === 'rear') H.heroRideRear(g, w / 2, h * 0.98, h * 0.95, 0, 1)
94
- if (which === 'sit') H.heroSit(g, w / 2, h * 0.95, h * 0.9, 1, { fire: 1 })
 
 
 
 
95
  if (which === 'face') H.heroPortrait(g, w / 2, h * 0.42, h * 0.22, { t: 1, tear: 0.5 })
96
  return c.toDataURL('image/png')
97
  }
@@ -266,9 +270,6 @@ function Player({ ready, orient, setOrient }: { ready: boolean; orient: Orient;
266
  {!started && <span>{ready ? '点击播放(建议戴耳机)' : '加载字体中…'}</span>}
267
  </button>
268
  )}
269
- <div className="mv-scene-tag" style={{ borderColor: scene.color }}>
270
- {scene.name}
271
- </div>
272
  </div>
273
  <div className="mv-controls">
274
  <button className="mv-ctrl" onClick={toggle} aria-label={playing ? '暂停' : '播放'}>
 
88
  const s = Math.min(w, h)
89
  if (which === 'walk') H.heroWalk(g, w / 2, h * 0.95, h * 0.9, 0.2, { t: 1 })
90
  if (which === 'back') H.heroBack(g, w / 2, h * 0.95, h * 0.9, 0, { t: 1 })
91
+ if (which === 'bike') H.bike(g, w / 2, h * 0.85, s * 0.62, { t: 1, parked: true })
92
+ if (which === 'ride') H.heroRide(g, w / 2, h * 0.95, s * 0.6, { t: 1, smile: true, tuck: 0 })
93
+ if (which === 'rear') H.heroRideRear(g, w / 2, h * 0.98, h * 0.9, 0, 1)
94
+ if (which === 'sit') {
95
+ H.bike(g, w * 0.62, h * 0.95, (h * 0.75) / H.HERO_H, { facing: -1, light: 0, parked: true })
96
+ H.heroSit(g, w * 0.36, h * 0.95, h * 0.75, 1, { fire: 0 })
97
+ }
98
+ if (which === 'push') H.heroPush(g, w * 0.5, h * 0.95, (h * 0.85) / H.HERO_H, 0.2, { t: 1, light: 1 })
99
  if (which === 'face') H.heroPortrait(g, w / 2, h * 0.42, h * 0.22, { t: 1, tear: 0.5 })
100
  return c.toDataURL('image/png')
101
  }
 
270
  {!started && <span>{ready ? '点击播放(建议戴耳机)' : '加载字体中…'}</span>}
271
  </button>
272
  )}
 
 
 
273
  </div>
274
  <div className="mv-controls">
275
  <button className="mv-ctrl" onClick={toggle} aria-label={playing ? '暂停' : '播放'}>
src/mv/engine/hero.ts CHANGED
@@ -1,347 +1,473 @@
1
- // 主角「阿飞」— redrawn from the protagonist of the reference footage:
2
  // a young man with a big mop of curly black hair, a deep-blue long-sleeve
3
- // sweater, grey trousers, and his black classic motorcycle (round headlight,
4
- // two round mirrors, red tail light). Mood: quiet, melancholic, eyes often closed.
 
 
 
 
 
 
 
 
5
  import { glowBlob, lightCone } from './draw'
6
- import { hash, rgba } from './util'
7
 
8
  type C2D = CanvasRenderingContext2D
 
 
 
 
9
 
10
  export const HERO = {
11
- skin: '#e6caa2',
12
- skinShade: '#b9997a',
13
  blush: '#e89a86',
14
  hair: '#121411',
15
- hairHi: '#41556b',
16
- sweater: '#2f4b66',
17
- sweaterShade: '#213649',
18
- sweaterHi: '#44698c',
19
- rib: '#273f57',
20
- pants: '#8c9196',
21
- pantsShade: '#646a70',
22
- shoe: '#1b1b1d',
23
- sole: '#dcd6cb',
24
- bike: '#121419',
25
- bikeHi: '#3a4250',
26
- chrome: '#c3cad2',
27
- seat: '#201b18',
28
- tire: '#09090a',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  }
30
 
31
  // ------------------------------------------------------------------ hair
32
- /** Curly mop: a deterministic cluster of curls around the top/back of a head. */
33
- function curls(ctx: C2D, cx: number, cy: number, r: number, facing: number, wind: number, t: number, front = false) {
34
- const n = front ? 30 : 32
35
  const pts: { x: number; y: number; r: number }[] = []
 
36
  for (let i = 0; i < n; i++) {
37
  let a: number
38
- if (front) a = Math.PI * 0.9 + (i / (n - 1)) * Math.PI * 1.2 // left → over the top → right
39
- else a = -Math.PI / 2 - facing * (-0.85 + (i / (n - 1)) * 3.05) // forehead → crown → down to the nape
 
 
40
  const k = 1.02 + 0.14 * hash(i * 3.7)
41
  const wob = Math.sin(t * 9 + i * 1.7) * wind * 0.05
42
- const back = -facing * wind * r * (0.2 + 0.4 * (1 - Math.abs(Math.sin(a))))
 
43
  pts.push({
44
- x: cx + Math.cos(a) * r * k + (front ? 0 : back) + wob * r,
45
- y: cy + Math.sin(a) * r * k * (front ? 0.95 : 1) + wob * r * 0.5,
46
  r: r * (0.34 + 0.16 * hash(i * 1.3)),
47
  })
48
  }
49
- // a second, inner row of curls for volume
50
- const inner = front ? 12 : 10
51
  for (let i = 0; i < inner; i++) {
52
- const a = front ? Math.PI * 1.05 + (i / (inner - 1)) * Math.PI * 0.9 : -Math.PI / 2 - facing * (-0.3 + (i / (inner - 1)) * 1.9)
53
- pts.push({ x: cx + Math.cos(a) * r * 0.62 - (front ? 0 : facing * wind * r * 0.2), y: cy + Math.sin(a) * r * 0.62 - r * 0.05, r: r * (0.3 + 0.12 * hash(i * 7.9)) })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }
 
55
  ctx.fillStyle = HERO.hair
56
  ctx.beginPath()
57
  for (const p of pts) {
58
  ctx.moveTo(p.x + p.r, p.y)
59
  ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
60
  }
61
- // fill the crown (top & back only, the face stays visible)
62
- if (front) {
63
- ctx.moveTo(cx + r * 0.95, cy - r * 0.5)
64
- ctx.ellipse(cx, cy - r * 0.5, r * 0.95, r * 0.5, 0, 0, Math.PI * 2)
65
- } else {
66
- const ccx = cx - facing * r * (0.22 + wind * 0.12)
67
- ctx.moveTo(ccx + r * 0.8, cy - r * 0.3)
68
- ctx.ellipse(ccx, cy - r * 0.3, r * 0.8, r * 0.62, 0, 0, Math.PI * 2)
69
- // back of the skull, down to the nape
70
- const bx = cx - facing * r * (0.45 + wind * 0.15)
71
- ctx.moveTo(bx + r * 0.62, cy + r * 0.1)
72
- ctx.ellipse(bx, cy + r * 0.1, r * 0.62, r * 0.8, 0, 0, Math.PI * 2)
73
- }
74
  ctx.fill()
75
- // curl texture: a highlight crescent on every curl
76
  ctx.strokeStyle = HERO.hairHi
77
  ctx.lineWidth = Math.max(1, r * 0.075)
78
  ctx.lineCap = 'round'
79
  ctx.beginPath()
80
  for (const p of pts) {
81
- const rr = p.r * 0.62
82
- ctx.moveTo(p.x + rr * Math.cos(-2.6), p.y + rr * Math.sin(-2.6))
83
- ctx.arc(p.x, p.y, rr, -2.6, -0.5)
 
84
  }
85
  ctx.stroke()
86
  }
87
 
88
- /** Side-view head with curly hair. facing 1 = looking right. */
89
- export function heroHead(ctx: C2D, cx: number, cy: number, r: number, facing: number, o: { wind?: number; t?: number; eyes?: 'closed' | 'open'; smile?: boolean; rim?: string } = {}) {
 
 
 
 
 
 
 
 
 
 
90
  const t = o.t ?? 0
91
  const wind = o.wind ?? 0
92
- // neck
93
- ctx.fillStyle = HERO.skinShade
94
- ctx.fillRect(cx - r * 0.22, cy + r * 0.7, r * 0.44, r * 0.5)
95
- // face / skull
96
- ctx.fillStyle = HERO.skin
97
- ctx.beginPath()
98
- ctx.ellipse(cx + facing * r * 0.06, cy + r * 0.05, r * 0.86, r * 0.92, 0, 0, Math.PI * 2)
99
- ctx.fill()
100
- // nose & chin profile
 
 
 
 
 
 
 
 
 
 
101
  ctx.beginPath()
102
- ctx.moveTo(cx + facing * r * 0.84, cy - r * 0.02)
103
- ctx.quadraticCurveTo(cx + facing * r * 1.04, cy + r * 0.16, cx + facing * r * 0.84, cy + r * 0.24)
104
- ctx.lineTo(cx + facing * r * 0.7, cy + r * 0.62)
105
- ctx.lineTo(cx + facing * r * 0.3, cy + r * 0.86)
106
- ctx.lineTo(cx, cy + r * 0.5)
107
  ctx.closePath()
108
  ctx.fill()
109
  // ear
110
- ctx.fillStyle = HERO.skinShade
111
  ctx.beginPath()
112
- ctx.ellipse(cx - facing * r * 0.12, cy + r * 0.12, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
113
- ctx.fill()
114
  // eye
115
- ctx.strokeStyle = '#2a1d17'
116
- ctx.lineWidth = Math.max(1, r * 0.07)
 
117
  ctx.lineCap = 'round'
 
 
118
  ctx.beginPath()
119
- const ex = cx + facing * r * 0.5
120
- const ey = cy + r * 0.02
121
  if ((o.eyes ?? 'closed') === 'closed') {
122
- ctx.arc(ex, ey - r * 0.05, r * 0.14, Math.PI * 0.15, Math.PI * 0.85)
 
123
  } else {
124
- ctx.moveTo(ex, ey)
125
- ctx.arc(ex, ey, r * 0.06, 0, Math.PI * 2)
 
 
 
 
126
  }
127
- ctx.stroke()
128
- // sad brow
129
  ctx.beginPath()
130
- ctx.moveTo(ex - facing * r * 0.16, ey - r * 0.2)
131
- ctx.lineTo(ex + facing * r * 0.14, ey - r * 0.26)
132
  ctx.stroke()
133
  // mouth
 
134
  ctx.beginPath()
135
- if (o.smile) ctx.arc(cx + facing * r * 0.62, cy + r * 0.44, r * 0.1, 0.2, Math.PI - 0.2)
136
  else {
137
- ctx.moveTo(cx + facing * r * 0.56, cy + r * 0.5)
138
- ctx.lineTo(cx + facing * r * 0.7, cy + r * 0.48)
139
  }
140
  ctx.stroke()
141
  // blush
142
- ctx.fillStyle = rgba(HERO.blush, 0.35)
143
  ctx.beginPath()
144
- ctx.ellipse(cx + facing * r * 0.4, cy + r * 0.3, r * 0.14, r * 0.08, 0, 0, Math.PI * 2)
145
  ctx.fill()
146
- curls(ctx, cx - facing * r * 0.05, cy - r * 0.12, r, facing, wind, t)
147
  if (o.rim) {
148
  ctx.strokeStyle = o.rim
149
  ctx.lineWidth = Math.max(1, r * 0.08)
150
  ctx.beginPath()
151
- ctx.arc(cx - facing * r * 0.05, cy - r * 0.2, r * 1.18, facing > 0 ? Math.PI * 1.05 : -0.45, facing > 0 ? Math.PI * 1.45 : -0.05)
152
  ctx.stroke()
153
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
- // ------------------------------------------------------------------ walking
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  export interface HeroWalkOpts {
158
  facing?: number
159
  run?: number
160
  rim?: string
161
  t?: number
162
- /** hand reaching forward (e.g. pushing the bike) */
163
- reach?: number
164
  eyes?: 'closed' | 'open'
 
 
 
165
  }
166
 
167
- /** Side-view walking hero. (x,y) = feet on ground, h = total height. */
168
- export function heroWalk(ctx: C2D, x: number, y: number, h: number, phase: number, o: HeroWalkOpts = {}) {
169
  const f = o.facing ?? 1
170
  const run = o.run ?? 0
171
- const t = o.t ?? 0
172
  const P = Math.PI * 2
173
- const bob = Math.abs(Math.sin(phase * P * 2)) * h * (0.012 + run * 0.02)
174
- const hipY = y - h * 0.4 - bob
175
- const lean = 0.04 + run * 0.22
176
- const shX = x + Math.sin(lean) * h * 0.24 * f
177
- const shY = hipY - h * 0.25
178
- const L1 = h * 0.2
179
- const L2 = h * 0.19
180
- ctx.lineCap = 'round'
181
- ctx.lineJoin = 'round'
182
- const leg = (ph: number, col: string, shoe: string) => {
183
  const s = Math.sin(ph * P)
184
- const th = s * (0.42 + run * 0.45)
185
- const knee = Math.max(0, Math.cos(ph * P)) * (0.35 + run * 1.1) + 0.06
186
- const kx = x + Math.sin(th) * L1 * f
187
- const ky = hipY + Math.cos(th) * L1
188
- const sa = th - knee
189
- const fx = kx + Math.sin(sa) * L2 * f
190
- const fy = ky + Math.cos(sa) * L2
191
- ctx.strokeStyle = col
192
- ctx.lineWidth = h * 0.085
193
- ctx.beginPath()
194
- ctx.moveTo(x, hipY)
195
- ctx.lineTo(kx, ky)
196
- ctx.lineTo(fx, fy)
197
- ctx.stroke()
198
- // sneaker
199
- ctx.fillStyle = shoe
200
- ctx.beginPath()
201
- ctx.ellipse(fx + h * 0.03 * f, fy + h * 0.005, h * 0.055, h * 0.026, 0, 0, Math.PI * 2)
202
- ctx.fill()
203
- ctx.fillStyle = HERO.sole
204
- ctx.fillRect(fx - h * 0.02, fy + h * 0.016, h * 0.1 * f, h * 0.012)
205
  }
206
- const arm = (ph: number, col: string, reach = 0) => {
 
 
 
 
207
  const s = Math.sin(ph * P)
208
- const a = reach > 0 ? 1.2 * reach : -s * (0.45 + run * 0.7)
209
- const elbow = reach > 0 ? 0.25 : 0.25 + run * 1.2
210
- const ex = shX + Math.sin(a) * h * 0.14 * f
211
- const ey = shY + h * 0.02 + Math.cos(a) * h * 0.14
212
- const hx = ex + Math.sin(a + elbow) * h * 0.13 * f
213
- const hy = ey + Math.cos(a + elbow) * h * 0.13
214
- ctx.strokeStyle = col
215
- ctx.lineWidth = h * 0.07
216
- ctx.beginPath()
217
- ctx.moveTo(shX, shY + h * 0.02)
218
- ctx.lineTo(ex, ey)
219
- ctx.lineTo(hx, hy)
220
- ctx.stroke()
221
- ctx.fillStyle = HERO.skin
222
- ctx.beginPath()
223
- ctx.arc(hx, hy, h * 0.028, 0, Math.PI * 2)
224
- ctx.fill()
 
 
 
225
  }
226
- leg(phase + 0.5, HERO.pantsShade, HERO.shoe)
227
- arm(phase, HERO.sweaterShade)
228
- // torso (sweater)
229
- ctx.fillStyle = HERO.sweater
230
- ctx.beginPath()
231
- const tw = h * 0.085
232
- ctx.moveTo(x - tw * f, hipY + h * 0.03)
233
- ctx.quadraticCurveTo(x - tw * 1.25 * f, (hipY + shY) / 2, shX - tw * 1.3 * f, shY)
234
- ctx.lineTo(shX + tw * 1.15 * f, shY + h * 0.01)
235
- ctx.quadraticCurveTo(x + tw * 1.35 * f, (hipY + shY) / 2, x + tw * 1.0 * f, hipY + h * 0.035)
236
- ctx.closePath()
237
- ctx.fill()
238
- // ribbed hem
239
- ctx.fillStyle = HERO.rib
240
- ctx.fillRect(Math.min(x - tw * f, x + tw * 1.05 * f), hipY + h * 0.005, tw * 2.05, h * 0.03)
241
- // back shading
242
- ctx.fillStyle = rgba(HERO.sweaterShade, 0.8)
243
- ctx.beginPath()
244
- ctx.moveTo(x - tw * f, hipY + h * 0.03)
245
- ctx.quadraticCurveTo(x - tw * 1.2 * f, (hipY + shY) / 2, shX - tw * 1.05 * f, shY)
246
- ctx.lineTo(shX - tw * 0.6 * f, shY)
247
- ctx.quadraticCurveTo(x - tw * 0.7 * f, (hipY + shY) / 2, x - tw * 0.5 * f, hipY + h * 0.03)
248
- ctx.closePath()
249
- ctx.fill()
250
- leg(phase, HERO.pants, HERO.shoe)
251
- // head
252
- const r = h * 0.13
253
- heroHead(ctx, shX + h * 0.015 * f, shY - r * 1.05, r, f, { t, wind: run * 0.6 + 0.1, eyes: o.eyes ?? 'closed', rim: o.rim })
254
- arm(phase + 0.5, HERO.sweater, o.reach ?? 0)
255
  }
256
 
257
- // ------------------------------------------------------------------ back view
258
- export function heroBack(ctx: C2D, x: number, y: number, h: number, sway = 0, o: { rim?: string; t?: number; wind?: number } = {}) {
259
- const sw = sway * h * 0.02
260
- const t = o.t ?? 0
261
- // legs
262
- ctx.fillStyle = HERO.pantsShade
263
- ctx.fillRect(x - h * 0.085, y - h * 0.4, h * 0.075, h * 0.4)
264
- ctx.fillRect(x + h * 0.01, y - h * 0.4, h * 0.075, h * 0.4)
265
- ctx.fillStyle = HERO.shoe
266
- ctx.fillRect(x - h * 0.095, y - h * 0.03, h * 0.09, h * 0.03)
267
- ctx.fillRect(x + h * 0.005, y - h * 0.03, h * 0.09, h * 0.03)
268
- // sweater
269
- ctx.fillStyle = HERO.sweater
270
- ctx.beginPath()
271
- ctx.moveTo(x - h * 0.14 + sw, y - h * 0.68)
272
- ctx.quadraticCurveTo(x - h * 0.17, y - h * 0.52, x - h * 0.13, y - h * 0.36)
273
- ctx.lineTo(x + h * 0.13, y - h * 0.36)
274
- ctx.quadraticCurveTo(x + h * 0.17, y - h * 0.52, x + h * 0.14 + sw, y - h * 0.68)
275
- ctx.closePath()
276
- ctx.fill()
277
- ctx.fillStyle = HERO.rib
278
- ctx.fillRect(x - h * 0.13, y - h * 0.39, h * 0.26, h * 0.035)
279
- // arms
280
- ctx.fillStyle = HERO.sweaterShade
281
- ctx.fillRect(x - h * 0.19 + sw, y - h * 0.66, h * 0.06, h * 0.3)
282
- ctx.fillRect(x + h * 0.13 + sw, y - h * 0.66, h * 0.06, h * 0.3)
283
- ctx.fillStyle = HERO.skin
284
- ctx.fillRect(x - h * 0.185 + sw, y - h * 0.37, h * 0.05, h * 0.04)
285
- ctx.fillRect(x + h * 0.135 + sw, y - h * 0.37, h * 0.05, h * 0.04)
286
- // neck + head from behind: mostly hair
287
- const r = h * 0.13
288
- const hx = x + sw * 1.2
289
- const hy = y - h * 0.68 - r * 0.95
290
- ctx.fillStyle = HERO.skinShade
291
- ctx.fillRect(hx - r * 0.25, hy + r * 0.6, r * 0.5, r * 0.5)
292
- ctx.beginPath()
293
- ctx.ellipse(hx - r * 0.95, hy + r * 0.15, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
294
- ctx.ellipse(hx + r * 0.95, hy + r * 0.15, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
295
- ctx.fill()
296
- backCurls(ctx, hx, hy, r, o.wind ?? 0, t)
297
- if (o.rim) {
298
- ctx.strokeStyle = o.rim
299
- ctx.lineWidth = Math.max(1, h * 0.008)
300
- ctx.beginPath()
301
- ctx.arc(hx, hy - r * 0.1, r * 1.22, Math.PI * 1.1, Math.PI * 1.9)
302
- ctx.moveTo(x - h * 0.15, y - h * 0.66)
303
- ctx.lineTo(x - h * 0.17, y - h * 0.5)
304
- ctx.moveTo(x + h * 0.15, y - h * 0.66)
305
- ctx.lineTo(x + h * 0.17, y - h * 0.5)
306
- ctx.stroke()
307
- }
308
  }
309
 
310
- function backCurls(ctx: C2D, hx: number, hy: number, r: number, wind: number, t: number) {
311
- const pts: { x: number; y: number; r: number }[] = []
312
- for (let i = 0; i < 28; i++) {
313
- const a = (i / 28) * Math.PI * 2
314
- if (Math.sin(a) > 0.8) continue // keep the nape a little open
315
- const wob = Math.sin(t * 8 + i) * wind * 0.06
316
- pts.push({
317
- x: hx + Math.cos(a) * r * (1.02 + 0.14 * hash(i)) + wob * r,
318
- y: hy - r * 0.05 + Math.sin(a) * r * 0.96 - wind * r * 0.18 * (1 - Math.sin(a)),
319
- r: r * (0.34 + 0.16 * hash(i * 2.3)),
320
- })
321
- }
322
- for (let i = 0; i < 9; i++) {
323
- const a = (i / 9) * Math.PI * 2
324
- pts.push({ x: hx + Math.cos(a) * r * 0.5, y: hy - r * 0.1 + Math.sin(a) * r * 0.5, r: r * 0.32 })
325
- }
326
- ctx.fillStyle = HERO.hair
327
  ctx.beginPath()
328
- ctx.moveTo(hx + r, hy)
329
- ctx.ellipse(hx, hy - r * 0.05, r * 1.0, r * 0.95, 0, 0, Math.PI * 2)
330
- for (const p of pts) {
331
- ctx.moveTo(p.x + p.r, p.y)
332
- ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
333
- }
334
  ctx.fill()
335
- ctx.strokeStyle = HERO.hairHi
336
- ctx.lineWidth = Math.max(1, r * 0.075)
337
- ctx.lineCap = 'round'
338
- ctx.beginPath()
339
- for (const p of pts) {
340
- const rr = p.r * 0.62
341
- ctx.moveTo(p.x + rr * Math.cos(-2.6), p.y + rr * Math.sin(-2.6))
342
- ctx.arc(p.x, p.y, rr, -2.6, -0.5)
343
- }
344
- ctx.stroke()
345
  }
346
 
347
  // ------------------------------------------------------------------ the motorcycle
@@ -351,185 +477,312 @@ export interface BikeOpts {
351
  spin?: number
352
  t?: number
353
  beam?: boolean
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  }
355
 
356
- /** Side-view black classic motorcycle. (x,y) = ground point under the middle, s = scale (≈ wheelbase). */
357
  export function bike(ctx: C2D, x: number, y: number, s: number, o: BikeOpts = {}) {
358
- const f = o.facing ?? 1
359
  ctx.save()
360
  ctx.translate(x, y)
361
- ctx.scale(f, 1)
362
  bikeLocal(ctx, s, o)
363
  ctx.restore()
364
  }
365
 
366
- /** bike drawn at origin facing +x (ground at y=0) */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
368
- const R = s * 0.22
369
  const rx = -s * 0.5
370
  const fx = s * 0.5
371
  const wy = -R
372
  const light = o.light ?? 1
 
373
  const X = (dx: number) => dx * s
374
  const Y = (dy: number) => -dy * s
375
- if (o.beam && light > 0) lightCone(ctx, X(0.58), Y(0.6), s * 3, 0.16, -Math.PI / 2, '#fff1c8', 0.16 * light)
376
- for (const cx of [rx, fx]) {
377
- ctx.fillStyle = HERO.tire
378
- ctx.beginPath()
379
- ctx.arc(cx, wy, R, 0, Math.PI * 2)
380
- ctx.fill()
381
- ctx.fillStyle = '#1c1f24'
382
- ctx.beginPath()
383
- ctx.arc(cx, wy, R * 0.62, 0, Math.PI * 2)
384
- ctx.fill()
385
- // tyre tread highlight
386
- ctx.strokeStyle = 'rgba(120,130,145,0.35)'
387
- ctx.lineWidth = Math.max(1, s * 0.006)
388
- ctx.beginPath()
389
- ctx.arc(cx, wy, R * 0.94, Math.PI * 1.1, Math.PI * 1.6)
390
- ctx.stroke()
391
- ctx.strokeStyle = rgba(HERO.chrome, 0.8)
392
- ctx.lineWidth = Math.max(1, s * 0.006)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  ctx.beginPath()
394
- ctx.arc(cx, wy, R * 0.6, 0, Math.PI * 2)
395
- const sp = o.spin ?? 0
396
- for (let k = 0; k < 12; k++) {
397
- const a = (k / 12) * Math.PI * 2 + sp
398
- ctx.moveTo(cx + Math.cos(a) * R * 0.12, wy + Math.sin(a) * R * 0.12)
399
- ctx.lineTo(cx + Math.cos(a + 0.3) * R * 0.6, wy + Math.sin(a + 0.3) * R * 0.6)
 
 
400
  }
401
  ctx.stroke()
402
- ctx.fillStyle = HERO.chrome
403
- ctx.beginPath()
404
- ctx.arc(cx, wy, R * 0.12, 0, Math.PI * 2)
405
- ctx.fill()
406
  }
407
- ctx.lineCap = 'round'
408
- ctx.lineJoin = 'round'
409
- // frame
410
- ctx.strokeStyle = HERO.bike
411
- ctx.lineWidth = s * 0.05
 
 
 
 
 
 
 
 
 
 
412
  ctx.beginPath()
413
- ctx.moveTo(rx, wy)
414
- ctx.lineTo(X(-0.1), Y(0.28))
415
- ctx.lineTo(X(0.32), Y(0.52))
416
- ctx.moveTo(rx, wy)
417
- ctx.lineTo(X(-0.28), Y(0.5))
418
- ctx.stroke()
419
- // front fork
420
  ctx.strokeStyle = HERO.chrome
421
- ctx.lineWidth = s * 0.034
422
  ctx.beginPath()
423
- ctx.moveTo(fx, wy)
424
- ctx.lineTo(X(0.36), Y(0.66))
 
 
 
425
  ctx.stroke()
426
- // fenders
427
- ctx.strokeStyle = HERO.bike
 
 
 
428
  ctx.lineWidth = s * 0.05
429
  ctx.beginPath()
430
- ctx.arc(fx, wy, R * 1.12, Math.PI * 1.05, Math.PI * 1.75)
 
 
 
 
 
431
  ctx.stroke()
 
 
 
432
  ctx.beginPath()
433
- ctx.arc(rx, wy, R * 1.12, Math.PI * 1.2, Math.PI * 1.9)
 
434
  ctx.stroke()
435
- // engine block (big, chunky) + side cover under the seat
436
- ctx.fillStyle = '#16181d'
437
  ctx.beginPath()
438
- ctx.moveTo(X(-0.16), Y(0.46))
439
- ctx.lineTo(X(0.22), Y(0.48))
440
- ctx.lineTo(X(0.24), Y(0.2))
441
- ctx.lineTo(X(-0.12), Y(0.17))
442
  ctx.closePath()
443
- ctx.fill()
444
- ctx.fillStyle = HERO.bike
445
- ctx.fillRect(X(-0.36), Y(0.47), s * 0.2, s * 0.14)
446
- ctx.fillStyle = '#2a2f38'
 
 
 
 
 
 
447
  ctx.beginPath()
448
- ctx.arc(X(0.03), Y(0.27), s * 0.07, 0, Math.PI * 2)
449
- ctx.fill()
450
- ctx.strokeStyle = HERO.chrome
451
- ctx.lineWidth = Math.max(1, s * 0.01)
452
  ctx.beginPath()
453
- ctx.arc(X(0.03), Y(0.27), s * 0.07, 0, Math.PI * 2)
454
- ctx.stroke()
455
- ctx.strokeStyle = rgba(HERO.chrome, 0.7)
456
- ctx.lineWidth = Math.max(1, s * 0.008)
457
  ctx.beginPath()
458
- for (let k = 0; k < 5; k++) {
459
- ctx.moveTo(X(-0.1), Y(0.4 - k * 0.035))
460
- ctx.lineTo(X(0.16), Y(0.4 - k * 0.035))
461
- }
 
 
 
 
 
 
 
 
 
462
  ctx.stroke()
463
- // exhaust
464
- ctx.strokeStyle = HERO.chrome
465
- ctx.lineWidth = s * 0.045
 
 
 
 
 
 
 
 
 
466
  ctx.beginPath()
467
- ctx.moveTo(X(0.1), Y(0.24))
468
- ctx.quadraticCurveTo(X(-0.05), Y(0.13), X(-0.62), Y(0.2))
469
  ctx.stroke()
470
- // tank (teardrop)
471
- ctx.fillStyle = HERO.bike
472
  ctx.beginPath()
473
- ctx.moveTo(X(-0.1), Y(0.5))
474
- ctx.quadraticCurveTo(X(0.0), Y(0.71), X(0.22), Y(0.68))
475
- ctx.quadraticCurveTo(X(0.4), Y(0.62), X(0.34), Y(0.48))
476
- ctx.quadraticCurveTo(X(0.12), Y(0.42), X(-0.1), Y(0.5))
 
477
  ctx.fill()
478
- ctx.strokeStyle = HERO.bikeHi
479
- ctx.lineWidth = Math.max(1, s * 0.012)
480
  ctx.beginPath()
481
- ctx.moveTo(X(0.0), Y(0.58))
482
- ctx.quadraticCurveTo(X(0.12), Y(0.635), X(0.24), Y(0.6))
483
- ctx.stroke()
484
- // seat
485
- ctx.fillStyle = HERO.seat
 
 
486
  ctx.beginPath()
487
- ctx.moveTo(X(-0.44), Y(0.5))
488
- ctx.quadraticCurveTo(X(-0.3), Y(0.56), X(-0.06), Y(0.53))
489
- ctx.lineTo(X(-0.06), Y(0.48))
490
- ctx.lineTo(X(-0.44), Y(0.46))
491
- ctx.closePath()
492
- ctx.fill()
493
- // rear fender & tail light
494
- ctx.fillStyle = HERO.bike
 
 
495
  ctx.beginPath()
496
- ctx.moveTo(X(-0.44), Y(0.47))
497
- ctx.lineTo(X(-0.66), Y(0.44))
498
- ctx.lineTo(X(-0.64), Y(0.4))
499
- ctx.lineTo(X(-0.42), Y(0.42))
500
- ctx.closePath()
501
- ctx.fill()
502
- ctx.fillStyle = '#ff3a5c'
503
- ctx.fillRect(X(-0.68), Y(0.455), s * 0.04, s * 0.03)
504
- glowBlob(ctx, X(-0.66), Y(0.44), s * 0.12, '#ff2d55', 0.8 * light)
505
- // handlebar, mirrors
506
- ctx.strokeStyle = HERO.chrome
507
- ctx.lineWidth = s * 0.016
508
  ctx.beginPath()
509
- ctx.moveTo(X(0.36), Y(0.66))
510
- ctx.lineTo(X(0.3), Y(0.74))
511
- ctx.lineTo(X(0.22), Y(0.75))
512
- ctx.moveTo(X(0.33), Y(0.7))
513
- ctx.lineTo(X(0.3), Y(0.86))
514
  ctx.stroke()
515
- ctx.fillStyle = HERO.chrome
516
  ctx.beginPath()
517
- ctx.ellipse(X(0.3), Y(0.89), s * 0.035, s * 0.028, 0, 0, Math.PI * 2)
518
- ctx.fill()
519
- ctx.fillStyle = '#5a6a7a'
520
  ctx.beginPath()
521
- ctx.ellipse(X(0.3), Y(0.89), s * 0.024, s * 0.018, 0, 0, Math.PI * 2)
522
  ctx.fill()
523
- // round headlight
524
- ctx.fillStyle = HERO.chrome
525
  ctx.beginPath()
526
- ctx.arc(X(0.44), Y(0.62), s * 0.065, 0, Math.PI * 2)
527
- ctx.fill()
528
- ctx.fillStyle = light > 0.1 ? '#fff6d8' : '#59606a'
529
  ctx.beginPath()
530
- ctx.arc(X(0.455), Y(0.62), s * 0.05, 0, Math.PI * 2)
531
  ctx.fill()
532
- if (light > 0.1) glowBlob(ctx, X(0.47), Y(0.62), s * 0.22, '#fff1c8', 0.9 * light)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
533
  }
534
 
535
  // ------------------------------------------------------------------ riding (side)
@@ -543,236 +796,285 @@ export interface RideOpts {
543
  smile?: boolean
544
  eyes?: 'closed' | 'open'
545
  rim?: string
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  }
547
 
548
- /** Hero riding the bike, side view. (x,y) = ground under bike centre, s = bike scale. */
549
  export function heroRide(ctx: C2D, x: number, y: number, s: number, o: RideOpts = {}) {
550
- ctx.save()
551
- ctx.translate(x, y)
552
- ctx.scale(o.facing ?? 1, 1)
553
- rideLocal(ctx, s, o)
554
- ctx.restore()
 
 
 
 
 
 
 
555
  }
556
 
557
- function rideLocal(ctx: C2D, s: number, o: RideOpts) {
558
- const f = 1
 
 
559
  const t = o.t ?? 0
560
- const x = 0
561
- const y = 0
562
- const X = (dx: number) => dx * s
563
- const Y = (dy: number) => -dy * s
564
- const bounce = Math.sin(t * 13) * s * 0.004
565
- // far arm & leg (shade)
566
- ctx.lineCap = 'round'
567
- ctx.lineJoin = 'round'
568
- ctx.strokeStyle = HERO.pantsShade
569
- ctx.lineWidth = s * 0.075
570
- ctx.beginPath()
571
- ctx.moveTo(X(-0.24), Y(0.55))
572
- ctx.lineTo(X(0.04), Y(0.56))
573
- ctx.lineTo(X(-0.02), Y(0.3))
574
- ctx.stroke()
575
- bikeLocal(ctx, s, { light: o.light, spin: o.spin, beam: o.beam })
576
- // near leg
577
- ctx.strokeStyle = HERO.pants
578
- ctx.lineWidth = s * 0.08
579
- ctx.beginPath()
580
- ctx.moveTo(X(-0.26), Y(0.56) + bounce)
581
- ctx.lineTo(X(0.06), Y(0.58) + bounce)
582
- ctx.lineTo(X(0.0), Y(0.3))
583
- ctx.stroke()
584
- ctx.fillStyle = HERO.shoe
585
- ctx.beginPath()
586
- ctx.ellipse(X(0.03), Y(0.28), s * 0.055, s * 0.026, 0, 0, Math.PI * 2)
587
- ctx.fill()
588
- // torso leaning forward
589
- const hip = { x: X(-0.24), y: Y(0.6) + bounce }
590
- const sh = { x: X(-0.06), y: Y(0.9) + bounce }
591
- ctx.fillStyle = HERO.sweater
592
- ctx.beginPath()
593
- ctx.moveTo(hip.x - s * 0.08 * f, hip.y + s * 0.03)
594
- ctx.quadraticCurveTo(hip.x - s * 0.12 * f, (hip.y + sh.y) / 2, sh.x - s * 0.08 * f, sh.y)
595
- ctx.lineTo(sh.x + s * 0.08 * f, sh.y + s * 0.02)
596
- ctx.quadraticCurveTo(hip.x + s * 0.14 * f, (hip.y + sh.y) / 2 + s * 0.05, hip.x + s * 0.1 * f, hip.y + s * 0.03)
597
- ctx.closePath()
598
- ctx.fill()
599
- ctx.fillStyle = HERO.rib
600
  ctx.beginPath()
601
- ctx.moveTo(hip.x - s * 0.08 * f, hip.y + s * 0.03)
602
- ctx.lineTo(hip.x + s * 0.1 * f, hip.y + s * 0.03)
603
- ctx.lineTo(hip.x + s * 0.1 * f, hip.y - s * 0.0)
604
- ctx.lineTo(hip.x - s * 0.085 * f, hip.y - s * 0.0)
 
605
  ctx.closePath()
606
- ctx.fill()
607
- // head
608
- const r = s * 0.13
609
- heroHead(ctx, sh.x + s * 0.05 * f, sh.y - r * 1.05, r, f, { t, wind: o.wind ?? 0.6, smile: o.smile, eyes: o.eyes ?? 'open', rim: o.rim })
610
- // near arm to handlebar
611
- ctx.strokeStyle = HERO.sweater
612
- ctx.lineWidth = s * 0.065
613
- ctx.beginPath()
614
- ctx.moveTo(sh.x, sh.y + s * 0.03)
615
- ctx.lineTo(X(0.1), Y(0.76) + bounce)
616
- ctx.lineTo(X(0.24), Y(0.75))
617
- ctx.stroke()
618
- ctx.fillStyle = HERO.skin
619
- ctx.beginPath()
620
- ctx.arc(X(0.25), Y(0.75), s * 0.028, 0, Math.PI * 2)
621
- ctx.fill()
 
 
 
 
 
 
622
  }
623
 
624
  // ------------------------------------------------------------------ riding (rear view)
 
625
  export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: number, t: number, wind = 0.8) {
 
626
  ctx.save()
627
  ctx.translate(x, y)
628
  ctx.rotate(lean)
629
- // tire
630
- ctx.fillStyle = HERO.tire
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631
  ctx.beginPath()
632
- ctx.ellipse(0, -s * 0.09, s * 0.07, s * 0.17, 0, 0, Math.PI * 2)
633
- ctx.fill()
634
- // fender + tail
635
- ctx.fillStyle = HERO.bike
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636
  ctx.beginPath()
637
- ctx.moveTo(-s * 0.1, -s * 0.24)
638
- ctx.lineTo(s * 0.1, -s * 0.24)
639
  ctx.lineTo(s * 0.08, -s * 0.36)
640
  ctx.lineTo(-s * 0.08, -s * 0.36)
641
  ctx.closePath()
642
- ctx.fill()
643
- glowBlob(ctx, 0, -s * 0.3, s * 0.14, '#ff2d55', 0.95)
644
- ctx.fillStyle = '#ff6a80'
645
- ctx.fillRect(-s * 0.055, -s * 0.31, s * 0.11, s * 0.03)
646
- ctx.fillStyle = '#e6e2d8'
647
- ctx.fillRect(-s * 0.05, -s * 0.27, s * 0.1, s * 0.035)
648
- // legs to pegs
649
- ctx.fillStyle = HERO.pantsShade
650
- ctx.beginPath()
651
- ctx.moveTo(-s * 0.16, -s * 0.42)
652
- ctx.lineTo(-s * 0.22, -s * 0.2)
653
- ctx.lineTo(-s * 0.15, -s * 0.18)
654
- ctx.lineTo(-s * 0.08, -s * 0.38)
655
- ctx.moveTo(s * 0.16, -s * 0.42)
656
- ctx.lineTo(s * 0.22, -s * 0.2)
657
- ctx.lineTo(s * 0.15, -s * 0.18)
658
- ctx.lineTo(s * 0.08, -s * 0.38)
659
- ctx.fill()
660
- // seat
661
- ctx.fillStyle = HERO.seat
662
- ctx.fillRect(-s * 0.12, -s * 0.42, s * 0.24, s * 0.06)
663
- // sweater torso
664
- ctx.fillStyle = HERO.sweater
665
- ctx.beginPath()
666
- ctx.moveTo(-s * 0.19, -s * 0.44)
667
- ctx.quadraticCurveTo(-s * 0.23, -s * 0.66, -s * 0.12, -s * 0.78)
668
- ctx.lineTo(s * 0.12, -s * 0.78)
669
- ctx.quadraticCurveTo(s * 0.23, -s * 0.66, s * 0.19, -s * 0.44)
670
- ctx.closePath()
671
- ctx.fill()
672
- ctx.fillStyle = HERO.rib
673
- ctx.fillRect(-s * 0.19, -s * 0.47, s * 0.38, s * 0.035)
674
- ctx.fillStyle = rgba(HERO.sweaterShade, 0.8)
675
- ctx.fillRect(-s * 0.02, -s * 0.76, s * 0.04, s * 0.3)
676
- // arms out to bars
677
- ctx.strokeStyle = HERO.sweaterShade
678
- ctx.lineCap = 'round'
679
- ctx.lineWidth = s * 0.055
680
  ctx.beginPath()
681
- ctx.moveTo(-s * 0.16, -s * 0.72)
682
- ctx.lineTo(-s * 0.3, -s * 0.55)
683
- ctx.moveTo(s * 0.16, -s * 0.72)
684
- ctx.lineTo(s * 0.3, -s * 0.55)
685
- ctx.stroke()
686
- ctx.strokeStyle = HERO.chrome
687
- ctx.lineWidth = s * 0.014
688
- ctx.beginPath()
689
- ctx.moveTo(-s * 0.34, -s * 0.56)
690
- ctx.lineTo(s * 0.34, -s * 0.56)
691
- ctx.moveTo(-s * 0.3, -s * 0.56)
692
- ctx.lineTo(-s * 0.33, -s * 0.66)
693
- ctx.moveTo(s * 0.3, -s * 0.56)
694
- ctx.lineTo(s * 0.33, -s * 0.66)
695
- ctx.stroke()
696
- ctx.fillStyle = HERO.chrome
697
  ctx.beginPath()
698
- ctx.ellipse(-s * 0.335, -s * 0.68, s * 0.03, s * 0.024, 0, 0, Math.PI * 2)
699
- ctx.ellipse(s * 0.335, -s * 0.68, s * 0.03, s * 0.024, 0, 0, Math.PI * 2)
700
- ctx.fill()
701
- // neck + hair mop (blown by the wind)
702
- const r = s * 0.11
703
- ctx.fillStyle = HERO.skinShade
704
- ctx.fillRect(-r * 0.25, -s * 0.84, r * 0.5, s * 0.07)
705
- backCurls(ctx, 0, -s * 0.84 - r * 0.8, r, wind, t)
706
  ctx.restore()
707
  }
708
 
709
  // ------------------------------------------------------------------ sitting with the letter
 
710
  export function heroSit(ctx: C2D, x: number, y: number, h: number, t: number, o: { facing?: number; letter?: number; fire?: number } = {}) {
711
  const f = o.facing ?? 1
712
- const X = (dx: number) => x + dx * h * f
713
- const Y = (dy: number) => y - dy * h
714
- ctx.lineCap = 'round'
715
- ctx.lineJoin = 'round'
716
- // legs: knees up
717
- ctx.strokeStyle = HERO.pantsShade
718
- ctx.lineWidth = h * 0.11
719
- ctx.beginPath()
720
- ctx.moveTo(X(-0.05), Y(0.05))
721
- ctx.lineTo(X(0.2), Y(0.3))
722
- ctx.lineTo(X(0.3), Y(0.04))
723
- ctx.stroke()
724
- ctx.strokeStyle = HERO.pants
725
- ctx.beginPath()
726
- ctx.moveTo(X(-0.02), Y(0.06))
727
- ctx.lineTo(X(0.24), Y(0.32))
728
- ctx.lineTo(X(0.36), Y(0.05))
729
- ctx.stroke()
730
- ctx.fillStyle = HERO.shoe
731
- ctx.beginPath()
732
- ctx.ellipse(X(0.4), Y(0.03), h * 0.07, h * 0.035, 0, 0, Math.PI * 2)
733
- ctx.fill()
734
- // torso hunched
735
- ctx.fillStyle = HERO.sweater
736
- ctx.beginPath()
737
- ctx.moveTo(X(-0.14), Y(0.04))
738
- ctx.quadraticCurveTo(X(-0.2), Y(0.3), X(-0.06), Y(0.5))
739
- ctx.lineTo(X(0.1), Y(0.48))
740
- ctx.quadraticCurveTo(X(0.08), Y(0.25), X(0.06), Y(0.06))
741
- ctx.closePath()
742
- ctx.fill()
743
- // head bowed toward the letter
744
- const r = h * 0.15
745
- heroHead(ctx, X(0.06), Y(0.62), r, f, { t, eyes: 'closed', wind: 0.05 })
746
- // arms holding paper
747
- const px = X(0.34)
748
- const py = Y(0.42)
749
- ctx.strokeStyle = HERO.sweater
750
- ctx.lineWidth = h * 0.075
751
- ctx.beginPath()
752
- ctx.moveTo(X(0.0), Y(0.45))
753
- ctx.lineTo(X(0.18), Y(0.33))
754
- ctx.lineTo(px - h * 0.03 * f, py + h * 0.03)
755
- ctx.stroke()
756
  const letter = o.letter ?? 1
 
757
  if (letter > 0) {
758
  ctx.save()
759
- ctx.translate(px, py)
760
- ctx.rotate(-0.25 * f)
761
- ctx.globalAlpha = letter
762
- ctx.fillStyle = '#f1e6cf'
763
- const lw = h * 0.16
764
- const lh = h * 0.2 * letter
765
- ctx.fillRect(-lw / 2, -lh, lw, lh)
 
766
  ctx.fillStyle = 'rgba(80,60,40,0.45)'
767
- for (let k = 0; k < 5; k++) ctx.fillRect(-lw * 0.38, -lh + lh * (0.18 + k * 0.15), lw * 0.76 * (k === 4 ? 0.5 : 1), Math.max(1, h * 0.006))
768
  ctx.restore()
769
  }
770
- ctx.fillStyle = HERO.skin
771
- ctx.beginPath()
772
- ctx.arc(px - h * 0.02 * f, py + h * 0.02, h * 0.03, 0, Math.PI * 2)
773
- ctx.fill()
774
  const fire = o.fire ?? 0
775
- if (fire > 0) flame(ctx, px, py - h * 0.2 * letter, h * 0.18 * fire, t)
776
  }
777
 
778
  export function flame(ctx: C2D, x: number, y: number, size: number, t: number) {
@@ -794,7 +1096,6 @@ export function flame(ctx: C2D, x: number, y: number, size: number, t: number) {
794
  ctx.quadraticCurveTo(x, y + w * 0.6, x - w, y)
795
  ctx.fill()
796
  }
797
- // embers
798
  ctx.fillStyle = '#ffcf7a'
799
  for (let i = 0; i < 10; i++) {
800
  const life = (t * (0.6 + hash(i) * 0.5) + hash(i * 3.3)) % 1
@@ -818,54 +1119,70 @@ export interface PortraitOpts {
818
  export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o: PortraitOpts) {
819
  const r = size
820
  const t = o.t
 
821
  // shoulders / sweater
822
- ctx.fillStyle = HERO.sweater
823
  ctx.beginPath()
824
- ctx.moveTo(cx - r * 2.4, cy + r * 3.2)
825
- ctx.quadraticCurveTo(cx - r * 2.2, cy + r * 1.45, cx - r * 0.5, cy + r * 1.3)
826
- ctx.lineTo(cx + r * 0.5, cy + r * 1.3)
827
- ctx.quadraticCurveTo(cx + r * 2.2, cy + r * 1.45, cx + r * 2.4, cy + r * 3.2)
828
  ctx.closePath()
829
- ctx.fill()
830
  ctx.fillStyle = HERO.sweaterShade
831
  ctx.beginPath()
832
- ctx.moveTo(cx - r * 2.4, cy + r * 3.2)
833
- ctx.quadraticCurveTo(cx - r * 2.2, cy + r * 1.45, cx - r * 1.2, cy + r * 1.35)
834
- ctx.quadraticCurveTo(cx - r * 1.6, cy + r * 2.2, cx - r * 1.5, cy + r * 3.2)
835
  ctx.closePath()
836
  ctx.fill()
837
- // neck + ribbed collar
838
- ctx.fillStyle = HERO.skinShade
839
- ctx.fillRect(cx - r * 0.34, cy + r * 0.7, r * 0.68, r * 0.7)
840
- ctx.strokeStyle = HERO.rib
841
- ctx.lineWidth = r * 0.16
842
  ctx.beginPath()
843
- ctx.ellipse(cx, cy + r * 1.34, r * 0.52, r * 0.16, 0, 0, Math.PI)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
  ctx.stroke()
845
  // back hair volume
 
 
 
 
846
  ctx.fillStyle = HERO.hair
847
  ctx.beginPath()
848
  ctx.ellipse(cx, cy - r * 0.15, r * 1.3, r * 1.18, 0, 0, Math.PI * 2)
849
  ctx.fill()
850
- // face
851
- ctx.fillStyle = HERO.skin
 
 
 
 
 
852
  ctx.beginPath()
853
  ctx.moveTo(cx - r * 0.94, cy - r * 0.2)
854
  ctx.lineTo(cx - r * 0.9, cy + r * 0.5)
855
  ctx.quadraticCurveTo(cx - r * 0.6, cy + r * 0.95, cx, cy + r * 1.0)
856
  ctx.quadraticCurveTo(cx + r * 0.6, cy + r * 0.95, cx + r * 0.9, cy + r * 0.5)
857
  ctx.lineTo(cx + r * 0.94, cy - r * 0.2)
858
- ctx.quadraticCurveTo(cx, cy - r * 1.05, cx - r * 0.92, cy - r * 0.2)
859
- ctx.fill()
860
- // ears
861
- ctx.beginPath()
862
- ctx.ellipse(cx - r * 0.95, cy + r * 0.12, r * 0.15, r * 0.24, 0, 0, Math.PI * 2)
863
- ctx.ellipse(cx + r * 0.95, cy + r * 0.12, r * 0.15, r * 0.24, 0, 0, Math.PI * 2)
864
- ctx.fill()
865
- // cheek shade
866
  ctx.fillStyle = rgba(HERO.skinShade, 0.35)
867
  ctx.beginPath()
868
- ctx.ellipse(cx - r * 0.55, cy + r * 0.55, r * 0.35, r * 0.3, 0.4, 0, Math.PI * 2)
869
  ctx.fill()
870
  ctx.fillStyle = rgba(HERO.blush, 0.16)
871
  ctx.beginPath()
@@ -874,8 +1191,8 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
874
  ctx.fill()
875
  // eyes
876
  const open = o.eyes ?? 0
877
- ctx.strokeStyle = '#2a1d17'
878
- ctx.fillStyle = '#2a1d17'
879
  ctx.lineCap = 'round'
880
  ctx.lineWidth = Math.max(1, r * 0.06)
881
  for (const sd of [-1, 1]) {
@@ -892,9 +1209,8 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
892
  ctx.beginPath()
893
  ctx.arc(ex + r * 0.035, ey - r * 0.04, r * 0.03, 0, Math.PI * 2)
894
  ctx.fill()
895
- ctx.fillStyle = '#2a1d17'
896
  }
897
- // thick, slightly sad brows
898
  ctx.save()
899
  ctx.lineWidth = Math.max(1.5, r * 0.1)
900
  ctx.beginPath()
@@ -903,26 +1219,22 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
903
  ctx.stroke()
904
  ctx.restore()
905
  }
906
- // nose + mouth (slightly open)
907
- ctx.strokeStyle = rgba(HERO.skinShade, 0.9)
 
908
  ctx.beginPath()
909
  ctx.moveTo(cx + r * 0.02, cy + r * 0.25)
910
  ctx.lineTo(cx - r * 0.05, cy + r * 0.42)
911
- ctx.lineTo(cx + r * 0.04, cy + r * 0.44)
912
  ctx.stroke()
913
- ctx.fillStyle = '#7a3a34'
914
  ctx.beginPath()
915
- if (o.smile) {
916
- ctx.strokeStyle = '#7a3a34'
917
- ctx.arc(cx, cy + r * 0.56, r * 0.14, 0.25, Math.PI - 0.25)
918
- ctx.stroke()
919
- } else {
920
- ctx.strokeStyle = '#6a3530'
921
- ctx.lineWidth = Math.max(1, r * 0.05)
922
  ctx.moveTo(cx - r * 0.13, cy + r * 0.66)
923
  ctx.quadraticCurveTo(cx, cy + r * 0.6, cx + r * 0.13, cy + r * 0.66)
924
- ctx.stroke()
925
  }
 
926
  // tear
927
  const tear = o.tear ?? 0
928
  if (tear > 0) {
@@ -938,22 +1250,38 @@ export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o:
938
  ctx.lineTo(cx - r * 0.42, ty)
939
  ctx.stroke()
940
  }
941
- // curly fringe + crown on top
942
- curls(ctx, cx, cy - r * 0.38, r * 1.1, 1, o.wind ?? 0, t, true)
 
 
 
 
 
 
 
 
 
943
  ctx.fillStyle = HERO.hair
944
  ctx.beginPath()
945
- for (let i = 0; i < 7; i++) {
946
- const fx = cx + (i - 3) * r * 0.26
947
- const fy = cy - r * 0.66 + Math.abs(i - 3) * r * 0.06 + Math.sin(t * 2 + i) * r * 0.01
948
- ctx.moveTo(fx + r * 0.2, fy)
949
- ctx.arc(fx, fy, r * (0.2 + 0.05 * hash(i * 9.1)), 0, Math.PI * 2)
950
  }
951
  ctx.fill()
 
 
 
 
 
 
 
 
952
  if (o.rim) {
953
  ctx.strokeStyle = o.rim
954
  ctx.lineWidth = Math.max(1, r * 0.05)
955
  ctx.beginPath()
956
- ctx.arc(cx, cy - r * 0.2, r * 1.42, Math.PI * 1.08, Math.PI * 1.55)
957
  ctx.stroke()
958
  }
 
959
  }
 
1
+ // 主角「阿飞」v3 — redrawn from the protagonist of the reference footage:
2
  // a young man with a big mop of curly black hair, a deep-blue long-sleeve
3
+ // sweater, grey trousers, white-soled sneakers, and his black classic
4
+ // motorcycle (round headlight, two round mirrors, red tail light).
5
+ //
6
+ // v3: everything is built on ONE rig.
7
+ // • The bike exposes anchor points (seat / grip / peg) in its own units.
8
+ // • The rider's limbs are solved with two-bone IK onto those anchors, so
9
+ // hands are always on the grips, feet on the pegs, hips on the seat.
10
+ // • Rider and bike share one scale: standing height h = HERO_H * bike scale s.
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 {
18
+ x: number
19
+ y: number
20
+ }
21
 
22
  export const HERO = {
23
+ skin: '#ecd0a8',
24
+ skinShade: '#c49f7c',
25
  blush: '#e89a86',
26
  hair: '#121411',
27
+ hairHi: '#44596f',
28
+ line: '#08090c',
29
+ sweater: '#2f5072',
30
+ sweaterShade: '#223a54',
31
+ sweaterHi: '#4a74a0',
32
+ rib: '#264262',
33
+ pants: '#8d9298',
34
+ pantsShade: '#666b72',
35
+ shoe: '#1d1d21',
36
+ sole: '#e4ded2',
37
+ bike: '#15171c',
38
+ bikeShade: '#0b0c10',
39
+ bikeHi: '#56606f',
40
+ chrome: '#cfd6de',
41
+ chromeShade: '#7e8894',
42
+ seat: '#221c19',
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) */
49
+ export const RIDE_TOP = 1.5
50
+
51
+ // ------------------------------------------------------------------ geometry helpers
52
+ 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)
60
+ const ang = Math.atan2(dy, dx)
61
+ d = clamp(d, Math.abs(l1 - l2) + 1e-4, l1 + l2 - 1e-4)
62
+ const cosA = (l1 * l1 + d * d - l2 * l2) / (2 * l1 * d)
63
+ const A = Math.acos(clamp(cosA, -1, 1))
64
+ const ja = ang + bend * A
65
+ const j = { x: a.x + Math.cos(ja) * l1, y: a.y + Math.sin(ja) * l1 }
66
+ const ea = Math.atan2(target.y - j.y, target.x - j.x)
67
+ return { j, e: { x: j.x + Math.cos(ea) * l2, y: j.y + Math.sin(ea) * l2 } }
68
+ }
69
+
70
+ /** tapered capsule between two points (limbs) */
71
+ function capsulePath(ctx: C2D, a: V, b: V, ra: number, rb: number) {
72
+ const ang = Math.atan2(b.y - a.y, b.x - a.x)
73
+ const px = Math.cos(ang + Math.PI / 2)
74
+ const py = Math.sin(ang + Math.PI / 2)
75
+ ctx.beginPath()
76
+ ctx.moveTo(a.x + px * ra, a.y + py * ra)
77
+ ctx.lineTo(b.x + px * rb, b.y + py * rb)
78
+ ctx.arc(b.x, b.y, rb, ang + Math.PI / 2, ang - Math.PI / 2, true)
79
+ ctx.lineTo(a.x - px * ra, a.y - py * ra)
80
+ ctx.arc(a.x, a.y, ra, ang - Math.PI / 2, ang + Math.PI / 2, true)
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)
104
  }
105
 
106
  // ------------------------------------------------------------------ hair
107
+ /** Curly mop. local: centre (cx,cy), radius r, facing +1/-1, or front view. */
108
+ function curls(ctx: C2D, cx: number, cy: number, r: number, facing: number, wind: number, t: number, mode: 'side' | 'front' | 'back') {
 
109
  const pts: { x: number; y: number; r: number }[] = []
110
+ const n = mode === 'back' ? 30 : 32
111
  for (let i = 0; i < n; i++) {
112
  let a: number
113
+ if (mode === 'front') a = Math.PI * 0.9 + (i / (n - 1)) * Math.PI * 1.2
114
+ else if (mode === 'back') a = (i / n) * Math.PI * 2
115
+ else a = -Math.PI / 2 - facing * (-0.85 + (i / (n - 1)) * 3.05) // forehead → crown → nape
116
+ if (mode === 'back' && Math.sin(a) > 0.82) continue
117
  const k = 1.02 + 0.14 * hash(i * 3.7)
118
  const wob = Math.sin(t * 9 + i * 1.7) * wind * 0.05
119
+ const blow = mode === 'side' ? -facing * wind * r * (0.2 + 0.4 * (1 - Math.abs(Math.sin(a)))) : mode === 'back' ? 0 : 0
120
+ const lift = mode === 'back' ? -wind * r * 0.18 * (1 - Math.sin(a)) : 0
121
  pts.push({
122
+ x: cx + Math.cos(a) * r * k + blow + wob * r,
123
+ y: cy + Math.sin(a) * r * k * (mode === 'front' ? 0.95 : 1) + wob * r * 0.5 + lift,
124
  r: r * (0.34 + 0.16 * hash(i * 1.3)),
125
  })
126
  }
127
+ const inner = 10
 
128
  for (let i = 0; i < inner; i++) {
129
+ let a: number
130
+ if (mode === 'front') a = Math.PI * 1.05 + (i / (inner - 1)) * Math.PI * 0.9
131
+ else if (mode === 'back') a = (i / inner) * Math.PI * 2
132
+ else a = -Math.PI / 2 - facing * (-0.3 + (i / (inner - 1)) * 1.9)
133
+ pts.push({ x: cx + Math.cos(a) * r * 0.6 - (mode === 'side' ? facing * wind * r * 0.2 : 0), y: cy + Math.sin(a) * r * 0.6 - r * 0.05, r: r * (0.32 + 0.12 * hash(i * 7.9)) })
134
+ }
135
+ const crown = () => {
136
+ if (mode === 'front') {
137
+ ctx.moveTo(cx + r * 0.95, cy - r * 0.5)
138
+ ctx.ellipse(cx, cy - r * 0.5, r * 0.95, r * 0.5, 0, 0, Math.PI * 2)
139
+ } else if (mode === 'back') {
140
+ ctx.moveTo(cx + r, cy)
141
+ ctx.ellipse(cx, cy - r * 0.05, r * 1.0, r * 0.95, 0, 0, Math.PI * 2)
142
+ } else {
143
+ const ccx = cx - facing * r * (0.22 + wind * 0.12)
144
+ ctx.moveTo(ccx + r * 0.8, cy - r * 0.3)
145
+ ctx.ellipse(ccx, cy - r * 0.3, r * 0.8, r * 0.62, 0, 0, Math.PI * 2)
146
+ const bx = cx - facing * r * (0.45 + wind * 0.15)
147
+ ctx.moveTo(bx + r * 0.62, cy + r * 0.1)
148
+ ctx.ellipse(bx, cy + r * 0.1, r * 0.62, r * 0.8, 0, 0, Math.PI * 2)
149
+ }
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)
164
  ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
165
  }
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()
173
  for (const p of pts) {
174
+ const rr = p.r * 0.6
175
+ const a0 = mode === 'side' ? (facing > 0 ? -2.3 : -2.6) : -2.6
176
+ ctx.moveTo(p.x + rr * Math.cos(a0), p.y + rr * Math.sin(a0))
177
+ ctx.arc(p.x, p.y, rr, a0, a0 + 2.0)
178
  }
179
  ctx.stroke()
180
  }
181
 
182
+ // ------------------------------------------------------------------ heads
183
+ export interface HeadOpts {
184
+ wind?: number
185
+ t?: number
186
+ eyes?: 'closed' | 'open'
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. */
193
+ export function heroHead(ctx: C2D, cx: number, cy: number, r: number, facing: number, o: HeadOpts = {}) {
194
  const t = o.t ?? 0
195
  const wind = o.wind ?? 0
196
+ const lw = Math.max(1, r * 0.06)
197
+ ctx.save()
198
+ ctx.translate(cx, cy)
199
+ ctx.rotate((o.tilt ?? 0) * facing)
200
+ ctx.scale(facing, 1)
201
+ // face + profile (local facing +x)
202
+ ctx.beginPath()
203
+ ctx.moveTo(-r * 0.55, -r * 0.7)
204
+ ctx.quadraticCurveTo(r * 0.55, -r * 1.0, r * 0.8, -r * 0.25)
205
+ ctx.quadraticCurveTo(r * 0.86, -r * 0.08, r * 0.98, r * 0.12) // nose
206
+ ctx.quadraticCurveTo(r * 0.92, r * 0.26, r * 0.8, r * 0.28)
207
+ ctx.lineTo(r * 0.78, r * 0.5)
208
+ ctx.quadraticCurveTo(r * 0.72, r * 0.86, r * 0.32, r * 0.9) // chin / jaw
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)
218
+ ctx.quadraticCurveTo(r * 0.0, r * 0.7, -r * 0.3, r * 0.3)
 
 
219
  ctx.closePath()
220
  ctx.fill()
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'
228
+ ctx.lineWidth = Math.max(1, r * 0.075)
229
  ctx.lineCap = 'round'
230
+ const ex = r * 0.5
231
+ const ey = r * 0.02
232
  ctx.beginPath()
 
 
233
  if ((o.eyes ?? 'closed') === 'closed') {
234
+ ctx.arc(ex, ey - r * 0.06, r * 0.15, Math.PI * 0.18, Math.PI * 0.82)
235
+ ctx.stroke()
236
  } else {
237
+ ctx.ellipse(ex, ey, r * 0.075, r * 0.11, 0, 0, Math.PI * 2)
238
+ ctx.fill()
239
+ ctx.fillStyle = '#ffffff'
240
+ ctx.beginPath()
241
+ ctx.arc(ex + r * 0.025, ey - r * 0.04, r * 0.028, 0, Math.PI * 2)
242
+ ctx.fill()
243
  }
244
+ // thick brow
245
+ ctx.lineWidth = Math.max(1.5, r * 0.1)
246
  ctx.beginPath()
247
+ ctx.moveTo(ex - r * 0.17, ey - r * 0.24)
248
+ ctx.lineTo(ex + r * 0.15, ey - r * 0.28)
249
  ctx.stroke()
250
  // mouth
251
+ ctx.lineWidth = Math.max(1, r * 0.06)
252
  ctx.beginPath()
253
+ if (o.smile) ctx.arc(r * 0.6, r * 0.5, r * 0.11, 0.15, Math.PI * 0.75)
254
  else {
255
+ ctx.moveTo(r * 0.55, r * 0.56)
256
+ ctx.lineTo(r * 0.7, r * 0.54)
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)
268
  ctx.beginPath()
269
+ ctx.arc(-r * 0.05, -r * 0.2, r * 1.2, Math.PI * 1.05, Math.PI * 1.5)
270
  ctx.stroke()
271
  }
272
+ ctx.restore()
273
+ }
274
+
275
+ // ------------------------------------------------------------------ body pieces (side view)
276
+ export interface Pose {
277
+ hip: V
278
+ sh: V
279
+ head: V
280
+ headR: number
281
+ kneeN: V
282
+ footN: V
283
+ kneeF: V
284
+ footF: V
285
+ elbowN: V
286
+ handN: V
287
+ elbowF: V
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
295
+ const L = Math.hypot(ux, uy) || 1
296
+ const nx = -uy / L
297
+ const ny = ux / L
298
+ // n points to the "front" when facing +x? make sure:
299
+ const s = nx * f > 0 ? 1 : -1
300
+ const fx = nx * s
301
+ const fy = ny * s
302
+ const wF = h * 0.11
303
+ const wB = h * 0.105
304
+ const p0 = { x: hip.x + fx * wF * 0.9 + (ux / L) * -h * 0.03, y: hip.y + fy * wF * 0.9 + (uy / L) * -h * 0.03 }
305
+ const p1 = { x: sh.x + fx * wF * 0.95, y: sh.y + fy * wF * 0.95 }
306
+ const p2 = { x: sh.x - fx * wB, y: sh.y - fy * wB }
307
+ const p3 = { x: hip.x - fx * wB + (ux / L) * -h * 0.03, y: hip.y - fy * wB + (uy / L) * -h * 0.03 }
308
+ ctx.beginPath()
309
+ ctx.moveTo(p0.x, p0.y)
310
+ ctx.quadraticCurveTo((p0.x + p1.x) / 2 + fx * h * 0.02, (p0.y + p1.y) / 2 + fy * h * 0.02, p1.x, p1.y)
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)
320
+ ctx.lineTo(sh.x - fx * wB * 0.35, sh.y - fy * wB * 0.35)
321
+ ctx.lineTo(hip.x - fx * wB * 0.3, hip.y - fy * wB * 0.3)
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++) {
329
+ const q = k / 4
330
+ const a = lerpV(p0, p1, q)
331
+ const b = lerpV(p3, p2, q)
332
+ ctx.moveTo(a.x - fx * h * 0.02, a.y - fy * h * 0.02)
333
+ ctx.lineTo(lerpV(a, b, 0.55).x, lerpV(a, b, 0.55).y)
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)
349
+ ctx.lineTo(knee.x + h * 0.01 * f, knee.y + h * 0.015)
350
+ ctx.stroke()
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) {
377
+ legPiece(ctx, p.hip, p.kneeF, p.footF, h, f, false, lw)
378
+ armPiece(ctx, p.sh, p.elbowF, p.handF, h, false, lw)
379
+ }
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)
387
+ armPiece(ctx, p.sh, p.elbowN, p.handN, h, true, lw)
388
+ }
389
+
390
+ const LEG1 = 0.21
391
+ const LEG2 = 0.205
392
+ const ARM1 = 0.15
393
+ const ARM2 = 0.14
394
+ const TORSO = 0.25
395
+
396
+ function headFor(sh: V, h: number, f: number, lean: number): { head: V; r: number } {
397
+ const r = h * 0.14
398
+ return { head: { x: sh.x + f * (h * 0.03 + Math.sin(lean) * h * 0.05), y: sh.y - h * 0.035 - r * 0.95 }, r }
399
+ }
400
+
401
+ // ------------------------------------------------------------------ walking / standing
402
  export interface HeroWalkOpts {
403
  facing?: number
404
  run?: number
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 {
 
414
  const f = o.facing ?? 1
415
  const run = o.run ?? 0
 
416
  const P = Math.PI * 2
417
+ const bob = Math.abs(Math.cos(phase * P)) * h * (0.012 + run * 0.02)
418
+ const hip = { x, y: y - h * 0.4 + bob * 0.6 - h * 0.012 }
419
+ const lean = 0.04 + run * 0.25
420
+ const sh = { x: hip.x + f * Math.sin(lean) * h * TORSO, y: hip.y - Math.cos(lean) * h * TORSO }
421
+ const stride = h * (0.13 + run * 0.08)
422
+ const foot = (ph: number): V => {
 
 
 
 
423
  const s = Math.sin(ph * P)
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 => {
432
  const s = Math.sin(ph * P)
433
+ return { x: sh.x + f * s * h * (0.1 + run * 0.08), y: sh.y + h * (0.25 - run * 0.08) }
434
+ }
435
+ const tN = o.gripN ?? handSwing(phase + 0.5)
436
+ const tF = o.gripF ?? handSwing(phase)
437
+ const armN = ik(sh, tN, h * ARM1, h * ARM2, f)
438
+ const armF = ik(sh, tF, h * ARM1, h * ARM2, f)
439
+ const hd = headFor(sh, h, f, lean)
440
+ return {
441
+ hip,
442
+ sh,
443
+ head: hd.head,
444
+ headR: hd.r,
445
+ kneeN: legN.j,
446
+ footN: legN.e,
447
+ kneeF: legF.j,
448
+ footF: legF.e,
449
+ elbowN: armN.j,
450
+ handN: armN.e,
451
+ elbowF: armF.j,
452
+ handF: armF.e,
453
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) {
467
+ ctx.fillStyle = 'rgba(0,0,0,0.45)'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468
  ctx.beginPath()
469
+ ctx.ellipse(x, y + w * 0.03, w, w * 0.12, 0, 0, Math.PI * 2)
 
 
 
 
 
470
  ctx.fill()
 
 
 
 
 
 
 
 
 
 
471
  }
472
 
473
  // ------------------------------------------------------------------ the motorcycle
 
477
  spin?: number
478
  t?: number
479
  beam?: boolean
480
+ /** show the side stand (parked) */
481
+ parked?: boolean
482
+ }
483
+
484
+ /** anchor points of the bike, local units (wheelbase = 1, ground y = 0, facing +x) */
485
+ const ANCHOR = {
486
+ seat: { x: -0.2, y: -0.6 },
487
+ grip: { x: 0.27, y: -0.84 },
488
+ peg: { x: -0.1, y: -0.3 },
489
+ R: 0.23,
490
+ }
491
+
492
+ export function bikeAnchors(x: number, y: number, s: number, facing = 1) {
493
+ const m = (p: V): V => ({ x: x + p.x * s * facing, y: y + p.y * s })
494
+ return { seat: m(ANCHOR.seat), grip: m(ANCHOR.grip), peg: m(ANCHOR.peg) }
495
  }
496
 
 
497
  export function bike(ctx: C2D, x: number, y: number, s: number, o: BikeOpts = {}) {
 
498
  ctx.save()
499
  ctx.translate(x, y)
500
+ ctx.scale(o.facing ?? 1, 1)
501
  bikeLocal(ctx, s, o)
502
  ctx.restore()
503
  }
504
 
505
+ function wheel(ctx: C2D, cx: number, cy: number, R: number, s: number, spin: number, front: boolean, lw: number) {
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)
520
+ ctx.stroke()
521
+ ctx.fillStyle = '#121418'
522
+ ctx.beginPath()
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++) {
530
+ const a = (k / 16) * Math.PI * 2 + spin
531
+ const b = a + (k % 2 ? 0.35 : -0.35)
532
+ ctx.moveTo(cx + Math.cos(a) * R * 0.1, cy + Math.sin(a) * R * 0.1)
533
+ ctx.lineTo(cx + Math.cos(b) * R * 0.66, cy + Math.sin(b) * R * 0.66)
534
+ }
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) */
549
  function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
550
+ const R = s * ANCHOR.R
551
  const rx = -s * 0.5
552
  const fx = s * 0.5
553
  const wy = -R
554
  const light = o.light ?? 1
555
+ const lw = Math.max(1, s * 0.008)
556
  const X = (dx: number) => dx * s
557
  const Y = (dy: number) => -dy * s
558
+ const spin = o.spin ?? 0
559
+ ctx.lineCap = 'round'
560
+ ctx.lineJoin = 'round'
561
+ // ground shadow
562
+ ctx.fillStyle = 'rgba(0,0,0,0.5)'
563
+ ctx.beginPath()
564
+ ctx.ellipse(0, s * 0.01, s * 0.78, s * 0.05, 0, 0, Math.PI * 2)
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)
576
+ ctx.beginPath()
577
+ ctx.moveTo(X(-0.06), Y(0.33))
578
+ ctx.lineTo(rx, wy - R * 0.32)
579
+ ctx.moveTo(X(-0.06), Y(0.27))
580
+ ctx.lineTo(rx, wy + R * 0.32)
581
+ ctx.stroke()
582
+ circle(ctx, { x: rx, y: wy }, R * 0.32, 'rgba(0,0,0,0)', lw)
583
+ // rear shock (spring)
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()
591
+ for (let k = 0; k <= 9; k++) {
592
+ const p = lerpV(a, b, 0.12 + (k / 9) * 0.7)
593
+ const dx = (b.y - a.y) / Math.hypot(b.x - a.x, b.y - a.y)
594
+ const dy = -(b.x - a.x) / Math.hypot(b.x - a.x, b.y - a.y)
595
+ const side = k % 2 ? 1 : -1
596
+ const q = { x: p.x + dx * s * 0.026 * side, y: p.y + dy * s * 0.026 * side }
597
+ if (k === 0) ctx.moveTo(q.x, q.y)
598
+ else ctx.lineTo(q.x, q.y)
599
  }
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))
608
+ ctx.lineTo(X(0.12), Y(0.46))
609
+ ctx.quadraticCurveTo(X(0.22), Y(0.4), X(0.2), Y(0.24))
610
+ ctx.quadraticCurveTo(X(0.05), Y(0.15), X(-0.12), Y(0.2))
611
+ ctx.quadraticCurveTo(X(-0.2), Y(0.3), X(-0.16), Y(0.44))
612
+ ctx.closePath()
613
+ ink(ctx, '#1b1e24', lw)
614
+ ctx.save()
615
+ ctx.translate(X(0.1), Y(0.52))
616
+ ctx.rotate(0.3)
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++) {
624
+ const yy = -s * 0.095 + k * s * 0.028
625
+ ctx.moveTo(-s * 0.085, yy)
626
+ ctx.lineTo(s * 0.085, yy)
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()
647
+ ctx.moveTo(X(-0.26), Y(0.225))
648
+ ctx.lineTo(X(-0.6), Y(0.32))
649
  ctx.stroke()
650
+ circle(ctx, { x: X(-0.64), y: Y(0.3) }, s * 0.03, '#2a2f37', lw)
651
+ // side cover under the seat
652
  ctx.beginPath()
653
+ ctx.moveTo(X(-0.38), Y(0.58))
654
+ ctx.lineTo(X(-0.12), Y(0.6))
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))
663
+ ctx.quadraticCurveTo(X(-0.62), Y(0.62), X(-0.72), Y(0.48))
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)
 
 
671
  ctx.beginPath()
672
+ ctx.ellipse(X(-0.69), Y(0.565), s * 0.035, s * 0.022, 0, 0, Math.PI * 2)
673
+ ink(ctx, '#ff3a5c', lw)
674
+ glowBlob(ctx, X(-0.7), Y(0.565), s * 0.13, '#ff2d55', 0.85 * light)
675
+ // seat
676
  ctx.beginPath()
677
+ ctx.moveTo(X(-0.46), Y(0.6))
678
+ ctx.quadraticCurveTo(X(-0.44), Y(0.67), X(-0.36), Y(0.66))
679
+ ctx.lineTo(X(-0.04), Y(0.64))
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])
687
+ ctx.beginPath()
688
+ ctx.moveTo(X(-0.4), Y(0.62))
689
+ ctx.lineTo(X(-0.04), Y(0.605))
690
  ctx.stroke()
691
+ ctx.setLineDash([])
692
+ // fuel tank — glossy teardrop with chrome badge and knee pad
693
+ ctx.beginPath()
694
+ ctx.moveTo(X(-0.04), Y(0.6))
695
+ ctx.quadraticCurveTo(X(0.02), Y(0.77), X(0.2), Y(0.77))
696
+ ctx.quadraticCurveTo(X(0.36), Y(0.76), X(0.38), Y(0.66))
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))
705
+ ctx.quadraticCurveTo(X(0.18), Y(0.765), X(0.3), Y(0.73))
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)
713
  ctx.fill()
 
 
714
  ctx.beginPath()
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))
735
+ ctx.lineTo(X(0.22), Y(0.81))
736
+ ctx.stroke()
737
+ // speedo
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))
745
+ ctx.quadraticCurveTo(X(0.29), Y(0.95), X(0.31), Y(1.0))
 
 
 
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)
753
  ctx.fill()
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)
761
  ctx.fill()
762
+ ctx.beginPath()
763
+ ctx.ellipse(X(0.4), Y(0.79), s * 0.02, s * 0.014, 0, 0, Math.PI * 2)
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
771
+ /** Hero walking beside (in front of) his bike, both hands on the bars. (x,y) = bike ground point. */
772
+ export function heroPush(ctx: C2D, x: number, y: number, s: number, phase: number, o: { facing?: number; t?: number; rim?: string; spin?: number; light?: number; beam?: boolean; eyes?: 'closed' | 'open' } = {}) {
773
+ const f = o.facing ?? 1
774
+ const h = HERO_H * s
775
+ const A = bikeAnchors(x, y, s, f)
776
+ const lw = Math.max(1, h * 0.007)
777
+ const px = x - f * s * 0.1
778
+ const p = walkPose(px, y, h, phase, { facing: f, gripN: A.grip, gripF: { x: A.grip.x - f * s * 0.02, y: A.grip.y - s * 0.01 } })
779
+ // far arm (to the far grip) is behind the bike
780
+ armPiece(ctx, p.sh, p.elbowF, p.handF, h, false, lw)
781
+ bike(ctx, x, y, s, { facing: f, spin: o.spin, light: o.light, beam: o.beam })
782
+ // body in front of the bike
783
+ contactShadow(ctx, px, y, h * 0.18)
784
+ legPiece(ctx, p.hip, p.kneeF, p.footF, h, f, false, lw)
785
+ drawNear(ctx, p, h, f, lw, { t: o.t, wind: 0.1, eyes: o.eyes ?? 'closed', rim: o.rim })
786
  }
787
 
788
  // ------------------------------------------------------------------ riding (side)
 
796
  smile?: boolean
797
  eyes?: 'closed' | 'open'
798
  rim?: string
799
+ /** 0 = sitting upright (parked), 1 = tucked in (racing) */
800
+ tuck?: number
801
+ }
802
+
803
+ /** Hero riding his bike, side view. (x,y) = ground under bike centre, s = bike scale. */
804
+ export function ridePose(x: number, y: number, s: number, o: RideOpts = {}): Pose {
805
+ const f = o.facing ?? 1
806
+ const t = o.t ?? 0
807
+ const h = HERO_H * s
808
+ const A = bikeAnchors(x, y, s, f)
809
+ const bounce = Math.sin(t * 13) * s * 0.004 * (o.tuck ?? 0.5)
810
+ const hip = { x: A.seat.x, y: A.seat.y - h * 0.035 + bounce }
811
+ // choose torso lean so the hands reach the grips with a relaxed elbow
812
+ const reach = (ARM1 + ARM2) * h * (0.9 - (o.tuck ?? 0.5) * 0.1)
813
+ let best = 0.3
814
+ let err = 1e9
815
+ for (let l = 0.05; l <= 1.2; l += 0.02) {
816
+ const sh = { x: hip.x + f * Math.sin(l) * h * TORSO, y: hip.y - Math.cos(l) * h * TORSO }
817
+ const e = Math.abs(Math.hypot(A.grip.x - sh.x, A.grip.y - sh.y) - reach)
818
+ if (e < err) {
819
+ err = e
820
+ best = l
821
+ }
822
+ }
823
+ const lean = best
824
+ const sh = { x: hip.x + f * Math.sin(lean) * h * TORSO, y: hip.y - Math.cos(lean) * h * TORSO }
825
+ const legN = ik(hip, A.peg, h * LEG1, h * LEG2, -f)
826
+ const pegF = { x: A.peg.x - f * s * 0.02, y: A.peg.y - s * 0.01 }
827
+ const legF = ik(hip, pegF, h * LEG1, h * LEG2, -f)
828
+ const gripF = { x: A.grip.x - f * s * 0.02, y: A.grip.y - s * 0.012 }
829
+ const armN = ik(sh, A.grip, h * ARM1, h * ARM2, f)
830
+ const armF = ik(sh, gripF, h * ARM1, h * ARM2, f)
831
+ const hd = headFor(sh, h, f, lean)
832
+ const p: Pose = {
833
+ hip,
834
+ sh,
835
+ head: hd.head,
836
+ headR: hd.r,
837
+ kneeN: legN.j,
838
+ footN: legN.e,
839
+ kneeF: legF.j,
840
+ footF: legF.e,
841
+ elbowN: armN.j,
842
+ handN: armN.e,
843
+ elbowF: armF.j,
844
+ handF: armF.e,
845
+ }
846
+ return p
847
  }
848
 
 
849
  export function heroRide(ctx: C2D, x: number, y: number, s: number, o: RideOpts = {}) {
850
+ const f = o.facing ?? 1
851
+ const t = o.t ?? 0
852
+ const h = HERO_H * s
853
+ const lw = Math.max(1, h * 0.007)
854
+ const p = ridePose(x, y, s, o)
855
+ const hip = p.hip
856
+ // far limbs behind the bike
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
 
864
+ // ------------------------------------------------------------------ back view (standing)
865
+ export function heroBack(ctx: C2D, x: number, y: number, h: number, sway = 0, o: { rim?: string; t?: number; wind?: number } = {}) {
866
+ const lw = Math.max(1, h * 0.007)
867
+ const sw = sway * h * 0.02
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()
885
+ ctx.moveTo(x - h * 0.14 + sw, y - h * 0.67)
886
+ ctx.quadraticCurveTo(x - h * 0.16, y - h * 0.52, x - h * 0.12, y - h * 0.37)
887
+ ctx.lineTo(x + h * 0.12, y - h * 0.37)
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) {
907
+ ctx.strokeStyle = o.rim
908
+ ctx.lineWidth = Math.max(1, h * 0.008)
909
+ ctx.beginPath()
910
+ ctx.arc(hx, hy - r * 0.1, r * 1.22, Math.PI * 1.1, Math.PI * 1.9)
911
+ ctx.stroke()
912
+ }
913
  }
914
 
915
  // ------------------------------------------------------------------ riding (rear view)
916
+ /** Rear view of hero on the bike. (x,y) = ground under rear tyre, s = overall scale (≈ height of rider+bike). */
917
  export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: number, t: number, wind = 0.8) {
918
+ const lw = Math.max(1, s * 0.006)
919
  ctx.save()
920
  ctx.translate(x, y)
921
  ctx.rotate(lean)
922
+ ctx.lineCap = 'round'
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)
932
+ ctx.lineTo(sd * s * 0.3, -s * 0.71)
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)
940
+ ctx.fill()
941
+ }
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()
958
+ ctx.moveTo(-h * 0.16, -s * 0.47)
959
+ ctx.quadraticCurveTo(-h * 0.19, -s * 0.66, -h * 0.13, -s * 0.8)
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()
994
+ for (let k = 0; k <= 8; k++) {
995
+ const p = lerpV(a, b, 0.1 + (k / 8) * 0.75)
996
+ ctx[k ? 'lineTo' : 'moveTo'](p.x + (k % 2 ? 1 : -1) * s * 0.022, p.y)
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()
1010
+ for (let k = 0; k < 6; k++) {
1011
+ const yy = -s * 0.27 + k * s * 0.045 + ((t * 40) % 1) * s * 0.045
1012
+ ctx.moveTo(-s * 0.05, yy)
1013
+ ctx.lineTo(s * 0.05, yy)
1014
+ }
1015
+ ctx.stroke()
1016
  ctx.beginPath()
1017
+ ctx.moveTo(-s * 0.09, -s * 0.24)
1018
+ ctx.quadraticCurveTo(0, -s * 0.31, s * 0.09, -s * 0.24)
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1026
  ctx.beginPath()
1027
+ ctx.ellipse(0, -s * 0.335, s * 0.045, s * 0.022, 0, 0, Math.PI * 2)
1028
+ ink(ctx, '#ff3a5c', lw)
1029
+ glowBlob(ctx, 0, -s * 0.335, s * 0.16, '#ff2d55', 0.95)
1030
+ for (const sd of [-1, 1]) {
1031
+ ctx.beginPath()
1032
+ ctx.ellipse(sd * s * 0.1, -s * 0.33, s * 0.016, s * 0.012, 0, 0, Math.PI * 2)
1033
+ ink(ctx, '#ffa63a', lw)
1034
+ }
1035
  ctx.restore()
1036
  }
1037
 
1038
  // ------------------------------------------------------------------ sitting with the letter
1039
+ /** Hero sitting on the ground, knees up, holding a letter. h = standing height. */
1040
  export function heroSit(ctx: C2D, x: number, y: number, h: number, t: number, o: { facing?: number; letter?: number; fire?: number } = {}) {
1041
  const f = o.facing ?? 1
1042
+ const lw = Math.max(1, h * 0.007)
1043
+ const hip = { x, y: y - h * 0.07 }
1044
+ const lean = 0.35
1045
+ const sh = { x: hip.x + f * Math.sin(lean) * h * TORSO, y: hip.y - Math.cos(lean) * h * TORSO }
1046
+ const footN = { x: x + f * h * 0.3, y: y - h * 0.012 }
1047
+ const footF = { x: x + f * h * 0.26, y: y - h * 0.02 }
1048
+ const legN = ik(hip, footN, h * LEG1, h * LEG2, -f)
1049
+ const legF = ik(hip, footF, h * LEG1, h * LEG2, -f)
1050
+ const handPt = { x: legN.j.x + f * h * 0.06, y: legN.j.y - h * 0.08 }
1051
+ const armN = ik(sh, handPt, h * ARM1, h * ARM2, f)
1052
+ const armF = ik(sh, { x: handPt.x - f * h * 0.02, y: handPt.y + h * 0.01 }, h * ARM1, h * ARM2, f)
1053
+ const r = h * 0.14
1054
+ const head = { x: sh.x + f * h * 0.07, y: sh.y - h * 0.02 - r * 0.85 }
1055
+ const p: Pose = { hip, sh, head, headR: r, kneeN: legN.j, footN: legN.e, kneeF: legF.j, footF: legF.e, elbowN: armN.j, handN: armN.e, elbowF: armF.j, handF: armF.e }
1056
+ contactShadow(ctx, x + f * h * 0.12, y, h * 0.26)
1057
+ drawFar(ctx, p, h, f, lw)
1058
+ // letter between the hands
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1059
  const letter = o.letter ?? 1
1060
+ const lp = { x: armN.e.x + f * h * 0.01, y: armN.e.y - h * 0.02 }
1061
  if (letter > 0) {
1062
  ctx.save()
1063
+ ctx.translate(lp.x, lp.y)
1064
+ ctx.rotate(-0.2 * f)
1065
+ ctx.globalAlpha = clamp(letter * 1.5)
1066
+ const lwid = h * 0.15
1067
+ const lh = h * 0.19 * letter
1068
+ ctx.beginPath()
1069
+ ctx.rect(-lwid / 2, -lh, lwid, lh)
1070
+ ink(ctx, '#f1e6cf', lw)
1071
  ctx.fillStyle = 'rgba(80,60,40,0.45)'
1072
+ for (let k = 0; k < 5; k++) if (lh * (0.18 + k * 0.15) < lh) ctx.fillRect(-lwid * 0.38, -lh + lh * (0.18 + k * 0.15), lwid * 0.76 * (k === 4 ? 0.5 : 1), Math.max(1, h * 0.005))
1073
  ctx.restore()
1074
  }
1075
+ drawNear(ctx, p, h, f, lw, { t, eyes: 'closed', wind: 0.05, tilt: 0.25 })
 
 
 
1076
  const fire = o.fire ?? 0
1077
+ if (fire > 0) flame(ctx, lp.x, lp.y - h * 0.19 * letter, h * 0.15 * fire, t)
1078
  }
1079
 
1080
  export function flame(ctx: C2D, x: number, y: number, size: number, t: number) {
 
1096
  ctx.quadraticCurveTo(x, y + w * 0.6, x - w, y)
1097
  ctx.fill()
1098
  }
 
1099
  ctx.fillStyle = '#ffcf7a'
1100
  for (let i = 0; i < 10; i++) {
1101
  const life = (t * (0.6 + hash(i) * 0.5) + hash(i * 3.3)) % 1
 
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()
1175
  ctx.moveTo(cx - r * 0.94, cy - r * 0.2)
1176
  ctx.lineTo(cx - r * 0.9, cy + r * 0.5)
1177
  ctx.quadraticCurveTo(cx - r * 0.6, cy + r * 0.95, cx, cy + r * 1.0)
1178
  ctx.quadraticCurveTo(cx + r * 0.6, cy + r * 0.95, cx + r * 0.9, cy + r * 0.5)
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()
 
1191
  ctx.fill()
1192
  // eyes
1193
  const open = o.eyes ?? 0
1194
+ ctx.strokeStyle = '#21160f'
1195
+ ctx.fillStyle = '#21160f'
1196
  ctx.lineCap = 'round'
1197
  ctx.lineWidth = Math.max(1, r * 0.06)
1198
  for (const sd of [-1, 1]) {
 
1209
  ctx.beginPath()
1210
  ctx.arc(ex + r * 0.035, ey - r * 0.04, r * 0.03, 0, Math.PI * 2)
1211
  ctx.fill()
1212
+ ctx.fillStyle = '#21160f'
1213
  }
 
1214
  ctx.save()
1215
  ctx.lineWidth = Math.max(1.5, r * 0.1)
1216
  ctx.beginPath()
 
1219
  ctx.stroke()
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)
1227
  ctx.lineTo(cx - r * 0.05, cy + r * 0.42)
1228
+ ctx.lineTo(cx + r * 0.05, cy + r * 0.44)
1229
  ctx.stroke()
1230
+ ctx.strokeStyle = '#6a3530'
1231
  ctx.beginPath()
1232
+ if (o.smile) ctx.arc(cx, cy + r * 0.56, r * 0.14, 0.25, Math.PI - 0.25)
1233
+ else {
 
 
 
 
 
1234
  ctx.moveTo(cx - r * 0.13, cy + r * 0.66)
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) {
 
1250
  ctx.lineTo(cx - r * 0.42, ty)
1251
  ctx.stroke()
1252
  }
1253
+ // curly fringe + crown
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) {
1275
+ ctx.moveTo(p.x + p.rr * 0.6 * Math.cos(-2.6), p.y + p.rr * 0.6 * Math.sin(-2.6))
1276
+ ctx.arc(p.x, p.y, p.rr * 0.6, -2.6, -0.6)
1277
+ }
1278
+ ctx.stroke()
1279
  if (o.rim) {
1280
  ctx.strokeStyle = o.rim
1281
  ctx.lineWidth = Math.max(1, r * 0.05)
1282
  ctx.beginPath()
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
  }
src/mv/engine/renderer.ts CHANGED
@@ -1,7 +1,6 @@
1
  import { DROP1, DROP2, DURATION, analyse, type AudioFrame } from './audio'
2
- import { caption } from './draw'
3
  import { Post, type PostParams } from './post'
4
- import { CUTS, captionAt, sceneAt } from './timeline'
5
  import type { SceneCtx } from './types'
6
  import { clamp, hash, noise1, smoothstep } from './util'
7
 
@@ -83,8 +82,6 @@ export class Renderer {
83
  ctx.setTransform(1, 0, 0, 1, 0, 0)
84
  ctx.globalAlpha = 1
85
  ctx.shadowBlur = 0
86
- const cap = captionAt(t)
87
- if (cap) caption(ctx, W, H, cap.text, t - cap.start, cap.end - cap.start, s.P)
88
 
89
  const pp = postParams(t, a)
90
  if (this.post) {
 
1
  import { DROP1, DROP2, DURATION, analyse, type AudioFrame } from './audio'
 
2
  import { Post, type PostParams } from './post'
3
+ import { CUTS, sceneAt } from './timeline'
4
  import type { SceneCtx } from './types'
5
  import { clamp, hash, noise1, smoothstep } from './util'
6
 
 
82
  ctx.setTransform(1, 0, 0, 1, 0, 0)
83
  ctx.globalAlpha = 1
84
  ctx.shadowBlur = 0
 
 
85
 
86
  const pp = postParams(t, a)
87
  if (this.post) {
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 { bike, heroPortrait, heroRide, heroRideRear, heroWalk } from './hero'
23
  import {
24
  FONT,
25
  PALETTE,
@@ -133,7 +133,7 @@ export function sIgnite(s: SceneCtx) {
133
  // his black motorcycle, parked in the rain — headlight wakes up with the title
134
  const bs = P ? W * 0.5 : H * 0.34
135
  const headOn = lt > 6.4 ? (lt < 7 ? flicker(lt, 12, 18) : 1) : 0
136
- bike(ctx, P ? W * 0.56 : W * 0.8, groundY, bs, { facing: -1, light: headOn, beam: headOn > 0.5 })
137
  neonSign(ctx, W * (P ? 0.78 : 0.86), H * 0.18, u * 60, u * 170, '旅馆', PALETTE.cyan, lt > 3.8 ? flicker(t, 4, 6) : 0, true)
138
  // ground
139
  resetCam(s)
@@ -256,9 +256,8 @@ export function sStreet(s: SceneCtx) {
256
  }
257
  // 阿飞 pushing his motorcycle through the rain
258
  const phase = (s.a.beatPos / 2) % 1
259
- const bs = wh * 1.05
260
- bike(ctx, wx + bs * 0.62, groundY + u * 2, bs, { facing: 1, light: 0.9, spin: scroll / (bs * 0.21), beam: true })
261
- heroWalk(ctx, wx, groundY + u * 2, wh, fract(phase), { reach: 1, t, rim: rgba(PALETTE.cyan, 0.8), eyes: 'closed' })
262
  // ground
263
  ctx.fillStyle = '#05070a'
264
  ctx.fillRect(-ext, groundY, W + ext * 3, H)
@@ -527,8 +526,8 @@ function runnerShot(s: SceneCtx, variant: number) {
527
  ctx.fillRect(x, gy + hash(i) * u * 40, u * (80 + hash(i * 2) * 200), Math.max(1, u * 3))
528
  }
529
  const facing = variant ? -1 : 1
530
- const bsz = P ? W * 0.62 : H * 0.6
531
- heroRide(ctx, cx, gy + a.kick * u * 6, bsz, { facing, wind: 1, t, spin: t * 30, beam: true, eyes: 'open', rim: variant ? PALETTE.red : PALETTE.cyan })
532
  // vertical type
533
  const vs = P ? W * 0.11 : H * 0.12
534
  const word = variant ? '不回头' : '夜行者'
@@ -725,7 +724,7 @@ export function sRooftop(s: SceneCtx) {
725
  for (let i = -6; i < 30; i++) ctx.fillRect(i * u * 90 + u * 20, ridgeY - u * 36, u * 6, u * 40)
726
  // 阿飞 sitting on the parked bike, looking at the moon
727
  const blink = fract(lt / 3.7) > 0.96 ? 'closed' : 'open'
728
- heroRide(ctx, figX, ridgeY + u * 4, bs, { facing: 1, wind: 0.35 + 0.15 * Math.sin(t), t, light: 0.6, smile: lt > 4, eyes: blink, rim: rgba('#ff7a4a', 0.9) })
729
  resetCam(s)
730
  rain(ctx, W, H, t, { count: Math.floor(200 * area(s)) + 40, speed: H * 1.6, len: u * 50, slant: -0.12, color: '#ffb0b0', alpha: 0.16, width: Math.max(1, u * 1.2) })
731
  if (shotC && a.beatPhase < 0.08 && a.beat % 2 === 0) {
 
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,
 
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)
 
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)
 
526
  ctx.fillRect(x, gy + hash(i) * u * 40, u * (80 + hash(i * 2) * 200), Math.max(1, u * 3))
527
  }
528
  const facing = variant ? -1 : 1
529
+ const bsz = P ? W * 0.5 : H * 0.45
530
+ heroRide(ctx, cx, gy + a.kick * u * 6, bsz, { facing, wind: 1, t, spin: t * 30, beam: true, eyes: 'open', tuck: 1, rim: variant ? PALETTE.red : PALETTE.cyan })
531
  // vertical type
532
  const vs = P ? W * 0.11 : H * 0.12
533
  const word = variant ? '不回头' : '夜行者'
 
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) {
src/mv/engine/scenesB.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
  wetReflection,
17
  } from './draw'
18
  import { camera, resetCam, type SceneCtx } from './types'
19
- import { HERO, bike, flame, heroPortrait, heroRide, heroRideRear, heroSit, heroWalk } from './hero'
20
  import { FONT, PALETTE, clamp, easeInOutCubic, easeOutCubic, easeOutExpo, fbm, fract, hash, hash2, lerp, rgba, smoothstep } from './util'
21
 
22
  const area = (s: SceneCtx) => (s.W * s.H) / (1920 * 1080)
@@ -338,10 +338,12 @@ export function sHeartbeat(s: SceneCtx) {
338
  ctx.restore()
339
  // 阿飞 sits by his motorcycle under the lamp, reading a letter … then burns it
340
  const fh = P ? H * 0.2 : H * 0.3
341
- bike(ctx, lx + fh * 0.95, floorY, fh * 1.25, { facing: -1, light: 0 })
 
 
342
  const burn = smoothstep(9.6, 10.4, lt)
343
  const letter = 1 - smoothstep(10.2, 14.5, lt)
344
- heroSit(ctx, lx - fh * 0.35, floorY, fh, t, { facing: 1, letter, fire: burn * (letter > 0.02 ? 1 : smoothstep(15.5, 14.5, lt)) })
345
  if (burn > 0) {
346
  // warm firelight on the floor
347
  ctx.save()
@@ -649,14 +651,14 @@ function sideShot(s: SceneCtx) {
649
  wetReflection(ctx, s.scratch, W, H, gy, t, 0.35, u * 2)
650
  // 阿飞 on his bike, side view, hair streaming back
651
  const bx = W * 0.5 + Math.sin(lt * 1.3) * u * 20
652
- const bs = P ? W * 0.62 : H * 0.5
653
  const by = gy + a.kick * u * 4
654
  const tg = ctx.createLinearGradient(bx - bs * 2.6, 0, bx - bs * 0.6, 0)
655
  tg.addColorStop(0, 'rgba(255,45,85,0)')
656
  tg.addColorStop(1, 'rgba(255,45,85,0.85)')
657
  ctx.fillStyle = tg
658
  ctx.fillRect(bx - bs * 2.6, by - bs * 0.46, bs * 2, Math.max(2, bs * 0.03))
659
- heroRide(ctx, bx, by, bs, { facing: 1, wind: 1, t, spin: lt * 40, beam: true, eyes: 'open', rim: rgba(PALETTE.cyan, 0.85) })
660
  // horizontal speed lines
661
  ctx.fillStyle = 'rgba(255,255,255,0.18)'
662
  for (let i = 0; i < 30; i++) {
@@ -825,7 +827,7 @@ export function sFinale(s: SceneCtx) {
825
  ctx.globalAlpha = 1
826
  // 阿飞 sitting on his bike under the tree, watching the train
827
  const bs = P ? W * 0.34 : H * 0.24
828
- heroRide(ctx, tx + th * (P ? 0.55 : 0.42), base + u * 2, bs, { facing: 1, wind: 0.25, t, light: 0.5, smile: true, eyes: 'open', rim: rgba('#9ab8ff', 0.6) })
829
  }
830
  // neon bursts on kicks
831
  ctx.save()
@@ -895,9 +897,6 @@ export function sFinale(s: SceneCtx) {
895
  ctx.font = `${fs}px ${FONT.black}`
896
  const y0 = P ? H * 0.72 : H * 0.8
897
  ctx.fillText('音乐 |《黑街》DJ葱姜蒜进行曲 — DJ鐘董', W / 2, y0)
898
- ctx.globalAlpha = cr * 0.7
899
- ctx.font = `${fs * 0.75}px ${FONT.black}`
900
- ctx.fillText('画面 | 原创程序化动画 · 浏览器实时渲染', W / 2, y0 + fs * 1.6)
901
  ctx.restore()
902
  }
903
  rain(ctx, W, H, t, { count: Math.floor(200 * area(s)) + 40, speed: H * 1.6, len: u * 60, slant: 0.1, color: '#a9c2d6', alpha: 0.2, width: Math.max(1, u * 1.3) })
 
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)
 
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()
 
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++) {
 
827
  ctx.globalAlpha = 1
828
  // 阿飞 sitting on his bike under the tree, watching the train
829
  const bs = P ? W * 0.34 : H * 0.24
830
+ heroRide(ctx, tx + th * (P ? 0.55 : 0.42), base + u * 2, bs, { facing: 1, wind: 0.25, t, light: 0.5, smile: true, eyes: 'open', tuck: 0, rim: rgba('#9ab8ff', 0.6) })
831
  }
832
  // neon bursts on kicks
833
  ctx.save()
 
897
  ctx.font = `${fs}px ${FONT.black}`
898
  const y0 = P ? H * 0.72 : H * 0.8
899
  ctx.fillText('音乐 |《黑街》DJ葱姜蒜进行曲 — DJ鐘董', W / 2, y0)
 
 
 
900
  ctx.restore()
901
  }
902
  rain(ctx, W, H, t, { count: Math.floor(200 * area(s)) + 40, speed: H * 1.6, len: u * 60, slant: 0.1, color: '#a9c2d6', alpha: 0.2, width: Math.max(1, u * 1.3) })