One commited on
Commit
1d409ea
·
verified ·
1 Parent(s): f385e6d

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +134 -53
index.html CHANGED
@@ -22,6 +22,7 @@
22
  <script>
23
  (() => {
24
  "use strict";
 
25
  const canvas = document.getElementById("tank");
26
  const ctx = canvas.getContext("2d");
27
  let W = 0, H = 0;
@@ -44,7 +45,7 @@ let sandHeights = [], starfish = null;
44
  class Fish {
45
  constructor() {
46
  this.size = rand(15, 42);
47
- this.speed = rand(0.55, 1.7) * (this.size / 30 + 0.5);
48
  this.x = rand(60, W - 60);
49
  this.y = rand(H * 0.15, H * 0.72);
50
  this.angle = Math.random() < 0.5 ? rand(-0.4, 0.4) : Math.PI + rand(-0.4, 0.4);
@@ -65,6 +66,11 @@ class Fish {
65
 
66
  // Occasionally puffs a tiny cluster of bubbles from its mouth
67
  this.bubbleTimer = rand(4, 16); // seconds until the next bubble puff
 
 
 
 
 
68
  }
69
  update(dt) {
70
  // Behavior state machine — occasionally hover or come to near-rest
@@ -93,7 +99,7 @@ class Fish {
93
  if (this.bubbleTimer <= 0) {
94
  const mx = this.x + Math.cos(this.angle) * this.size * 0.62;
95
  const my = this.y + Math.sin(this.angle) * this.size * 0.62;
96
- const n = 2 + ((Math.random() * 3) | 0); // 2..4 bubbles, a tiny cluster
97
  for (let i = 0; i < n; i++) bubbles.push(new Bubble(false, mx + rand(-3, 3), my + rand(-3, 3)));
98
  this.bubbleTimer = rand(8, 22); // wait a while before the next puff
99
  }
@@ -108,10 +114,10 @@ class Fish {
108
 
109
  let desired = Math.atan2(wy - this.y, wx - this.x);
110
 
111
- // Soft boundary steering: only kicks in near the actual glass, so fish roam
112
- // freely across almost the whole tank (including far left and right)
113
  let pull = 0;
114
- const mX = W * 0.13, mTop = H * 0.10, mBot = H * 0.16;
115
  if (this.x < mX) pull = Math.max(pull, 1 - this.x / mX);
116
  else if (this.x > W - mX) pull = Math.max(pull, 1 - (W - this.x) / mX);
117
  if (this.y < mTop) pull = Math.max(pull, 1 - this.y / mTop);
@@ -123,11 +129,12 @@ class Fish {
123
 
124
  // Floor steering: as a fish nears the sand bed it is steered upward,
125
  // so it skims above the ground line instead of diving under it
 
126
  const floorY = sandAt(this.x) - this.size * 0.35;
127
- const fZone = H * 0.14;
128
  if (this.y > floorY - fZone) {
129
  const fp = Math.min(1, (this.y - (floorY - fZone)) / fZone);
130
- desired = lerpAngle(desired, Math.atan2(H * 0.45 - this.y, W / 2 - this.x), fp * 1.2);
131
  }
132
 
133
  // Limit turn rate so direction changes are smooth and fish-like
@@ -137,6 +144,19 @@ class Fish {
137
  const maxStep = this.maxTurn * dt;
138
  this.angle += Math.max(-maxStep, Math.min(maxStep, d));
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  const sp = this.speed * this.speedFactor * 60 * dt;
141
  this.x += Math.cos(this.angle) * sp;
142
  this.y += Math.sin(this.angle) * sp;
@@ -144,9 +164,10 @@ class Fish {
144
  // NOTE: fish do NOT collide with plants — they plough straight through.
145
  // The seaweed bends out of the way instead (see updatePlants).
146
 
147
- // Hard safety clamp — never below the ground line (sand surface)
148
- this.x = Math.max(20, Math.min(W - 20, this.x));
149
- this.y = Math.max(20, Math.min(sandAt(this.x) - this.size * 0.35, this.y));
 
150
 
151
  // Tail beat follows actual speed — a resting fish barely moves its tail
152
  const effSpeed = this.speed * this.speedFactor;
@@ -156,8 +177,18 @@ class Fish {
156
  c.save();
157
  c.translate(this.x, this.y);
158
  c.rotate(this.angle);
 
 
 
 
 
 
159
  const s = this.size;
160
- const sway = Math.sin(this.phase) * s * 0.28;
 
 
 
 
161
 
162
  // tail fin
163
  c.fillStyle = `hsla(${this.hue},75%,52%,0.92)`;
@@ -169,13 +200,27 @@ class Fish {
169
  c.quadraticCurveTo(-s * 1.0, s * 0.35 + sway, -s * 0.5, 0);
170
  c.fill();
171
 
172
- // body
173
  const g = c.createLinearGradient(0, -s * 0.5, 0, s * 0.5);
174
  g.addColorStop(0, `hsl(${this.hue},82%,64%)`);
175
  g.addColorStop(1, `hsl(${this.hue},70%,44%)`);
176
  c.fillStyle = g;
 
 
 
 
177
  c.beginPath();
178
- c.ellipse(0, 0, s, s * 0.42, 0, 0, Math.PI * 2);
 
 
 
 
 
 
 
 
 
 
179
  c.fill();
180
 
181
  // belly highlight
@@ -184,11 +229,12 @@ class Fish {
184
  c.ellipse(0, s * 0.14, s * 0.82, s * 0.24, 0, 0, Math.PI * 2);
185
  c.fill();
186
 
187
- // dorsal fin
 
188
  c.fillStyle = `hsla(${this.hue},80%,50%,0.9)`;
189
  c.beginPath();
190
- c.moveTo(-s * 0.15, -s * 0.36);
191
- c.quadraticCurveTo(s * 0.05, -s * 0.78, s * 0.38, -s * 0.4);
192
  c.closePath();
193
  c.fill();
194
 
@@ -305,11 +351,15 @@ function buildScene() {
305
  up: rand(10, 26), // how far it curls upward
306
  w: rand(2, 4),
307
  ph: rand(0, Math.PI * 2),
308
- flower: Math.random() < 0.3 ? { // ~30% of branch tips bloom
309
- hue: (Math.random() * 360) | 0, // colourful — full spectrum
310
- r: rand(4.5, 8), // head size
311
- petals: 5 + ((Math.random() * 3) | 0) // 5..7 petals
312
- } : null
 
 
 
 
313
  });
314
  }
315
  seaweeds.push(st);
@@ -328,7 +378,7 @@ function buildScene() {
328
  grass.push({
329
  x: gx + rand(-7, 7),
330
  y: gy,
331
- h: rand(14, 44),
332
  lean: rand(-0.35, 0.35), // base tilt from vertical
333
  phase: rand(0, Math.PI * 2),
334
  speed: rand(1.3, 2.8), // quicker, finer sway than seaweed
@@ -342,7 +392,7 @@ function buildScene() {
342
  const nFish = Math.max(7, Math.floor(W / 130));
343
  for (let i = 0; i < nFish; i++) fishes.push(new Fish());
344
 
345
- for (let i = 0; i < 52; i++) bubbles.push(new Bubble(true)); // doubled for a livelier stream
346
 
347
  for (let i = 0; i < 45; i++) {
348
  motes.push({ x: rand(0, W), y: rand(0, H), r: rand(0.6, 1.8), s: rand(3, 9), p: rand(0, Math.PI * 2) });
@@ -351,7 +401,10 @@ function buildScene() {
351
  for (let i = 0; i < 5; i++) {
352
  rays.push({
353
  x: rand(0, W), w: rand(80, 210), tilt: rand(-0.35, 0.35),
354
- speed: rand(0.06, 0.14) * (Math.random() < 0.5 ? 1 : -1), alpha: rand(0.04, 0.09)
 
 
 
355
  });
356
  }
357
 
@@ -408,39 +461,59 @@ function drawBackground(light) {
408
 
409
  function drawRays(t, light) {
410
  const [rr, rg, rb] = light.ray;
 
411
  for (const r of rays) {
 
412
  const off = Math.sin(t * r.speed * 6 + r.x) * 55;
413
- const x = r.x + off;
414
  const topW = r.w * 0.45, botW = r.w * 1.9;
415
  const shift = r.tilt * H;
416
 
417
- // soft outer beam: bright at the surface, fading down through the water
418
- let grad = ctx.createLinearGradient(0, 0, 0, H);
419
- grad.addColorStop(0, `rgba(${rr},${rg},${rb},${r.alpha})`);
420
- grad.addColorStop(0.55, `rgba(${rr},${rg},${rb},${r.alpha * 0.45})`);
421
- grad.addColorStop(1, `rgba(${rr},${rg},${rb},0)`);
422
- ctx.fillStyle = grad;
423
- ctx.beginPath();
424
- ctx.moveTo(x - topW, -10);
425
- ctx.lineTo(x + topW, -10);
426
- ctx.lineTo(x + shift + botW, H * 0.95);
427
- ctx.lineTo(x + shift - botW, H * 0.95);
428
- ctx.closePath();
429
- ctx.fill();
 
 
 
430
 
431
- // brighter inner core so each beam has a gentle gradient across it
432
- const cTop = topW * 0.42, cBot = botW * 0.42;
433
- grad = ctx.createLinearGradient(0, 0, 0, H);
434
- grad.addColorStop(0, `rgba(${rr},${rg},${rb},${r.alpha * 1.5})`);
435
- grad.addColorStop(0.65, `rgba(${rr},${rg},${rb},0)`);
436
- ctx.fillStyle = grad;
437
- ctx.beginPath();
438
- ctx.moveTo(x - cTop, -10);
439
- ctx.lineTo(x + cTop, -10);
440
- ctx.lineTo(x + shift + cBot, H * 0.95);
441
- ctx.lineTo(x + shift - cBot, H * 0.95);
442
- ctx.closePath();
443
- ctx.fill();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  }
445
  }
446
 
@@ -618,8 +691,16 @@ function drawSeaweed() {
618
  ctx.quadraticCurveTo((a.x + b.tx) / 2 + b.side * 3, (a.y + b.ty) / 2 - 5, b.tx, b.ty);
619
  ctx.stroke();
620
 
621
- // colourful flower head blooming at the branch tip
622
- if (b.flower) drawFlowerHead(b.tx, b.ty, b.flower);
 
 
 
 
 
 
 
 
623
  }
624
  }
625
  }
 
22
  <script>
23
  (() => {
24
  "use strict";
25
+ // ============ Aquarium v2 — undulating god rays (light refracting through moving water) ============
26
  const canvas = document.getElementById("tank");
27
  const ctx = canvas.getContext("2d");
28
  let W = 0, H = 0;
 
45
  class Fish {
46
  constructor() {
47
  this.size = rand(15, 42);
48
+ this.speed = rand(0.55, 1.7) * (this.size / 30 + 0.5) * 0.75; // v3: max speed reduced 25%
49
  this.x = rand(60, W - 60);
50
  this.y = rand(H * 0.15, H * 0.72);
51
  this.angle = Math.random() < 0.5 ? rand(-0.4, 0.4) : Math.PI + rand(-0.4, 0.4);
 
66
 
67
  // Occasionally puffs a tiny cluster of bubbles from its mouth
68
  this.bubbleTimer = rand(4, 16); // seconds until the next bubble puff
69
+
70
+ // Body roll — banks/rolls through sharp turns like a real fish (spring-damper)
71
+ this.roll = 0; // current roll angle (rad); 0 = upright
72
+ this.rollVel = 0; // angular velocity of the roll
73
+ this.inHardTurn = false;// was it in a sharp turn last frame?
74
  }
75
  update(dt) {
76
  // Behavior state machine — occasionally hover or come to near-rest
 
99
  if (this.bubbleTimer <= 0) {
100
  const mx = this.x + Math.cos(this.angle) * this.size * 0.62;
101
  const my = this.y + Math.sin(this.angle) * this.size * 0.62;
102
+ const n = (2 + ((Math.random() * 3) | 0)) * 2; // 4..8 bubbles — doubled from the old 2..4
103
  for (let i = 0; i < n; i++) bubbles.push(new Bubble(false, mx + rand(-3, 3), my + rand(-3, 3)));
104
  this.bubbleTimer = rand(8, 22); // wait a while before the next puff
105
  }
 
114
 
115
  let desired = Math.atan2(wy - this.y, wx - this.x);
116
 
117
+ // Soft boundary steering: kicks in a bit before the glass so fish turn
118
+ // gently instead of bonking (v4), roaming freely across the whole tank
119
  let pull = 0;
120
+ const mX = W * 0.16, mTop = H * 0.14, mBot = H * 0.16;
121
  if (this.x < mX) pull = Math.max(pull, 1 - this.x / mX);
122
  else if (this.x > W - mX) pull = Math.max(pull, 1 - (W - this.x) / mX);
123
  if (this.y < mTop) pull = Math.max(pull, 1 - this.y / mTop);
 
129
 
130
  // Floor steering: as a fish nears the sand bed it is steered upward,
131
  // so it skims above the ground line instead of diving under it
132
+ // (v4: starts earlier and pushes harder — grass yes, faceplants no)
133
  const floorY = sandAt(this.x) - this.size * 0.35;
134
+ const fZone = H * 0.18;
135
  if (this.y > floorY - fZone) {
136
  const fp = Math.min(1, (this.y - (floorY - fZone)) / fZone);
137
+ desired = lerpAngle(desired, Math.atan2(H * 0.45 - this.y, W / 2 - this.x), fp * 1.6);
138
  }
139
 
140
  // Limit turn rate so direction changes are smooth and fish-like
 
144
  const maxStep = this.maxTurn * dt;
145
  this.angle += Math.max(-maxStep, Math.min(maxStep, d));
146
 
147
+ // Fish roll their bodies when banking through sharp turns: the moment a big
148
+ // heading change begins, sometimes excite a roll (banking into the turn),
149
+ // then let a spring-damper wobble it back upright.
150
+ const hardTurn = Math.abs(d) > 1.2;
151
+ if (hardTurn && !this.inHardTurn && this.speedFactor > 0.35 && Math.random() < 0.55) {
152
+ this.rollVel += Math.sign(d) * rand(3.8, 5.5); // bank into the turn
153
+ }
154
+ this.inHardTurn = hardTurn;
155
+ this.rollVel += (-8 * this.roll - 2.4 * this.rollVel) * dt;
156
+ this.roll += this.rollVel * dt;
157
+ if (this.roll > 1.15) { this.roll = 1.15; this.rollVel *= -0.25; }
158
+ else if (this.roll < -1.15) { this.roll = -1.15; this.rollVel *= -0.25; }
159
+
160
  const sp = this.speed * this.speedFactor * 60 * dt;
161
  this.x += Math.cos(this.angle) * sp;
162
  this.y += Math.sin(this.angle) * sp;
 
164
  // NOTE: fish do NOT collide with plants — they plough straight through.
165
  // The seaweed bends out of the way instead (see updatePlants).
166
 
167
+ // Hard safety clamp — fish may just about swim off-screen (they never
168
+ // despawn or leave), but never below the ground line (sand surface)
169
+ this.x = Math.max(-40, Math.min(W + 40, this.x));
170
+ this.y = Math.max(-50, Math.min(sandAt(this.x) - this.size * 0.35, this.y));
171
 
172
  // Tail beat follows actual speed — a resting fish barely moves its tail
173
  const effSpeed = this.speed * this.speedFactor;
 
177
  c.save();
178
  c.translate(this.x, this.y);
179
  c.rotate(this.angle);
180
+ // body roll from banking into sharp turns: squash vertically as it rolls,
181
+ // plus a tiny wobble so the motion reads as a real roll, not a glitch
182
+ if (Math.abs(this.roll) > 0.01) {
183
+ c.scale(1, Math.max(0.42, Math.cos(this.roll)));
184
+ c.rotate(this.roll * 0.1);
185
+ }
186
  const s = this.size;
187
+ // traveling body wave (v3): ripples head→tail so the fish undulates like a real one
188
+ const waveK = Math.PI / s; // ~one wavelength across the body length
189
+ const waveAmp = s * 0.12; // subtle flex amplitude
190
+ // tail fin follows the body wave at its base, amplified (same phase → no fighting)
191
+ const sway = Math.sin(-s * waveK + this.phase) * s * 0.34;
192
 
193
  // tail fin
194
  c.fillStyle = `hsla(${this.hue},75%,52%,0.92)`;
 
200
  c.quadraticCurveTo(-s * 1.0, s * 0.35 + sway, -s * 0.5, 0);
201
  c.fill();
202
 
203
+ // body — undulates while swimming: the ellipse flexes along a traveling wave (v3)
204
  const g = c.createLinearGradient(0, -s * 0.5, 0, s * 0.5);
205
  g.addColorStop(0, `hsl(${this.hue},82%,64%)`);
206
  g.addColorStop(1, `hsl(${this.hue},70%,44%)`);
207
  c.fillStyle = g;
208
+ const NSEG = 26; // outline samples for a smooth curve
209
+ // wave offset at any x along the body: rigid at head, full flex at tail.
210
+ // Shared with the dorsal fin so it stays glued to the moving back (v4)
211
+ const wy = x => Math.sin(x * waveK + this.phase) * waveAmp * ((s - x) / (2 * s));
212
  c.beginPath();
213
+ for (let i = 0; i <= NSEG; i++) { // top edge: head (+s) -> tail (-s)
214
+ const x = s - (i / NSEG) * 2 * s;
215
+ const hh = s * 0.42 * Math.sqrt(Math.max(0, 1 - (x / s) ** 2));
216
+ if (i === 0) c.moveTo(x, -hh + wy(x)); else c.lineTo(x, -hh + wy(x));
217
+ }
218
+ for (let i = NSEG; i >= 0; i--) { // bottom edge: tail (-s) -> head (+s)
219
+ const x = s - (i / NSEG) * 2 * s;
220
+ const hh = s * 0.42 * Math.sqrt(Math.max(0, 1 - (x / s) ** 2));
221
+ c.lineTo(x, hh + wy(x));
222
+ }
223
+ c.closePath();
224
  c.fill();
225
 
226
  // belly highlight
 
229
  c.ellipse(0, s * 0.14, s * 0.82, s * 0.24, 0, 0, Math.PI * 2);
230
  c.fill();
231
 
232
+ // dorsal fin — rides the body wave at its attachment points so it
233
+ // never disconnects as the back undulates (v4)
234
  c.fillStyle = `hsla(${this.hue},80%,50%,0.9)`;
235
  c.beginPath();
236
+ c.moveTo(-s * 0.15, -s * 0.36 + wy(-s * 0.15));
237
+ c.quadraticCurveTo(s * 0.05, -s * 0.78 + wy(s * 0.05), s * 0.38, -s * 0.4 + wy(s * 0.38));
238
  c.closePath();
239
  c.fill();
240
 
 
351
  up: rand(10, 26), // how far it curls upward
352
  w: rand(2, 4),
353
  ph: rand(0, Math.PI * 2),
354
+ flowers: Math.random() < 0.3 ? (() => { // ~30% of branches bloom with 1-3 heads (v3)
355
+ const n = 1 + ((Math.random() * 3) | 0); // 1..3 flowers per branch
356
+ return Array.from({ length: n }, () => ({
357
+ t: rand(0.45, 1), // where along the branch it sits (tip zone)
358
+ hue: (Math.random() * 360) | 0, // colourful — full spectrum
359
+ r: rand(4, 7), // head size
360
+ petals: 5 + ((Math.random() * 3) | 0) // 5..7 petals
361
+ }));
362
+ })() : []
363
  });
364
  }
365
  seaweeds.push(st);
 
378
  grass.push({
379
  x: gx + rand(-7, 7),
380
  y: gy,
381
+ h: rand(14, 70), // v3: taller grass blades allowed (seaweed unchanged)
382
  lean: rand(-0.35, 0.35), // base tilt from vertical
383
  phase: rand(0, Math.PI * 2),
384
  speed: rand(1.3, 2.8), // quicker, finer sway than seaweed
 
392
  const nFish = Math.max(7, Math.floor(W / 130));
393
  for (let i = 0; i < nFish; i++) fishes.push(new Fish());
394
 
395
+ for (let i = 0; i < 26; i++) bubbles.push(new Bubble(true)); // halved back to the original stream
396
 
397
  for (let i = 0; i < 45; i++) {
398
  motes.push({ x: rand(0, W), y: rand(0, H), r: rand(0.6, 1.8), s: rand(3, 9), p: rand(0, Math.PI * 2) });
 
401
  for (let i = 0; i < 5; i++) {
402
  rays.push({
403
  x: rand(0, W), w: rand(80, 210), tilt: rand(-0.35, 0.35),
404
+ speed: rand(0.06, 0.14) * (Math.random() < 0.5 ? 1 : -1), alpha: rand(0.04, 0.09),
405
+ // undulation — two traveling waves so each beam shimmers like light refracted through moving water
406
+ uAmp: rand(18, 46), uLen: rand(2.2, 4.5), uSpd: rand(0.35, 0.9) * (Math.random() < 0.5 ? 1 : -1), uPh: rand(0, Math.PI * 2),
407
+ vAmp: rand(6, 14), vLen: rand(5, 9), vSpd: rand(0.8, 1.6) * (Math.random() < 0.5 ? 1 : -1), vPh: rand(0, Math.PI * 2)
408
  });
409
  }
410
 
 
461
 
462
  function drawRays(t, light) {
463
  const [rr, rg, rb] = light.ray;
464
+ const segs = 18; // vertical resolution of each beam's undulating spine
465
  for (const r of rays) {
466
+ // slow horizontal drift of the whole beam (kept from v1)
467
  const off = Math.sin(t * r.speed * 6 + r.x) * 55;
468
+ const x0 = r.x + off;
469
  const topW = r.w * 0.45, botW = r.w * 1.9;
470
  const shift = r.tilt * H;
471
 
472
+ // Undulating spine: the beam's centerline bends left/right as it descends,
473
+ // driven by two traveling sine waves (different wavelength & speed) so it
474
+ // shimmers like sunlight refracted through moving water, seen from inside.
475
+ const L = [], R = [];
476
+ for (let i = 0; i <= segs; i++) {
477
+ const v = i / segs; // 0 at the surface, 1 near the floor
478
+ const y = -10 + v * (H * 0.95 + 10);
479
+ const grow = 0.35 + 0.65 * v; // straighter up top, bends more with depth
480
+ const wave =
481
+ Math.sin(v * r.uLen + t * r.uSpd + r.uPh) * r.uAmp +
482
+ Math.sin(v * r.vLen - t * r.vSpd + r.vPh) * r.vAmp;
483
+ const cx = x0 + shift * v + wave * grow; // undulating center x at this depth
484
+ const halfW = topW + (botW - topW) * v; // beam widens as it falls
485
+ L.push([cx - halfW, y]);
486
+ R.push([cx + halfW, y]);
487
+ }
488
 
489
+ // Fill a band between two edge polylines with a vertical fade (matches v1 look).
490
+ const band = (a, b, aTop, midStop, midFactor) => {
491
+ ctx.beginPath();
492
+ ctx.moveTo(a[0][0], a[0][1]);
493
+ for (let i = 1; i < a.length; i++) ctx.lineTo(a[i][0], a[i][1]);
494
+ for (let i = b.length - 1; i >= 0; i--) ctx.lineTo(b[i][0], b[i][1]);
495
+ ctx.closePath();
496
+ const g = ctx.createLinearGradient(0, 0, 0, H);
497
+ g.addColorStop(0, `rgba(${rr},${rg},${rb},${aTop})`);
498
+ g.addColorStop(midStop, `rgba(${rr},${rg},${rb},${aTop * midFactor})`);
499
+ g.addColorStop(1, `rgba(${rr},${rg},${rb},0)`);
500
+ ctx.fillStyle = g;
501
+ ctx.fill();
502
+ };
503
+
504
+ // soft outer beam (v1 alphas), now following the undulating spine
505
+ band(L, R, r.alpha, 0.55, 0.45);
506
+
507
+ // brighter, narrower inner core riding the same undulation (v1 core profile)
508
+ const LC = [], RC = [];
509
+ for (let i = 0; i <= segs; i++) {
510
+ const [lx, ly] = L[i], [rx2, ry2] = R[i];
511
+ const cxm = (lx + rx2) / 2;
512
+ const coreHalf = ((rx2 - lx) / 2) * 0.42; // 42% of the local half-width, as in v1
513
+ LC.push([cxm - coreHalf, ly]);
514
+ RC.push([cxm + coreHalf, ry2]);
515
+ }
516
+ band(LC, RC, r.alpha * 1.5, 0.65, 0);
517
  }
518
  }
519
 
 
691
  ctx.quadraticCurveTo((a.x + b.tx) / 2 + b.side * 3, (a.y + b.ty) / 2 - 5, b.tx, b.ty);
692
  ctx.stroke();
693
 
694
+ // colourful flower heads blooming along the branch — 1..3 per branch (v3)
695
+ if (b.flowers.length) {
696
+ const cpX = (a.x + b.tx) / 2 + b.side * 3;
697
+ const cpY = (a.y + b.ty) / 2 - 5;
698
+ for (const fl of b.flowers) {
699
+ const u = fl.t, iu = 1 - u; // point on the branch's quadratic curve
700
+ drawFlowerHead(iu * iu * a.x + 2 * iu * u * cpX + u * u * b.tx,
701
+ iu * iu * a.y + 2 * iu * u * cpY + u * u * b.ty, fl);
702
+ }
703
+ }
704
  }
705
  }
706
  }