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:
@@ -120,6 +120,8 @@ class RadioactiveSim {
|
||||
);
|
||||
this.simTime = 0;
|
||||
this.history = [];
|
||||
this._lastHalfLifeMark = 0;
|
||||
this._fxDecayCount = 0;
|
||||
}
|
||||
|
||||
/* ══════════════ public API ══════════════ */
|
||||
@@ -265,6 +267,16 @@ class RadioactiveSim {
|
||||
: decayType.startsWith('β') ? 'β'
|
||||
: 'γ';
|
||||
this._flashes.push({ x: p.x, y: p.y, t: 0, maxT: 0.35, sym });
|
||||
// LabFX decay effects (throttled)
|
||||
if (window.LabFX) {
|
||||
this._fxFrameDecays = (this._fxFrameDecays || 0) + 1;
|
||||
LabFX.particles.emit({
|
||||
ctx: this.ctx, x: p.x, y: p.y,
|
||||
count: 6, color: '#FFD700', speed: 60,
|
||||
spread: Math.PI * 2, angle: 0, gravity: 0,
|
||||
life: 300, shape: 'spark', glow: true, size: 2,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// age flash on particle itself
|
||||
@@ -284,6 +296,32 @@ class RadioactiveSim {
|
||||
|
||||
this.simTime += dt;
|
||||
|
||||
// LabFX half-life crossing + throttled tick sound
|
||||
if (window.LabFX) {
|
||||
/* throttle tick: play at most once per frame, only if ≤10 decays/s effective */
|
||||
const frameDecays = this._fxFrameDecays || 0;
|
||||
this._fxFrameDecays = 0;
|
||||
if (frameDecays > 0) {
|
||||
const decaysPerSec = frameDecays / Math.max(wallDt, 0.001);
|
||||
const N = Math.max(1, Math.round(decaysPerSec / 10));
|
||||
if (Math.random() < 1 / N) {
|
||||
LabFX.sound.play('tick', { pitch: 0.8 + Math.random() * 0.4, volume: 0.08 });
|
||||
}
|
||||
}
|
||||
LabFX.particles.update(wallDt);
|
||||
const T0 = this.steps[0].T_half;
|
||||
if (T0 !== Infinity) {
|
||||
const halfLifesElapsed = Math.floor(this.simTime / T0);
|
||||
if (halfLifesElapsed > (this._lastHalfLifeMark || 0)) {
|
||||
this._lastHalfLifeMark = halfLifesElapsed;
|
||||
LabFX.sound.play('chime', {
|
||||
pitch: 0.6 + halfLifesElapsed * 0.1,
|
||||
volume: 0.3,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// record history every ~2 ticks (≈30ms)
|
||||
const last = this.history[this.history.length - 1];
|
||||
if (!last || this.simTime - last.t > this.steps[0].T_half * 0.005 || this.history.length < 5) {
|
||||
@@ -342,11 +380,23 @@ class RadioactiveSim {
|
||||
ctx.fillStyle = `rgba(255,255,200,${alpha * 0.45})`;
|
||||
ctx.fill();
|
||||
|
||||
ctx.font = `bold ${Math.round(8 + alpha * 4)}px Manrope,sans-serif`;
|
||||
ctx.fillStyle = `rgba(255,255,180,${alpha})`;
|
||||
const symSize = Math.round(8 + alpha * 4);
|
||||
ctx.font = `bold ${symSize}px Manrope,sans-serif`;
|
||||
const symColor = `rgba(255,255,180,${alpha})`;
|
||||
ctx.fillStyle = symColor;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(fl.sym, fl.x, fl.y - r - 4);
|
||||
if (window.LabFX) {
|
||||
LabFX.glow.drawGlow(ctx, () => {
|
||||
ctx.font = `bold ${symSize}px Manrope,sans-serif`;
|
||||
ctx.fillStyle = symColor;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(fl.sym, fl.x, fl.y - r - 4);
|
||||
}, { color: '#FFFFFF', intensity: 6 });
|
||||
} else {
|
||||
ctx.fillText(fl.sym, fl.x, fl.y - r - 4);
|
||||
}
|
||||
}
|
||||
|
||||
// draw particles
|
||||
@@ -374,6 +424,8 @@ class RadioactiveSim {
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.75)';
|
||||
ctx.fillText(s.name, lx + 15, y);
|
||||
}
|
||||
|
||||
if (window.LabFX) LabFX.particles.draw(ctx);
|
||||
}
|
||||
|
||||
_drawGraph() {
|
||||
@@ -549,6 +601,7 @@ function radioactiveN0(val) {
|
||||
|
||||
function radioactivePlay() {
|
||||
if (!radioactiveSim) return;
|
||||
if (window.LabFX) LabFX.sound.play('click');
|
||||
if (radioactiveSim.playing) {
|
||||
radioactiveSim.pause();
|
||||
document.getElementById('rd-play-btn').textContent = 'Старт';
|
||||
@@ -560,6 +613,9 @@ function radioactivePlay() {
|
||||
|
||||
function radioactiveReset() {
|
||||
if (!radioactiveSim) return;
|
||||
if (window.LabFX) LabFX.sound.play('whoosh', { pitch: 0.5, volume: 0.3 });
|
||||
radioactiveSim._lastHalfLifeMark = 0;
|
||||
radioactiveSim._fxDecayCount = 0;
|
||||
radioactiveSim.reset();
|
||||
document.getElementById('rd-play-btn').textContent = 'Старт';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user