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:
+89
-19
@@ -78,6 +78,7 @@ class WavesSim {
|
||||
if (mode === 'doppler') this._dopInit();
|
||||
if (mode === 'spectrum' && !this._specComponents.length)
|
||||
this._specComponents = [{ f: 5, A: 60 }, { f: 10, A: 30 }];
|
||||
if (window.LabFX) LabFX.sound.play('whoosh', { pitch: 1.2, volume: 0.3 });
|
||||
this.draw();
|
||||
this._emit();
|
||||
}
|
||||
@@ -135,6 +136,21 @@ class WavesSim {
|
||||
const dt = Math.min((ts - this._last) / 1000, 0.05) * this._speed;
|
||||
this._t += dt;
|
||||
if (this._mode === 'doppler') this._dopStep(dt);
|
||||
if (window.LabFX) LabFX.particles.update(dt);
|
||||
/* beats: play tick at envelope peaks (throttle to beat period) */
|
||||
if (this._mode === 'beats') {
|
||||
const fBeat = Math.abs(this._beatsF1 - this._beatsF2);
|
||||
if (fBeat > 0) {
|
||||
const TBeat = 1 / fBeat;
|
||||
const beatPhase = this._t % TBeat;
|
||||
if (!this._lastBeatTick || this._t - this._lastBeatTick >= TBeat * 0.95) {
|
||||
if (beatPhase < dt * this._speed + 0.02) {
|
||||
if (window.LabFX) LabFX.sound.play('tick', { pitch: 0.5, volume: 0.15 });
|
||||
this._lastBeatTick = this._t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this._last = ts;
|
||||
this._raf = requestAnimationFrame(t => this._tick(t));
|
||||
@@ -161,6 +177,7 @@ class WavesSim {
|
||||
else if (this._mode === 'doppler') this._dopplerDraw(ctx, W, H);
|
||||
else if (this._mode === 'beats') this._beatsDraw(ctx, W, H);
|
||||
else if (this._mode === 'spectrum') this._spectrumDraw(ctx, W, H);
|
||||
if (window.LabFX) LabFX.particles.draw(ctx);
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════
|
||||
@@ -185,18 +202,24 @@ class WavesSim {
|
||||
const y = x => A * Math.sin(om * t - k * (x - PL) + phi);
|
||||
|
||||
/* волновая кривая */
|
||||
ctx.save();
|
||||
ctx.shadowColor = WavesSim.V;
|
||||
ctx.shadowBlur = 16;
|
||||
ctx.strokeStyle = WavesSim.V;
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.beginPath();
|
||||
for (let x = PL; x <= PL + cw; x += 1) {
|
||||
const py = cy + y(x);
|
||||
x === PL ? ctx.moveTo(x, py) : ctx.lineTo(x, py);
|
||||
const _drawTransvWave = () => {
|
||||
ctx.strokeStyle = WavesSim.V;
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.beginPath();
|
||||
for (let x = PL; x <= PL + cw; x += 1) {
|
||||
const py = cy + y(x);
|
||||
x === PL ? ctx.moveTo(x, py) : ctx.lineTo(x, py);
|
||||
}
|
||||
ctx.stroke();
|
||||
};
|
||||
if (window.LabFX) {
|
||||
LabFX.glow.drawGlow(ctx, _drawTransvWave, { color: WavesSim.V, intensity: 5 });
|
||||
} else {
|
||||
ctx.save();
|
||||
ctx.shadowColor = WavesSim.V; ctx.shadowBlur = 16;
|
||||
_drawTransvWave();
|
||||
ctx.restore();
|
||||
}
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
|
||||
/* частицы */
|
||||
const step = Math.max(12, Math.floor(lam / 10));
|
||||
@@ -488,6 +511,32 @@ class WavesSim {
|
||||
ring.age += dt;
|
||||
return ring.r < maxR;
|
||||
});
|
||||
|
||||
/* LabFX: Mach shock particles when vs >= c */
|
||||
const mach = vsPx / c_px;
|
||||
if (window.LabFX) {
|
||||
if (mach >= 1.0 && !this._dopWasMach) {
|
||||
this._dopWasMach = true;
|
||||
LabFX.sound.play('spark', { volume: 0.4 });
|
||||
LabFX.particles.emit({
|
||||
ctx: this._ctx, x: this._dopSrcX, y: this._dopSrcY,
|
||||
count: 20, color: '#FF6B35', speed: 120,
|
||||
spread: Math.PI * 2, angle: 0, gravity: 80,
|
||||
life: 600, shape: 'spark', glow: true, size: 3,
|
||||
});
|
||||
} else if (mach < 1.0) {
|
||||
this._dopWasMach = false;
|
||||
}
|
||||
|
||||
/* haptic while dragging src (throttle 100ms) */
|
||||
if (this._dopDrag === 'src') {
|
||||
const now2 = performance.now();
|
||||
if (!this._dopHapticLast || now2 - this._dopHapticLast >= 100) {
|
||||
LabFX.haptic(5);
|
||||
this._dopHapticLast = now2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_dopplerDraw(ctx, W, H) {
|
||||
@@ -806,16 +855,24 @@ class WavesSim {
|
||||
══════════════════════════════════════ */
|
||||
|
||||
_waveLine(ctx, PL, cw, cy, fn, color, lw, alpha, glow) {
|
||||
const drawFn = () => {
|
||||
ctx.strokeStyle = color; ctx.lineWidth = lw;
|
||||
ctx.beginPath();
|
||||
for (let x = PL; x <= PL + cw; x += 1) {
|
||||
const py = cy + fn(x);
|
||||
x === PL ? ctx.moveTo(x, py) : ctx.lineTo(x, py);
|
||||
}
|
||||
ctx.stroke();
|
||||
};
|
||||
ctx.save();
|
||||
ctx.globalAlpha = alpha;
|
||||
if (glow) { ctx.shadowColor = color; ctx.shadowBlur = 16; }
|
||||
ctx.strokeStyle = color; ctx.lineWidth = lw;
|
||||
ctx.beginPath();
|
||||
for (let x = PL; x <= PL + cw; x += 1) {
|
||||
const py = cy + fn(x);
|
||||
x === PL ? ctx.moveTo(x, py) : ctx.lineTo(x, py);
|
||||
if (glow && window.LabFX) {
|
||||
LabFX.glow.drawGlow(ctx, drawFn, { color, intensity: 5 });
|
||||
} else {
|
||||
if (glow) { ctx.shadowColor = color; ctx.shadowBlur = 16; }
|
||||
drawFn();
|
||||
}
|
||||
ctx.stroke(); ctx.restore();
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
_grid(ctx, PL, PR, PT, PB, W, H) {
|
||||
@@ -847,8 +904,21 @@ class WavesSim {
|
||||
specAddComponent() {
|
||||
const f = this._specNewF;
|
||||
const A = 60;
|
||||
if (this._specComponents.length < 12)
|
||||
if (this._specComponents.length < 12) {
|
||||
this._specComponents.push({ f, A });
|
||||
if (window.LabFX) {
|
||||
LabFX.sound.play('chime', { pitch: Math.pow(2, f / 12), volume: 0.3 });
|
||||
/* emit dust at approximate peak position on spectrum */
|
||||
const peakX = this._W ? (this._W * 0.08) + (f / 50) * (this._W * 0.84) : 200;
|
||||
const peakY = this._H ? this._H * 0.3 : 100;
|
||||
LabFX.particles.emit({
|
||||
ctx: this._ctx, x: peakX, y: peakY,
|
||||
count: 8, color: '#FFD166', speed: 30,
|
||||
spread: Math.PI, angle: -Math.PI / 2, gravity: 50,
|
||||
life: 400, shape: 'dust', size: 2,
|
||||
});
|
||||
}
|
||||
}
|
||||
this.draw();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user