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:
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict';
|
||||
/* ══════════════════════════════════════════════════════════════
|
||||
ProbabilitySim — probability & law of large numbers
|
||||
coin flip · single die · two-dice sum
|
||||
@@ -569,3 +569,45 @@ class ProbabilitySim {
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined') module.exports = ProbabilitySim;
|
||||
|
||||
/* ─── lab UI init ─────────────────────────────────── */
|
||||
function _openProbability() {
|
||||
document.getElementById('sim-topbar-title').textContent = 'Теория вероятностей';
|
||||
_simShow('sim-probability');
|
||||
_registerSimState('probability', () => probSim?.getParams(), st => probSim?.setParams(st));
|
||||
if (_embedMode) _startStateEmit('probability');
|
||||
requestAnimationFrame(() => requestAnimationFrame(() => {
|
||||
if (!probSim) {
|
||||
probSim = new ProbabilitySim(document.getElementById('probability-canvas'));
|
||||
probSim.onUpdate = _probUpdateUI;
|
||||
}
|
||||
probSim.fit();
|
||||
probSim.reset();
|
||||
probSim.play();
|
||||
}));
|
||||
}
|
||||
|
||||
function probMode(mode, btn) {
|
||||
document.querySelectorAll('.prob-mode-btn').forEach(b => b.classList.remove('active'));
|
||||
if (btn) btn.classList.add('active');
|
||||
if (probSim) { probSim.setParams({ mode }); probSim.reset(); probSim.play(); }
|
||||
}
|
||||
|
||||
function probPreset(mode, trials) {
|
||||
document.querySelectorAll('.prob-mode-btn').forEach(b => {
|
||||
b.classList.toggle('active', b.textContent.toLowerCase().includes(mode === 'coin' ? 'монет' : mode === 'dice2' ? '2 куб' : 'кубик'));
|
||||
});
|
||||
if (probSim) { probSim.setParams({ mode, trials }); probSim.reset(); probSim.play(); }
|
||||
}
|
||||
|
||||
function _probUpdateUI(info) {
|
||||
const v = (id, val) => { const el = document.getElementById(id); if (el) el.textContent = val; };
|
||||
v('probbar-v1', info.totalTrials);
|
||||
v('probbar-v2', typeof info.maxDeviation === 'number' ? (info.maxDeviation * 100).toFixed(1) + '%' : '—');
|
||||
v('probbar-v3', typeof info.chiSquare === 'number' ? info.chiSquare.toFixed(2) : '—');
|
||||
const modeNames = { coin: 'Монета', dice: 'Кубик', dice2: '2 кубика' };
|
||||
v('probbar-v4', modeNames[info.mode] || info.mode);
|
||||
}
|
||||
|
||||
/* ── bohr atom ── */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user