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
+79 -30
View File
@@ -337,6 +337,30 @@ class CircuitSim {
const speed = Math.min(Math.abs(c._I) * 0.6, 8) / (this.CELL * _compLen(c));
c._t = ((c._t || 0) + speed * dt * 60) % 1;
}
if (window.LabFX) LabFX.particles.update(dt);
// heat shimmer: emit smoke above hottest resistor every 5 frames
if (window.LabFX && this._heatmapOn && this._solution?.solved) {
if (!this._smokeFrame) this._smokeFrame = 0;
this._smokeFrame++;
if (this._smokeFrame % 5 === 0) {
const dissipators = this.components.filter(c => c.type === 'resistor' || c.type === 'lamp');
if (dissipators.length) {
let hottest = dissipators[0], hotP = 0;
for (const c of dissipators) {
const P = Math.abs((c._I ?? 0) ** 2 * this._compR(c));
if (P > hotP) { hotP = P; hottest = c; }
}
if (hotP > 0.1) {
const p1 = this._nodePixel(hottest.x1, hottest.y1), p2 = this._nodePixel(hottest.x2, hottest.y2);
const mx = (p1.x + p2.x) / 2, my = (p1.y + p2.y) / 2;
LabFX.particles.emit({ ctx: this.ctx, x: mx, y: my - 10, count: 1, color: 'rgba(255,180,100,0.15)', speed: 8, spread: 0.5, angle: -Math.PI / 2, gravity: -50, life: 1500, shape: 'smoke', size: 8, fade: true });
}
}
}
}
this.draw();
if (this._oscPanel && this._oscPanel.offsetParent !== null) {
this.drawOscilloscope(this._oscPanel);
@@ -467,7 +491,12 @@ class CircuitSim {
/* ─── Component draw methods ───────────────────────────────────────────── */
_drawWire(ctx, c, p1, p2, hasI) {
this._drawWireLine(ctx, p1, p2, c._v1, c._v2, 3, hasI);
if (window.LabFX && hasI && Math.abs(c._I) > 0) {
const intensity = Math.min(20, 6 + Math.abs(c._I) * 2);
LabFX.glow.drawGlow(ctx, () => this._drawWireLine(ctx, p1, p2, c._v1, c._v2, 3, hasI), { color: '#06D6E0', intensity });
} else {
this._drawWireLine(ctx, p1, p2, c._v1, c._v2, 3, hasI);
}
}
_drawResistor(ctx, c, p1, p2, mx, my, hasI) {
@@ -769,35 +798,41 @@ class CircuitSim {
const on=(this._diodeR.get(c.id)??1e9)<1;
const col=c.ledColor||this.ledColor;
if (on) {
const grd=ctx.createRadialGradient(mx,my,0,mx,my,38);
grd.addColorStop(0,col+'50'); grd.addColorStop(1,col+'00');
ctx.fillStyle=grd;
ctx.beginPath(); ctx.arc(mx,my,38,0,Math.PI*2); ctx.fill();
}
ctx.save();
ctx.translate(mx,my); ctx.rotate(Math.atan2(dy,dx));
ctx.beginPath();
ctx.moveTo(-tw,-th); ctx.lineTo(-tw,th); ctx.lineTo(tw,0); ctx.closePath();
ctx.fillStyle=on?col+'55':col+'18'; ctx.fill();
ctx.strokeStyle=on?col:col+'90'; ctx.lineWidth=1.5; ctx.stroke();
ctx.beginPath(); ctx.moveTo(tw,-th); ctx.lineTo(tw,th); ctx.stroke();
if (on) {
ctx.strokeStyle=col; ctx.lineWidth=1.2;
for (let s=-1;s<=1;s+=2) {
ctx.beginPath();
ctx.moveTo(tw+3, s*5);
ctx.lineTo(tw+11, s*5-s*6);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(tw+11,s*5-s*6); ctx.lineTo(tw+8,s*5-s*6);
ctx.moveTo(tw+11,s*5-s*6); ctx.lineTo(tw+11,s*5-s*3);
ctx.stroke();
const drawLEDBody = () => {
if (on) {
const grd=ctx.createRadialGradient(mx,my,0,mx,my,38);
grd.addColorStop(0,col+'50'); grd.addColorStop(1,col+'00');
ctx.fillStyle=grd;
ctx.beginPath(); ctx.arc(mx,my,38,0,Math.PI*2); ctx.fill();
}
ctx.save();
ctx.translate(mx,my); ctx.rotate(Math.atan2(dy,dx));
ctx.beginPath();
ctx.moveTo(-tw,-th); ctx.lineTo(-tw,th); ctx.lineTo(tw,0); ctx.closePath();
ctx.fillStyle=on?col+'55':col+'18'; ctx.fill();
ctx.strokeStyle=on?col:col+'90'; ctx.lineWidth=1.5; ctx.stroke();
ctx.beginPath(); ctx.moveTo(tw,-th); ctx.lineTo(tw,th); ctx.stroke();
if (on) {
ctx.strokeStyle=col; ctx.lineWidth=1.2;
for (let s=-1;s<=1;s+=2) {
ctx.beginPath();
ctx.moveTo(tw+3, s*5);
ctx.lineTo(tw+11, s*5-s*6);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(tw+11,s*5-s*6); ctx.lineTo(tw+8,s*5-s*6);
ctx.moveTo(tw+11,s*5-s*6); ctx.lineTo(tw+11,s*5-s*3);
ctx.stroke();
}
}
ctx.restore();
};
if (window.LabFX && on) {
LabFX.glow.drawGlow(ctx, drawLEDBody, { color: col, intensity: 18, layers: 2 });
} else {
drawLEDBody();
}
ctx.restore();
ctx.font='9px Manrope,sans-serif'; ctx.fillStyle=col+'cc';
ctx.textAlign='center'; ctx.textBaseline='top';
@@ -985,6 +1020,17 @@ class CircuitSim {
ctx.textAlign='center'; ctx.textBaseline='middle';
ctx.fillText('Короткое замыкание!', this.W/2, this.H/2);
ctx.textBaseline='alphabetic';
if (window.LabFX) {
const now4 = performance.now();
if (!this._shortFXt || now4 - this._shortFXt > 600) {
this._shortFXt = now4;
const p1=this._nodePixel(batt.x1,batt.y1), p2=this._nodePixel(batt.x2,batt.y2);
const sx=(p1.x+p2.x)/2, sy=(p1.y+p2.y)/2;
LabFX.particles.emit({ ctx, x: sx, y: sy, count: 12, color: '#EF476F', speed: 80, spread: Math.PI*2, life: 300, shape: 'spark', size: 3, glow: true });
LabFX.sound.play('spark');
LabFX.shake(this.canvas, { intensity: 5, durMs: 200 });
}
}
}
/* ─── Hint ─────────────────────────────────────────────────────────────── */
@@ -1145,6 +1191,7 @@ class CircuitSim {
if (this._drawing&&this._ghostEnd) this._drawGhost(ctx);
this._drawTooltip(ctx);
if (this.components.length===0) this._drawHint(ctx);
if (window.LabFX) LabFX.particles.draw(ctx);
}
/* ─── Events ───────────────────────────────────────────────────────────── */
@@ -1196,7 +1243,7 @@ class CircuitSim {
const p=pos(e), g=snap(p), hi=hitComp(p);
if (this.addMode==='erase') {
if (hi>=0) { this._pushHistory(); this.components.splice(hi,1); this._solve(); this.draw(); }
if (hi>=0) { this._pushHistory(); this.components.splice(hi,1); this._solve(); this.draw(); if (window.LabFX) LabFX.sound.play('fizz', { volume: 0.3 }); }
return;
}
if (hi>=0) {
@@ -1266,13 +1313,14 @@ class CircuitSim {
cvs.addEventListener('contextmenu', e=>{
e.preventDefault();
const p=pos(e), i=hitComp(p);
if (i>=0) { this._pushHistory(); this.components.splice(i,1); this._selected=null; this._solve(); this.draw(); }
if (i>=0) { this._pushHistory(); this.components.splice(i,1); this._selected=null; this._solve(); this.draw(); if (window.LabFX) LabFX.sound.play('fizz', { volume: 0.3 }); }
});
cvs.addEventListener('dblclick', e=>{
const p=pos(e), i=hitComp(p);
if (i>=0&&this.components[i].type==='switch') {
this._pushHistory(); this.components[i].open=!this.components[i].open; this._solve(); this.draw();
if (window.LabFX) LabFX.sound.play('click', { pitch: 1.5 });
}
});
@@ -1327,6 +1375,7 @@ class CircuitSim {
: undefined;
const L_value = type==='inductor' ? this.L_value : undefined;
this._add(type,x1,y1,x2,y2,value,L_value);
if (window.LabFX) LabFX.sound.play('click', { pitch: 0.9 });
this._solve(); this.draw();
if (this.onUpdate) this.onUpdate(this.info());
}