Skip to content

Commit 58ace87

Browse files
committed
feat: Implement interactive Shockwave Physics (Wave & Particle displacement) & Fix Button Clicks (#8655)
1 parent f936156 commit 58ace87

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

apps/portal/canvas/HeaderCanvas.mjs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,25 @@ class HeaderCanvas extends Base {
282282
let sine = Math.sin(((x + freqMod) * 0.04) - timeShift) * localAmp,
283283
sineB = Math.sin(((x + freqMod) * 0.04) - timeShift + Math.PI) * localAmp; // Inverted
284284

285+
// SHOCKWAVE PHYSICS (Displacement)
286+
let shockY = 0;
287+
if (me.shockwaves.length > 0) {
288+
me.shockwaves.forEach(wave => {
289+
let radius = wave.age * wave.speed,
290+
dist = x - wave.x; // Signed distance
291+
292+
// Check if point is near the wave front (e.g. within 50px)
293+
if (Math.abs(dist) < radius && Math.abs(dist) > radius - 60) {
294+
// Pulse shape: Sine wave based on distance from center relative to radius
295+
let pulse = Math.sin((dist / radius) * Math.PI * 10) * (1 - (wave.age / wave.life)) * 20;
296+
shockY += pulse;
297+
}
298+
})
299+
}
300+
285301
// Write Y values to buffers
286-
bufA[i] = centerY + sine - offsetY + noiseA;
287-
bufB[i] = centerY + sineB + offsetY + noiseB;
302+
bufA[i] = centerY + sine - offsetY + noiseA + shockY;
303+
bufB[i] = centerY + sineB + offsetY + noiseB + shockY;
288304
}
289305

290306
return {shimmerA, shimmerB, count}
@@ -337,11 +353,30 @@ class HeaderCanvas extends Base {
337353
p.y += (dy / dist) * force * (2 / mass);
338354
// Brighten slightly
339355
p.alpha = Math.min(p.baseAlpha + force * (p.isNebula ? 0.05 : 0.5), 0.8);
340-
} else {
341-
// Return to base alpha
342-
if (p.alpha > p.baseAlpha) {
343-
p.alpha -= 0.005
344-
}
356+
}
357+
358+
// Interaction: Shockwave Repulsion
359+
if (me.shockwaves.length > 0) {
360+
me.shockwaves.forEach(wave => {
361+
let wx = p.x - wave.x,
362+
wy = p.y - wave.y,
363+
wDist = Math.sqrt(wx*wx + wy*wy),
364+
radius = wave.age * wave.speed;
365+
366+
// If particle is near the expanding ring (width 40px)
367+
if (wDist < radius && wDist > radius - 40) {
368+
let force = (1 - (wave.age / wave.life)) * 2; // Decay force over time
369+
// Push outward
370+
p.x += (wx / wDist) * force * 5;
371+
p.y += (wy / wDist) * force * 5;
372+
p.alpha = Math.min(p.alpha + 0.3, 1); // Flash bright
373+
}
374+
})
375+
}
376+
377+
// Return to base alpha
378+
if (p.alpha > p.baseAlpha) {
379+
p.alpha -= 0.005
345380
}
346381

347382
ctx.globalAlpha = p.alpha;

apps/portal/view/HeaderToolbar.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HeaderToolbar extends Base {
2121
* @member {Object[]} domListeners
2222
*/
2323
domListeners: [{
24-
click : 'onClick',
24+
click : {fn: 'onClick', options: {capture: true}},
2525
mouseleave: 'onMouseLeave',
2626
mousemove : {fn: 'onMouseMove', local: true}
2727
}],

0 commit comments

Comments
 (0)