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:
@@ -63,8 +63,25 @@ class HeatEngineSim {
|
||||
setTc(v) { this.Tc = Math.max(200, Math.min(this.Th - 10, +v)); this._recompute(); }
|
||||
setCR(v) { this.cr = Math.max(2, Math.min(20, +v)); this._recompute(); }
|
||||
|
||||
start() { if (!this._running) { this._running = true; this._loop(); } }
|
||||
pause() { this._running = false; cancelAnimationFrame(this._raf); }
|
||||
start() {
|
||||
if (!this._running) {
|
||||
this._running = true;
|
||||
this._lastPhase = null;
|
||||
this._fxDroneHandle = null;
|
||||
if (window.LabFX) {
|
||||
this._fxDroneHandle = LabFX.sound.startDrone('drone');
|
||||
}
|
||||
this._loop();
|
||||
}
|
||||
}
|
||||
pause() {
|
||||
this._running = false;
|
||||
cancelAnimationFrame(this._raf);
|
||||
if (window.LabFX && this._fxDroneHandle) {
|
||||
try { this._fxDroneHandle.stop(); } catch {}
|
||||
this._fxDroneHandle = null;
|
||||
}
|
||||
}
|
||||
stop() { this.pause(); this._t = 0; this._drawPv(); this._drawPiston(); }
|
||||
step() { this._t = (this._t + this._speed * 10) % 1; this._drawPv(); this._drawPiston(); }
|
||||
reset() { this.stop(); this._recompute(); }
|
||||
@@ -286,11 +303,64 @@ class HeatEngineSim {
|
||||
if (!this._running) return;
|
||||
this._t = (this._t + this._speed) % 1;
|
||||
this._updateParticles();
|
||||
this._fxUpdate();
|
||||
this._drawPv();
|
||||
this._drawPiston();
|
||||
this._raf = requestAnimationFrame(() => this._loop());
|
||||
}
|
||||
|
||||
_fxUpdate() {
|
||||
if (!window.LabFX) return;
|
||||
const st = this._stateAt(this._t);
|
||||
if (!st) return;
|
||||
|
||||
const pisCtx = this._pisCtx;
|
||||
const W = this._pis.offsetWidth || 300;
|
||||
const H = this._pis.offsetHeight || 300;
|
||||
|
||||
/* phase change tick */
|
||||
if (this._lastPhase !== null && st.phase !== this._lastPhase) {
|
||||
LabFX.sound.play('tick', { pitch: 0.8, volume: 0.2 });
|
||||
/* BDC / TDC bounce — detect segment boundaries (u≈0) */
|
||||
LabFX.sound.play('bounce', { pitch: 0.5, volume: 0.15 });
|
||||
}
|
||||
this._lastPhase = st.phase;
|
||||
|
||||
/* compute piston position for particle emit */
|
||||
const ns = this._nodes;
|
||||
const Vmin = Math.min(...ns.map(n => n.V));
|
||||
const Vmax = Math.max(...ns.map(n => n.V));
|
||||
const Vfrac = (st.V - Vmin) / (Vmax - Vmin || 1);
|
||||
const cylX = W * 0.2, cylW = W * 0.6;
|
||||
const cylTop = H * 0.12, cylBot = H * 0.92;
|
||||
const cylH = cylBot - cylTop;
|
||||
const pistonY = cylTop + cylH * (1 - Vfrac);
|
||||
const resX = W * 0.05, resW = W * 0.12;
|
||||
|
||||
const isHot = st.phase === 'isotherm_hot' || st.phase === 'isochoric_hot' || st.phase === 'isobar_hot';
|
||||
const isCold = st.phase === 'isotherm_cold' || st.phase === 'isochoric_cold' || st.phase === 'isobar_cold';
|
||||
|
||||
if (isHot) {
|
||||
/* red smoke upward from hot reservoir */
|
||||
LabFX.particles.emit({
|
||||
ctx: pisCtx, x: resX + resW / 2, y: pistonY - 5,
|
||||
count: 1, color: 'rgba(255,80,40,0.3)', speed: 15,
|
||||
spread: 0.6, angle: -Math.PI / 2, gravity: -50,
|
||||
life: 1500, shape: 'smoke', size: 6,
|
||||
});
|
||||
} else if (isCold) {
|
||||
/* blue dust downward from cold reservoir */
|
||||
LabFX.particles.emit({
|
||||
ctx: pisCtx, x: resX + resW / 2, y: pistonY + 10,
|
||||
count: 1, color: 'rgba(100,150,255,0.3)', speed: 10,
|
||||
spread: 0.6, angle: Math.PI / 2, gravity: 30,
|
||||
life: 800, shape: 'dust', size: 4,
|
||||
});
|
||||
}
|
||||
|
||||
LabFX.particles.update(this._speed);
|
||||
}
|
||||
|
||||
/* ── interpolated state ──────────────────────────── */
|
||||
|
||||
_stateAt(t) {
|
||||
@@ -824,6 +894,19 @@ class HeatEngineSim {
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillText('T = ' + Math.round(st.T) + ' K', W * 0.75, cylTop + 16);
|
||||
ctx.fillText('V = ' + this._fmtSci(st.V) + ' m³', W * 0.75, cylTop + 30);
|
||||
|
||||
/* adiabatic shimmer on insulation lines */
|
||||
const isAdia2 = phase === 'adiabat_exp' || phase === 'adiabat_comp';
|
||||
if (isAdia2 && window.LabFX) {
|
||||
const pulse = LabFX.glow.pulse(performance.now() / 1000, 0.6);
|
||||
ctx.save();
|
||||
ctx.globalAlpha = 0.1 + pulse * 0.25;
|
||||
ctx.fillStyle = 'rgba(255,200,0,0.6)';
|
||||
ctx.fillRect(resX, cylTop, resW, cylH);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
if (window.LabFX) LabFX.particles.draw(ctx);
|
||||
}
|
||||
|
||||
_drawHeatArrows(ctx, x0, y0, x1, col, rightward) {
|
||||
|
||||
Reference in New Issue
Block a user