refactor: distribute lab-init.js into 34 engine files

lab-init.js: 4098 -> 543 lines (infrastructure + THEORY only)

Each sim's _open*() + UI helpers moved to its engine file:
graph.js, projectile.js, collision.js, magnetic.js, triangle.js,
geometry.js, trigcircle.js, gas.js (molphys), coulomb.js, circuit.js,
reactions.js (chemistry), newton.js (dynamics), chemsandbox.js,
celldivision.js, photosynthesis.js, angrybirds.js, quadratic.js,
normaldist.js, graphtransform.js, pendulum.js, equilibrium.js,
thinlens.js, mirror.js, isoprocess.js, titration.js, refraction.js,
probability.js, bohratom.js, electrolysis.js, waves.js,
crystal.js, orbitals.js, stereo.js, hydrostatics.js

All 34 engine files syntax-checked OK.
This commit is contained in:
Maxim Dolgolyov
2026-05-08 14:54:54 +03:00
parent d5f77bb648
commit ae31e4c4e8
35 changed files with 3657 additions and 3589 deletions
+65 -1
View File
@@ -1,4 +1,4 @@
'use strict';
'use strict';
/* ══════════════════════════════════════════════════════════
CoulombSim — Coulomb's Law interactive simulation
• Click canvas to place charge (+ or )
@@ -746,3 +746,67 @@ class CoulombSim {
}, { passive: false });
}
}
/* ─── lab UI init ─────────────────────────────────── */
var csSim = null;
function _openCoulomb() {
document.getElementById('sim-topbar-title').textContent = 'Закон Кулона';
_simShow('sim-coulomb');
_simShow('ctrl-coulomb');
requestAnimationFrame(() => requestAnimationFrame(() => {
const canvas = document.getElementById('coulomb-canvas');
if (!csSim) {
csSim = new CoulombSim(canvas);
csSim.onUpdate = _coulombUpdateUI;
}
csSim.fit();
if (csSim.charges.length === 0) csSim.preset('dipole');
_coulombUpdateUI(csSim.info());
}));
}
function coulombSign(s) {
if (!csSim) return;
csSim.setSign(s);
document.getElementById('cbtn-pos').classList.toggle('active', s > 0);
document.getElementById('cbtn-neg').classList.toggle('active', s < 0);
document.getElementById('csign-pos').style.opacity = s > 0 ? '1' : '0.45';
document.getElementById('csign-neg').style.opacity = s < 0 ? '1' : '0.45';
}
function coulombLayer(name, rowEl) {
if (!csSim) return;
csSim.toggleLayer(name);
const on = csSim.layers[name];
rowEl.classList.toggle('active', on);
const tog = rowEl.querySelector('.tri-toggle');
if (tog) {
tog.style.background = on ? 'var(--violet)' : 'rgba(255,255,255,0.12)';
const dot = tog.querySelector('span');
if (dot) dot.style.marginLeft = on ? '14px' : '2px';
}
csSim.draw();
}
function coulombPreset(name) {
if (!csSim) return;
csSim.preset(name);
}
function _coulombUpdateUI(info) {
if (!info) return;
document.getElementById('cs-total').textContent = info.total;
document.getElementById('cs-curE').textContent = info.cursorE;
document.getElementById('cs-curV').textContent = info.cursorV;
document.getElementById('csbar-total').textContent = info.total;
document.getElementById('csbar-pos').textContent = info.positive;
document.getElementById('csbar-neg').textContent = info.negative;
document.getElementById('csbar-maxE').textContent = info.maxE;
document.getElementById('csbar-curE').textContent = info.cursorE;
}
/* ════════════════════════════════
ЭЛЕКТРИЧЕСКИЕ ЦЕПИ
════════════════════════════════ */