feat(labs): visual polish wave — LabFX foundation + 33 sims juiced up

ФУНДАМЕНТ (4 новых файла):
- _fx_core.js: LabFX namespace, glow.drawGlow, glow.pulse, haptic, shake
- _fx_particles.js: пул 1500 объектов, 6 shapes (dot/spark/ring/smoke/splash/dust)
- _fx_motion.js: tween + 12 easings + critically-damped spring
- _fx_sound.js: 9 procedural synth-звуков (click/tick/whoosh/chime/fizz/spark/bounce/pour/drone), Web Audio API
- Sound toggle в шапке lab.html с localStorage-persist

UX МИКРО (CSS + JS):
- Button states: hover scale+brightness, active scale-down, disabled grayscale
- Slider polish: custom thumb с тенью, filled-track gradient, hover/active
- Focus rings через :focus-visible
- Tooltip system .tt-host data-tt= с 400ms hover, fade-in
- Marching ants для selection
- Loading skeleton с shimmer
- Empty state .sim-empty-* паттерн
- Toast: progress bar внизу, icons по типу
- Cursor states utility classes
- View Transitions API для smooth sim-switch, fallback на CSS fade

PHASE 2 — визуальные эффекты для 33 симуляций:

Physics motion: projectile (launch whoosh + landing splash/shake/haptic + target chime), pendulum (max-extension tick + bob glow), collision (bounce + sparks + shake), angrybirds (whoosh/bounce/fizz/chime + confetti), newton (rocket flame trail + scene transitions), forcesandbox (spring glow + impact sparks)

Physics fields: emfield (field-lines glow + particle trail + lightning при high field + Gauss-drag haptic + rod motion sparks), circuit (energized-wire glow ∝ current + LED bloom + short-circuit shake/spark + heat shimmer smoke + place/erase/switch sounds), opticsbench (beam glow на всех режимах + caustics dust у фокуса + TIR/Brewster one-shot sounds)

Thermo+waves: waves (mode-switch whoosh + Mach-cone particles + spectrum harmonic chime + waveform glow), hydrostatics (pour sound + splash при погружении + valve click), isoprocess (PV-trail dust), heatengine (drone цикла + hot/cold reservoir smoke/dust + phase-change ticks), radioactive (Geiger tick throttle + decay sparks + half-life chime + α/β/γ glow)

Chemistry: chemsandbox (pour splash + fizz bubbles/dust/spark по типу реакции + shake при горении), equilibrium/electrolysis/reactions/titration/flask/ionexchange/redox (pour/fizz/spark/chime по событиям, частицы при ключевых моментах), stoichiometry (fizz bubbles + recipe-change click)

Math+geom: geometry (tool-click + object-create tick + locus glow + challenge confetti via LabFX + haptic), triangle (vertex-drop tick + special-point glow), stereo (figure-change whoosh + cross-section chime, no particles — Three.js), trigcircle (drag-haptic + pitch∝angle tick + sin/cos glow), graph/graphtransform/quadratic (slider-tick throttled + curve glow + discriminant-cross chime), probability (bounce + finish-chime burst), normaldist (pulsing shade + bell glow)

Bio+misc: celldivision (phase-change whoosh + prophase dust + anaphase poles spark + cytokinesis chime), photosynthesis (photon tick + ATP chime + glucose sparkle), bohratom (electron-jump chime ∝ levels + photon spark), orbitals/crystal (mode-change whoosh — Three.js, sound only), logic (gate-place + wire-connect + LED bloom + HIGH wire flowing dots + preset chime), gas/brownian/diffusion/states (preset whoosh, throttled tick по событиям)

Все LabFX вызовы обёрнуты в if (window.LabFX) guard — graceful degradation если фундамент не загружен. 47 JS файлов прошли syntax check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maxim Dolgolyov
2026-05-23 13:58:49 +03:00
parent 8b3159b529
commit 6afe928c0d
50 changed files with 2748 additions and 215 deletions
+50 -3
View File
@@ -29,7 +29,27 @@ class TriangleSim {
};
this.onUpdate = null; // cb(stats)
this._lastHapticTs = 0;
this._lastRafTs = 0;
this._bindEvents();
this._startParticleLoop();
}
_startParticleLoop() {
let last = performance.now();
let fxFrames = 0; // countdown frames to keep drawing after last emit
const loop = (now) => {
const dt = (now - last) / 1000;
last = now;
if (window.LabFX) {
LabFX.particles.update(dt);
if (fxFrames > 0) { fxFrames--; this.draw(); }
}
requestAnimationFrame(loop);
};
// expose a trigger so emit events bump the counter
this._fxActivate = () => { fxFrames = 60; };
requestAnimationFrame(loop);
}
/* ── sizing ── */
@@ -70,6 +90,7 @@ class TriangleSim {
this._initPts();
this.draw();
if (this.onUpdate) this.onUpdate(this.stats());
if (window.LabFX) LabFX.sound.play('whoosh', { volume: 0.3 });
}
/* ── pointer events ── */
@@ -97,6 +118,11 @@ class TriangleSim {
this._clampPts();
this.draw();
if (this.onUpdate) this.onUpdate(this.stats());
const now = performance.now();
if (window.LabFX && now - (this._lastHapticTs || 0) > 100) {
this._lastHapticTs = now;
LabFX.haptic(5);
}
};
c.addEventListener('mousedown', e => {
@@ -115,6 +141,14 @@ class TriangleSim {
});
c.addEventListener('mouseup', () => {
if (this._dragging !== null && this.pts) {
const p = this.pts[this._dragging];
if (window.LabFX) {
LabFX.sound.play('tick', { pitch: 1.2, volume: 0.2 });
LabFX.particles.emit({ ctx: this.ctx, x: p.x, y: p.y, count: 4, color: '#9B5DE5', shape: 'dust', life: 300, speed: 40, spread: Math.PI * 2, gravity: 0 });
if (this._fxActivate) this._fxActivate();
}
}
this._dragging = null;
c.style.cursor = this._hovered !== null ? 'grab' : 'default';
});
@@ -298,6 +332,7 @@ class TriangleSim {
this._drawVertices(ctx);
this._drawSideLabels(ctx);
this._drawAngleLabels(ctx);
if (window.LabFX) LabFX.particles.draw(ctx);
}
/* helpers */
@@ -506,8 +541,14 @@ class TriangleSim {
// midpoint ticks
[mA, mB, mC].forEach(m => this._dot(ctx, m.x, m.y, 4, '#22d55e'));
// centroid
this._dot(ctx, G.x, G.y, 7, '#22d55e');
// centroid with glow
if (window.LabFX) {
LabFX.glow.drawGlow(ctx, () => {
this._dot(ctx, G.x, G.y, 7, '#22d55e');
}, { color: '#F59E0B', intensity: 6 });
} else {
this._dot(ctx, G.x, G.y, 7, '#22d55e');
}
this._label(ctx, 'G', G.x + 14, G.y - 8, '#22d55e', 13);
ctx.restore();
@@ -549,7 +590,13 @@ class TriangleSim {
[fA, fB, fC].forEach(f => this._dot(ctx, f.x, f.y, 4, '#f59e0b'));
if (H) {
this._dot(ctx, H.x, H.y, 7, '#f59e0b');
if (window.LabFX) {
LabFX.glow.drawGlow(ctx, () => {
this._dot(ctx, H.x, H.y, 7, '#f59e0b');
}, { color: '#F59E0B', intensity: 6 });
} else {
this._dot(ctx, H.x, H.y, 7, '#f59e0b');
}
this._label(ctx, 'H', H.x + 14, H.y - 8, '#f59e0b', 13);
}
ctx.restore();