Электромагнитные явления — от заряда до магнита
Заряды притягиваются и отталкиваются, образуют электрическое поле. По проводнику течёт ток, и закон Ома связывает $U$, $I$, $R$. У постоянных магнитов и проводников с током есть магнитное поле.
0.05) { [40, 70, 100].forEach((dy, k) => { const op = intensity * (1 - k * 0.25); if (op < 0.05) return; svg.appendChild(P8Helpers.svg.el('path', { d: 'M 50 '+(100-dy)+' Q 280 '+(100-dy*1.5)+', 510 '+(100-dy), fill: 'none', stroke: '#7c3aed', 'stroke-width': 1.5, opacity: op })); svg.appendChild(P8Helpers.svg.el('path', { d: 'M 50 '+(100+dy)+' Q 280 '+(100+dy*1.5)+', 510 '+(100+dy), fill: 'none', stroke: '#7c3aed', 'stroke-width': 1.5, opacity: op })); }); } svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 180, 'font-family':"'JetBrains Mono',monospace", 'font-size':12, 'font-weight':800, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'B ∝ N·I = '+B+' (отн.)' })); document.getElementById('p31-iv6-out').textContent = B; } state.n = 100; const nInp = document.getElementById('p31-iv6-n'); const nLab = document.getElementById('p31-iv6-n-val'); nInp.oninput = ev => { state.n = +ev.target.value; nLab.textContent = (state.n).toFixed(0); render(); }; state.i = 1; const iInp = document.getElementById('p31-iv6-i'); const iLab = document.getElementById('p31-iv6-i-val'); iInp.oninput = ev => { state.i = +ev.target.value; iLab.textContent = (state.i).toFixed(2); render(); }; render(); } function _initP29_iv6(){ const sb = document.getElementById('p29-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const I = state.i; /* Wire (vertical center) */ svg.appendChild(P8Helpers.svg.el('line', { x1: 280, y1: 20, x2: 280, y2: 180, stroke: '#0f172a', 'stroke-width': 5 })); /* Current direction */ if (Math.abs(I) > 0.05) { const dir = I > 0 ? 1 : -1; svg.appendChild(P8Helpers.svg.el('polygon', { points: '280,'+(dir>0?20:180)+' 274,'+(dir>0?30:170)+' 286,'+(dir>0?30:170), fill: '#dc2626' })); } /* Field circles around wire */ const intensity = Math.abs(I) / 10; [25, 45, 65, 90, 115].forEach((r, k) => { const opacity = intensity * (1 - k * 0.15); if (opacity > 0.05) { svg.appendChild(P8Helpers.svg.el('circle', { cx: 280, cy: 100, r, fill: 'none', stroke: '#7c3aed', 'stroke-width': 1.5, opacity, 'stroke-dasharray': '5 3' })); } }); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 195, 'font-family':"'JetBrains Mono',monospace", 'font-size':12, 'font-weight':800, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'I = '+I.toFixed(1)+' А, B ∝ |I|' })); document.getElementById('p29-iv6-out').textContent = Math.abs(I).toFixed(1); } state.i = 3; const iInp = document.getElementById('p29-iv6-i'); const iLab = document.getElementById('p29-iv6-i-val'); iInp.oninput = ev => { state.i = +ev.target.value; iLab.textContent = (state.i).toFixed(2); render(); }; render(); } function _initP27_iv6(){ const sb = document.getElementById('p27-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const P = state.p, t = state.t; const A = P * t / 1000; /* kWh */ /* Time bar */ const barW = (t / 24) * 460; svg.appendChild(P8Helpers.svg.el('rect', { x: 50, y: 80, width: 460, height: 40, fill: '#e5e7eb', stroke: '#0f172a' })); svg.appendChild(P8Helpers.svg.el('rect', { x: 50, y: 80, width: barW, height: 40, fill: 'var(--el-mid,#06b6d4)', opacity: 0.7 })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 105, 'font-family':"'JetBrains Mono',monospace", 'font-size':14, 'font-weight':800, fill:'#fff', 'text-anchor':'middle', text: t.toFixed(1)+' ч из 24' })); /* A display */ svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 160, 'font-family':"'Unbounded',sans-serif", 'font-size':18, 'font-weight':900, fill:'#0f172a', 'text-anchor':'middle', text: 'A = '+A.toFixed(3)+' кВт·ч' })); document.getElementById('p27-iv6-out').textContent = A.toFixed(3); } state.p = 100; const pInp = document.getElementById('p27-iv6-p'); const pLab = document.getElementById('p27-iv6-p-val'); pInp.oninput = ev => { state.p = +ev.target.value; pLab.textContent = (state.p).toFixed(0); render(); }; state.t = 5; const tInp = document.getElementById('p27-iv6-t'); const tLab = document.getElementById('p27-iv6-t-val'); tInp.oninput = ev => { state.t = +ev.target.value; tLab.textContent = (state.t).toFixed(2); render(); }; render(); } function _initP26_iv6(){ const sb = document.getElementById('p26-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const U = state.u, I = state.i; const P = U * I; /* Lamp brightness */ const brightness = Math.min(1, P / 200); svg.appendChild(P8Helpers.svg.el('circle', { cx: 280, cy: 100, r: 50, fill: '#fef3c7', opacity: brightness * 0.5 + 0.2 })); svg.appendChild(P8Helpers.svg.el('circle', { cx: 280, cy: 100, r: 30, fill: '#fde047', stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 105, 'font-family':"'Unbounded',sans-serif", 'font-size':16, 'font-weight':900, fill: '#0f172a', 'text-anchor':'middle', text: P.toFixed(0) })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 122, 'font-family':"'Inter',sans-serif", 'font-size':11, 'font-weight':700, fill: '#0f172a', 'text-anchor':'middle', text: 'Вт' })); if (brightness > 0.6) { /* Rays */ for (let i = 0; i < 8; i++) { const a = i * Math.PI / 4; const x1 = 280 + 38 * Math.cos(a), y1 = 100 + 38 * Math.sin(a); const x2 = 280 + 58 * Math.cos(a), y2 = 100 + 58 * Math.sin(a); svg.appendChild(P8Helpers.svg.el('line', { x1, y1, x2, y2, stroke: '#facc15', 'stroke-width': 3 })); } } svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 180, 'font-family':"'JetBrains Mono',monospace", 'font-size':12, 'font-weight':700, fill:'#0f172a', 'text-anchor':'middle', text: 'P = U·I = '+U+'·'+I.toFixed(2)+' = '+P.toFixed(1)+' Вт' })); document.getElementById('p26-iv6-out').textContent = P.toFixed(1); } state.u = 220; const uInp = document.getElementById('p26-iv6-u'); const uLab = document.getElementById('p26-iv6-u-val'); uInp.oninput = ev => { state.u = +ev.target.value; uLab.textContent = (state.u).toFixed(0); render(); }; state.i = 0.5; const iInp = document.getElementById('p26-iv6-i'); const iLab = document.getElementById('p26-iv6-i-val'); iInp.oninput = ev => { state.i = +ev.target.value; iLab.textContent = (state.i).toFixed(2); render(); }; render(); } function _initP24_iv6(){ const sb = document.getElementById('p24-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const R1 = state.r1, R2 = state.r2; const R = R1 + R2; const U = 12; const I = U / R; /* Battery */ svg.appendChild(P8Helpers.em.circuitComponent('battery', 80, 100, 'h', U+' В')); /* R1 */ svg.appendChild(P8Helpers.em.circuitComponent('resistor', 240, 100, 'h', R1+' Ом')); /* R2 */ svg.appendChild(P8Helpers.em.circuitComponent('resistor', 400, 100, 'h', R2+' Ом')); /* Wires */ svg.appendChild(P8Helpers.svg.el('line', { x1: 110, y1: 100, x2: 210, y2: 100, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 270, y1: 100, x2: 370, y2: 100, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 430, y1: 100, x2: 510, y2: 100, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 510, y1: 100, x2: 510, y2: 160, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 50, y1: 100, x2: 50, y2: 160, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 50, y1: 160, x2: 510, y2: 160, stroke: '#0f172a', 'stroke-width': 2 })); /* Labels */ svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 180, 'font-family':"'JetBrains Mono',monospace", 'font-size':12, 'font-weight':800, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'R = R₁+R₂ = '+R+' Ом, I = U/R = '+I.toFixed(3)+' А' })); document.getElementById('p24-iv6-out').textContent = R; } state.r1 = 20; const r1Inp = document.getElementById('p24-iv6-r1'); const r1Lab = document.getElementById('p24-iv6-r1-val'); r1Inp.oninput = ev => { state.r1 = +ev.target.value; r1Lab.textContent = (state.r1).toFixed(0); render(); }; state.r2 = 30; const r2Inp = document.getElementById('p24-iv6-r2'); const r2Lab = document.getElementById('p24-iv6-r2-val'); r2Inp.oninput = ev => { state.r2 = +ev.target.value; r2Lab.textContent = (state.r2).toFixed(0); render(); }; render(); } function _initP23_iv6(){ const sb = document.getElementById('p23-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const l = state.l, S = state.s * 1e-6; const rho = 1.7e-8; const R = rho * l / S; /* Wire shape: длина = l*60 max, толщина = sqrt(S)*8 max */ const wireL = Math.min(440, 50 + l * 40); const wireH = Math.min(40, 6 + Math.sqrt(state.s) * 8); svg.appendChild(P8Helpers.svg.el('rect', { x: (560 - wireL) / 2, y: (200 - wireH) / 2, width: wireL, height: wireH, fill: '#b45309', stroke: '#0f172a', 'stroke-width': 2, rx: 4 })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: (200 - wireH)/2 - 8, 'font-family':"'JetBrains Mono',monospace", 'font-size':11, 'font-weight':700, fill:'#0f172a', 'text-anchor':'middle', text: 'l = '+l.toFixed(1)+' м, S = '+state.s.toFixed(1)+' мм²' })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 170, 'font-family':"'Unbounded',sans-serif", 'font-size':14, 'font-weight':800, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'R = '+R.toFixed(4)+' Ом' })); document.getElementById('p23-iv6-out').textContent = R.toFixed(4); } state.l = 1; const lInp = document.getElementById('p23-iv6-l'); const lLab = document.getElementById('p23-iv6-l-val'); lInp.oninput = ev => { state.l = +ev.target.value; lLab.textContent = (state.l).toFixed(2); render(); }; state.s = 1; const sInp = document.getElementById('p23-iv6-s'); const sLab = document.getElementById('p23-iv6-s-val'); sInp.oninput = ev => { state.s = +ev.target.value; sLab.textContent = (state.s).toFixed(2); render(); }; render(); } function _initP21_iv6(){ const sb = document.getElementById('p21-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const closed = state.s > 0.5; /* Battery */ svg.appendChild(P8Helpers.em.circuitComponent('battery', 120, 100, 'h', '6 В')); /* Switch */ svg.appendChild(P8Helpers.em.circuitComponent('switch', 270, 100, 'h')); if (closed) { svg.appendChild(P8Helpers.svg.el('line', { x1: 258, y1: 100, x2: 282, y2: 100, stroke: '#0f172a', 'stroke-width': 2 })); } /* Lamp */ svg.appendChild(P8Helpers.em.circuitComponent('lamp', 420, 100, 'h')); if (closed) { svg.appendChild(P8Helpers.svg.el('circle', { cx: 420, cy: 100, r: 22, fill: '#fef3c7', opacity: 0.5 })); } /* Wires */ svg.appendChild(P8Helpers.svg.el('line', { x1: 150, y1: 100, x2: 240, y2: 100, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 300, y1: 100, x2: 394, y2: 100, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 446, y1: 100, x2: 500, y2: 100, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 500, y1: 100, x2: 500, y2: 160, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 90, y1: 100, x2: 90, y2: 160, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 90, y1: 160, x2: 500, y2: 160, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 185, 'font-family':"'Inter',sans-serif", 'font-size':11, 'font-weight':700, fill: closed ? '#16a34a' : '#dc2626', 'text-anchor':'middle', text: closed ? '✓ Цепь замкнута — ток идёт' : '✗ Цепь разомкнута' })); document.getElementById('p21-iv6-out').textContent = closed ? 'замкнута' : 'разомкнута'; } state.s = 1; const sInp = document.getElementById('p21-iv6-s'); const sLab = document.getElementById('p21-iv6-s-val'); sInp.oninput = ev => { state.s = +ev.target.value; sLab.textContent = (state.s).toFixed(0); render(); }; render(); } function _initP20_iv6(){ const sb = document.getElementById('p20-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const q = state.q, t = state.t; const I = q / t; /* Wire with flowing charges */ svg.appendChild(P8Helpers.svg.el('rect', { x: 80, y: 90, width: 400, height: 20, fill: '#cbd5e1', stroke: '#0f172a', 'stroke-width': 2 })); const numE = Math.min(20, Math.round(q)); for (let i = 0; i < numE; i++) { const t0 = (Date.now() / 200 + i / numE) % 1; const x = 90 + t0 * 380; svg.appendChild(P8Helpers.svg.el('circle', { cx: x, cy: 100, r: 4, fill: '#dc2626' })); } /* Arrow direction */ svg.appendChild(P8Helpers.svg.gradientArrow(svg, 480, 100, 530, 100, { colorFrom: '#dc2626', colorTo: '#7f1d1d', width: 3, headSize: 12 })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 140, 'font-family':"'JetBrains Mono',monospace", 'font-size':14, 'font-weight':800, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'I = '+q+'/'+t+' = '+I.toFixed(2)+' А' })); document.getElementById('p20-iv6-out').textContent = I.toFixed(2); if (!sb._anim) sb._anim = setInterval(() => { if (sb.isConnected) render(); else clearInterval(sb._anim); }, 100); } state.q = 6; const qInp = document.getElementById('p20-iv6-q'); const qLab = document.getElementById('p20-iv6-q-val'); qInp.oninput = ev => { state.q = +ev.target.value; qLab.textContent = (state.q).toFixed(2); render(); }; state.t = 2; const tInp = document.getElementById('p20-iv6-t'); const tLab = document.getElementById('p20-iv6-t-val'); tInp.oninput = ev => { state.t = +ev.target.value; tLab.textContent = (state.t).toFixed(2); render(); }; render(); } function _initP19_iv6(){ const sb = document.getElementById('p19-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const A = state.a, q = state.q; const E = A / q; /* Battery shape */ svg.appendChild(P8Helpers.svg.el('rect', { x: 200, y: 60, width: 160, height: 80, fill: '#facc15', stroke: '#0f172a', 'stroke-width': 3, rx: 8 })); svg.appendChild(P8Helpers.svg.el('rect', { x: 215, y: 50, width: 30, height: 10, fill: '#475569' })); svg.appendChild(P8Helpers.svg.el('rect', { x: 320, y: 50, width: 30, height: 10, fill: '#475569' })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 100, 'font-family':"'Unbounded',sans-serif", 'font-size':22, 'font-weight':900, fill:'#0f172a', 'text-anchor':'middle', text: E.toFixed(1)+' В' })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 125, 'font-family':"'Inter',sans-serif", 'font-size':11, fill:'#0f172a', 'text-anchor':'middle', text: 'A = '+A+' Дж, q = '+q+' Кл' })); document.getElementById('p19-iv6-out').textContent = E.toFixed(1); } state.a = 24; const aInp = document.getElementById('p19-iv6-a'); const aLab = document.getElementById('p19-iv6-a-val'); aInp.oninput = ev => { state.a = +ev.target.value; aLab.textContent = (state.a).toFixed(0); render(); }; state.q = 2; const qInp = document.getElementById('p19-iv6-q'); const qLab = document.getElementById('p19-iv6-q-val'); qInp.oninput = ev => { state.q = +ev.target.value; qLab.textContent = (state.q).toFixed(2); render(); }; render(); } function _initP18_iv6(){ const sb = document.getElementById('p18-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const q = state.q, U = state.u; const A = q * U; /* Two plates */ svg.appendChild(P8Helpers.svg.el('line', { x1: 100, y1: 40, x2: 100, y2: 160, stroke: '#dc2626', 'stroke-width': 6 })); svg.appendChild(P8Helpers.svg.el('text', { x: 100, y: 30, 'font-family':"'Unbounded',sans-serif", 'font-size':14, 'font-weight':900, fill:'#dc2626', 'text-anchor':'middle', text: '+' })); svg.appendChild(P8Helpers.svg.el('line', { x1: 400, y1: 40, x2: 400, y2: 160, stroke: '#2563eb', 'stroke-width': 6 })); svg.appendChild(P8Helpers.svg.el('text', { x: 400, y: 30, 'font-family':"'Unbounded',sans-serif", 'font-size':14, 'font-weight':900, fill:'#2563eb', 'text-anchor':'middle', text: '−' })); /* Charge moving */ svg.appendChild(P8Helpers.svg.el('circle', { cx: 200, cy: 100, r: 14, fill: '#fecaca', stroke: '#dc2626', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('text', { x: 200, y: 105, 'font-family':"'Inter',sans-serif", 'font-size':14, 'font-weight':900, fill:'#dc2626', 'text-anchor':'middle', text: '+q' })); /* Arrow direction of work */ svg.appendChild(P8Helpers.svg.gradientArrow(svg, 220, 100, 380, 100, { colorFrom: '#facc15', colorTo: '#dc2626', width: 3, headSize: 12, glow: true })); svg.appendChild(P8Helpers.svg.el('text', { x: 300, y: 90, 'font-family':"'JetBrains Mono',monospace", 'font-size':14, 'font-weight':800, fill:'#0f172a', 'text-anchor':'middle', text: 'A = qU = '+A.toFixed(1)+' мкДж' })); svg.appendChild(P8Helpers.svg.el('text', { x: 250, y: 180, 'font-family':"'Inter',sans-serif", 'font-size':11, fill:'var(--p8-muted,#64748b)', 'text-anchor':'middle', text: 'U = '+U+' В, между пластинами' })); document.getElementById('p18-iv6-out').textContent = A.toFixed(1); } state.q = 1; const qInp = document.getElementById('p18-iv6-q'); const qLab = document.getElementById('p18-iv6-q-val'); qInp.oninput = ev => { state.q = +ev.target.value; qLab.textContent = (state.q).toFixed(2); render(); }; state.u = 12; const uInp = document.getElementById('p18-iv6-u'); const uLab = document.getElementById('p18-iv6-u-val'); uInp.oninput = ev => { state.u = +ev.target.value; uLab.textContent = (state.u).toFixed(0); render(); }; render(); } function _initP16_iv6(){ const sb = document.getElementById('p16-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const Z = Math.round(state.z); /* Nucleus */ svg.appendChild(P8Helpers.svg.el('circle', { cx: 280, cy: 100, r: 14, fill: '#dc2626', stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 105, 'font-family':"'Unbounded',sans-serif", 'font-size':12, 'font-weight':900, fill:'#fff', 'text-anchor':'middle', text: '+'+Z })); /* Orbits — fill shell by shell: 2, 8, 8, 2 */ const shells = []; let remaining = Z; [2, 8, 8, 2].forEach(cap => { if (remaining > 0) { shells.push(Math.min(cap, remaining)); remaining -= cap; }}); shells.forEach((electrons, shellIdx) => { const radius = 35 + shellIdx * 20; svg.appendChild(P8Helpers.svg.el('circle', { cx: 280, cy: 100, r: radius, fill: 'none', stroke: '#94a3b8', 'stroke-width': 1, 'stroke-dasharray': '3 3' })); for (let i = 0; i < electrons; i++) { const a = i * 2 * Math.PI / electrons; svg.appendChild(P8Helpers.svg.el('circle', { cx: 280 + radius * Math.cos(a), cy: 100 + radius * Math.sin(a), r: 4.5, fill: '#2563eb', stroke: '#0f172a', 'stroke-width': 1 })); } }); document.getElementById('p16-iv6-out').textContent = '+'+Z+'e'; } state.z = 6; const zInp = document.getElementById('p16-iv6-z'); const zLab = document.getElementById('p16-iv6-z-val'); zInp.oninput = ev => { state.z = +ev.target.value; zLab.textContent = (state.z).toFixed(0); render(); }; render(); } function _initP15_iv6(){ const sb = document.getElementById('p15-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const q = state.q * 1e-9; const n = Math.abs(q / 1.6e-19); const sign = q > 0 ? 1 : -1; /* Body (sphere) */ svg.appendChild(P8Helpers.svg.el('circle', { cx: 200, cy: 100, r: 50, fill: sign > 0 ? '#fecaca' : '#bfdbfe', stroke: sign > 0 ? '#dc2626' : '#2563eb', 'stroke-width': 3 })); /* +/- charges around */ const numE = Math.min(12, Math.round(n / 1e10) + 1); for (let i = 0; i < numE; i++) { const a = i * 2 * Math.PI / numE; svg.appendChild(P8Helpers.svg.el('text', { x: 200 + 38 * Math.cos(a), y: 105 + 38 * Math.sin(a), 'font-family':"'Inter',sans-serif", 'font-size':14, 'font-weight':900, fill: sign > 0 ? '#dc2626' : '#2563eb', 'text-anchor':'middle', text: sign > 0 ? '+' : '−' })); } /* Counter */ svg.appendChild(P8Helpers.svg.el('text', { x: 380, y: 90, 'font-family':"'Unbounded',sans-serif", 'font-size':14, 'font-weight':800, fill:'#0f172a', 'text-anchor':'middle', text: 'n = q/e' })); svg.appendChild(P8Helpers.svg.el('text', { x: 380, y: 115, 'font-family':"'JetBrains Mono',monospace", 'font-size':16, 'font-weight':700, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: '≈ '+(n/1e10).toFixed(2)+'·10¹⁰' })); document.getElementById('p15-iv6-out').textContent = (n / 1e10).toFixed(2); } state.q = 1; const qInp = document.getElementById('p15-iv6-q'); const qLab = document.getElementById('p15-iv6-q-val'); qInp.oninput = ev => { state.q = +ev.target.value; qLab.textContent = (state.q).toFixed(2); render(); }; render(); } function _initP14_iv6(){ const sb = document.getElementById('p14-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const d = state.d; /* Charged rod (left) */ svg.appendChild(P8Helpers.svg.el('rect', { x: 30, y: 80, width: 60, height: 30, fill: '#fecaca', stroke: '#dc2626', 'stroke-width': 2, rx: 5 })); svg.appendChild(P8Helpers.svg.el('text', { x: 60, y: 100, 'font-family':"'Unbounded',sans-serif", 'font-size':18, 'font-weight':900, fill: '#dc2626', 'text-anchor':'middle', text: '+++' })); /* Conductor (right at position 90 + d) */ const condX = 90 + d; svg.appendChild(P8Helpers.svg.el('rect', { x: condX, y: 70, width: 140, height: 50, fill: '#fef3c7', stroke: '#0f172a', 'stroke-width': 2, rx: 5 })); /* Distribution: near side − , far side + (induction) */ const intensity = Math.max(0, Math.min(1, (300 - d) / 250)); if (intensity > 0.1) { svg.appendChild(P8Helpers.svg.el('text', { x: condX + 25, y: 100, 'font-family':"'Unbounded',sans-serif", 'font-size':16, 'font-weight':900, fill: '#2563eb', 'text-anchor':'middle', text: '−−' })); svg.appendChild(P8Helpers.svg.el('text', { x: condX + 115, y: 100, 'font-family':"'Unbounded',sans-serif", 'font-size':16, 'font-weight':900, fill: '#dc2626', 'text-anchor':'middle', text: '++' })); } document.getElementById('p14-iv6-out').textContent = intensity.toFixed(2); } state.d = 200; const dInp = document.getElementById('p14-iv6-d'); const dLab = document.getElementById('p14-iv6-d-val'); dInp.oninput = ev => { state.d = +ev.target.value; dLab.textContent = (state.d).toFixed(0); render(); }; render(); } function _initP13_iv6(){ const sb = document.getElementById('p13-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 200); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const state = {}; function render(){ svg.innerHTML = ''; const U = state.u; /* Conductor (left) — copper bar */ svg.appendChild(P8Helpers.svg.el('rect', { x: 50, y: 60, width: 180, height: 60, fill: '#b45309', stroke: '#0f172a', 'stroke-width': 2, rx: 5 })); svg.appendChild(P8Helpers.svg.el('text', { x: 140, y: 50, 'font-family':"'Inter',sans-serif", 'font-size':12, 'font-weight':700, fill:'#0f172a', 'text-anchor':'middle', text: 'Проводник (медь)' })); /* Moving electrons in conductor */ const numE = 8; for (let i = 0; i < numE; i++) { const t = (Date.now() / 100 + i * 20) % 100 / 100; const x = 60 + t * 160; svg.appendChild(P8Helpers.svg.el('circle', { cx: x, cy: 80 + (i % 2) * 20, r: 4, fill: '#dc2626', opacity: U > 5 ? 1 : 0.3 })); } /* Insulator (right) — glass bar */ svg.appendChild(P8Helpers.svg.el('rect', { x: 320, y: 60, width: 180, height: 60, fill: '#bae6fd', stroke: '#0f172a', 'stroke-width': 2, rx: 5 })); svg.appendChild(P8Helpers.svg.el('text', { x: 410, y: 50, 'font-family':"'Inter',sans-serif", 'font-size':12, 'font-weight':700, fill:'#0f172a', 'text-anchor':'middle', text: 'Диэлектрик (стекло)' })); /* Stuck electrons */ for (let i = 0; i < 8; i++) { svg.appendChild(P8Helpers.svg.el('circle', { cx: 335 + i * 22, cy: 80 + (i % 2) * 20, r: 4, fill: '#475569' })); } /* Current ↦ in conductor only */ const I = U > 1 ? U / 10 : 0; svg.appendChild(P8Helpers.svg.el('text', { x: 140, y: 145, 'font-family':"'JetBrains Mono',monospace", 'font-size':12, 'font-weight':800, fill:'#dc2626', 'text-anchor':'middle', text: 'I = '+I.toFixed(2)+' А' })); svg.appendChild(P8Helpers.svg.el('text', { x: 410, y: 145, 'font-family':"'JetBrains Mono',monospace", 'font-size':12, 'font-weight':800, fill:'#94a3b8', 'text-anchor':'middle', text: 'I = 0 А' })); document.getElementById('p13-iv6-out').textContent = I.toFixed(2); /* Animate by re-render every 50ms */ if (!sb._anim) sb._anim = setInterval(() => { if (sb.isConnected) render(); else { clearInterval(sb._anim); } }, 100); } state.u = 0; const uInp = document.getElementById('p13-iv6-u'); const uLab = document.getElementById('p13-iv6-u-val'); uInp.oninput = ev => { state.u = +ev.target.value; uLab.textContent = (state.u).toFixed(0); render(); }; render(); } function _initP30_iv6(){ const sb = document.getElementById('p30-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 240); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); let I = 0; function render(){ svg.innerHTML = ''; /* Wire (horizontal) */ svg.appendChild(P8Helpers.svg.el('line', { x1: 40, y1: 120, x2: 520, y2: 120, stroke: '#0f172a', 'stroke-width': 5 })); /* Current arrow direction */ if (Math.abs(I) > 0.05) { const dir = I > 0 ? 1 : -1; const arrowX = 320; svg.appendChild(P8Helpers.svg.el('polygon', { points: dir > 0 ? (arrowX+8)+',120 '+(arrowX-12)+',114 '+(arrowX-12)+',126' : (arrowX-8)+',120 '+(arrowX+12)+',114 '+(arrowX+12)+',126', fill: '#dc2626' })); svg.appendChild(P8Helpers.svg.el('text', { x: 100, y: 110, 'font-family':"'JetBrains Mono',monospace", 'font-size':11, 'font-weight':700, fill:'#dc2626', text: 'I = '+I.toFixed(1)+' А' })); } /* Field lines around wire (concentric circles) */ const intensity = Math.abs(I) / 5; if (intensity > 0.05) { [30, 50, 70, 90].forEach((r, i) => { svg.appendChild(P8Helpers.svg.el('circle', { cx: 280, cy: 120, r, fill: 'none', stroke: '#7c3aed', 'stroke-width': 1.5, opacity: intensity * (1 - i * 0.15), 'stroke-dasharray': '5 3' })); }); } /* Compass below wire (initially N up = 0°) */ const angle = Math.atan2(0, 1) * 180 / Math.PI; /* baseline */ /* Angle deflection ∝ I (sign determines direction) */ const deflection = Math.atan(I * 0.5) * 60; /* approx */ /* Compass body */ svg.appendChild(P8Helpers.svg.el('circle', { cx: 280, cy: 195, r: 28, fill: '#fff', stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('text', { x: 280, y: 172, 'font-family':"'Unbounded',sans-serif", 'font-size':10, 'font-weight':800, fill:'#dc2626', 'text-anchor':'middle', text: 'N' })); /* Needle */ const needleG = P8Helpers.svg.el('g', { transform: 'translate(280, 195) rotate('+deflection+')' }); needleG.appendChild(P8Helpers.svg.el('polygon', { points: '-2,-22 2,-22 0,-2', fill: '#dc2626' })); needleG.appendChild(P8Helpers.svg.el('polygon', { points: '-2,22 2,22 0,2', fill: '#475569' })); needleG.appendChild(P8Helpers.svg.el('circle', { cx: 0, cy: 0, r: 3, fill: '#0f172a' })); svg.appendChild(needleG); document.getElementById('p30-iv6-ang').textContent = Math.round(deflection); } document.getElementById('p30-iv6-i').oninput = ev => { I = +ev.target.value; document.getElementById('p30-iv6-i-val').textContent = I.toFixed(1); render(); }; render(); } function _initP28_iv6(){ const sb = document.getElementById('p28-iv6-sandbox'); if (!sb || !window.P8Drag) return; const W = 560, H = 240; const canvas = document.createElement('canvas'); canvas.width = W; canvas.height = H; canvas.style.width='100%'; canvas.style.height='100%'; canvas.style.display='block'; sb.appendChild(canvas); const ctx = canvas.getContext('2d'); const magnets = [ { x: 140, y: 120, angle: 0, r: 50 }, { x: 420, y: 120, angle: 0, r: 50 } ]; function drawMagnet(m){ const w = 100, h = 32; ctx.save(); ctx.translate(m.x, m.y); ctx.rotate(m.angle); /* N half (red) */ ctx.fillStyle = '#dc2626'; ctx.fillRect(-w/2, -h/2, w/2, h); /* S half (blue) */ ctx.fillStyle = '#2563eb'; ctx.fillRect(0, -h/2, w/2, h); ctx.strokeStyle = '#0f172a'; ctx.lineWidth = 2; ctx.strokeRect(-w/2, -h/2, w, h); ctx.fillStyle = '#fff'; ctx.font = "bold 18px sans-serif"; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText('N', -w/4, 0); ctx.fillText('S', w/4, 0); ctx.restore(); } function draw(){ ctx.fillStyle = '#fafafa'; ctx.fillRect(0, 0, W, H); /* Compute interaction between the two magnets — their inner poles */ /* Magnet 1: right side is S (blue, at +50), Magnet 2: left side is N (red, at -50) */ const m1S_x = magnets[0].x + 50 * Math.cos(magnets[0].angle); const m1S_y = magnets[0].y + 50 * Math.sin(magnets[0].angle); const m2N_x = magnets[1].x - 50 * Math.cos(magnets[1].angle); const m2N_y = magnets[1].y - 50 * Math.sin(magnets[1].angle); const dx = m2N_x - m1S_x; const dy = m2N_y - m1S_y; const dist = Math.sqrt(dx*dx + dy*dy); if (dist < 250 && dist > 30) { /* N-S → attraction */ const F = 5000 / (dist * dist); const ux = dx / dist, uy = dy / dist; const len = Math.min(50, F * 50); const color = '#dc2626'; /* Arrow 1 from m1S toward m2N */ ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(m1S_x, m1S_y); ctx.lineTo(m1S_x + ux * len, m1S_y + uy * len); ctx.stroke(); /* Arrow 2 from m2N back */ ctx.beginPath(); ctx.moveTo(m2N_x, m2N_y); ctx.lineTo(m2N_x - ux * len, m2N_y - uy * len); ctx.stroke(); ctx.fillStyle = color; ctx.font = "bold 12px sans-serif"; ctx.textAlign = 'center'; ctx.fillText('притяжение', (m1S_x + m2N_x)/2, (m1S_y + m2N_y)/2 - 12); } magnets.forEach(drawMagnet); } /* Drag */ const dragObjs = magnets.map((m, i) => ({ x: m.x, y: m.y, r: 50, idx: i })); const drag = P8Drag.attachCanvas(canvas, { objects: dragObjs, onDrag: (obj, pos) => { magnets[obj.idx].x = pos.x; magnets[obj.idx].y = pos.y; draw(); } }); draw(); } function _initP25_iv6(){ const sb = document.getElementById('p25-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 240); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); const U = 12; let R1 = 20, R2 = 30; function render(){ svg.innerHTML = ''; const R = 1 / (1/R1 + 1/R2); const I1 = U / R1, I2 = U / R2, I = I1 + I2; /* Battery left */ svg.appendChild(P8Helpers.em.circuitComponent('battery', 80, 120, 'h', U+' В')); /* Branch split */ svg.appendChild(P8Helpers.svg.el('line', { x1: 110, y1: 120, x2: 200, y2: 120, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 200, y1: 60, x2: 200, y2: 180, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 380, y1: 60, x2: 380, y2: 180, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 200, y1: 60, x2: 290, y2: 60, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 320, y1: 60, x2: 380, y2: 60, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 200, y1: 180, x2: 290, y2: 180, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 320, y1: 180, x2: 380, y2: 180, stroke: '#0f172a', 'stroke-width': 2 })); /* R1 (top) */ svg.appendChild(P8Helpers.em.circuitComponent('resistor', 305, 60, 'h', R1+' Ом')); /* R2 (bottom) */ svg.appendChild(P8Helpers.em.circuitComponent('resistor', 305, 180, 'h', R2+' Ом')); /* Right wire */ svg.appendChild(P8Helpers.svg.el('line', { x1: 380, y1: 120, x2: 510, y2: 120, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 510, y1: 120, x2: 510, y2: 210, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 50, y1: 120, x2: 50, y2: 210, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 50, y1: 210, x2: 510, y2: 210, stroke: '#0f172a', 'stroke-width': 2 })); /* Current labels */ svg.appendChild(P8Helpers.svg.el('text', { x: 290, y: 48, 'font-family':"'JetBrains Mono',monospace", 'font-size':11, 'font-weight':700, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'I₁ = '+I1.toFixed(2)+' А' })); svg.appendChild(P8Helpers.svg.el('text', { x: 290, y: 218, 'font-family':"'JetBrains Mono',monospace", 'font-size':11, 'font-weight':700, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'I₂ = '+I2.toFixed(2)+' А' })); svg.appendChild(P8Helpers.svg.el('text', { x: 150, y: 138, 'font-family':"'JetBrains Mono',monospace", 'font-size':11, 'font-weight':700, fill:'#dc2626', 'text-anchor':'middle', text: 'I = '+I.toFixed(2)+' А' })); document.getElementById('p25-iv6-r').textContent = R.toFixed(1); document.getElementById('p25-iv6-i1').textContent = I1.toFixed(2); document.getElementById('p25-iv6-i2').textContent = I2.toFixed(2); } document.getElementById('p25-iv6-r1').oninput = ev => { R1 = +ev.target.value; document.getElementById('p25-iv6-r1-val').textContent = R1; render(); }; document.getElementById('p25-iv6-r2').oninput = ev => { R2 = +ev.target.value; document.getElementById('p25-iv6-r2-val').textContent = R2; render(); }; render(); } function _initP22_iv6(){ const sb = document.getElementById('p22-iv6-sandbox'); if (!sb || !window.P8Helpers) return; const svg = P8Helpers.svg.create(560, 220); svg.setAttribute('width','100%'); svg.setAttribute('height','100%'); svg.style.display='block'; sb.appendChild(svg); let U = 6, R = 12; function render(){ svg.innerHTML = ''; const I = U / R; /* Circuit */ /* Battery */ svg.appendChild(P8Helpers.em.circuitComponent('battery', 120, 110, 'h', U+' В')); /* Resistor */ svg.appendChild(P8Helpers.em.circuitComponent('resistor', 280, 110, 'h', R+' Ом')); /* Lamp (brightness varies with I) */ const lampG = P8Helpers.svg.el('g', { transform: 'translate(440, 110)' }); const brightness = Math.min(1, I / 1.5); lampG.appendChild(P8Helpers.svg.el('circle', { cx: 0, cy: 0, r: 26, fill: '#fef3c7', opacity: brightness * 0.6 + 0.1 })); lampG.appendChild(P8Helpers.svg.el('circle', { cx: 0, cy: 0, r: 16, fill: '#fef3c7', stroke: '#0f172a', 'stroke-width': 2 })); if (brightness > 0.3) { lampG.appendChild(P8Helpers.svg.el('circle', { cx: 0, cy: 0, r: 30, fill: 'none', stroke: '#facc15', 'stroke-width': 3, opacity: brightness })); } lampG.appendChild(P8Helpers.svg.el('line', { x1: -10, y1: -10, x2: 10, y2: 10, stroke: '#0f172a', 'stroke-width': 1.5 })); lampG.appendChild(P8Helpers.svg.el('line', { x1: -10, y1: 10, x2: 10, y2: -10, stroke: '#0f172a', 'stroke-width': 1.5 })); svg.appendChild(lampG); /* Connect wires */ svg.appendChild(P8Helpers.svg.el('line', { x1: 150, y1: 110, x2: 250, y2: 110, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 310, y1: 110, x2: 414, y2: 110, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 466, y1: 110, x2: 510, y2: 110, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 510, y1: 110, x2: 510, y2: 170, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 90, y1: 110, x2: 90, y2: 170, stroke: '#0f172a', 'stroke-width': 2 })); svg.appendChild(P8Helpers.svg.el('line', { x1: 90, y1: 170, x2: 510, y2: 170, stroke: '#0f172a', 'stroke-width': 2 })); /* Current label */ svg.appendChild(P8Helpers.svg.el('text', { x: 300, y: 195, 'font-family':"'JetBrains Mono',monospace", 'font-size':14, 'font-weight':800, fill:'var(--el-mid,#06b6d4)', 'text-anchor':'middle', text: 'I = '+I.toFixed(2)+' А' })); document.getElementById('p22-iv6-i').textContent = I.toFixed(2); } document.getElementById('p22-iv6-u').oninput = ev => { U = +ev.target.value; document.getElementById('p22-iv6-u-val').textContent = U.toFixed(1); render(); }; document.getElementById('p22-iv6-r').oninput = ev => { R = +ev.target.value; document.getElementById('p22-iv6-r-val').textContent = R; render(); }; render(); } function _initP17_iv6(){ const sb = document.getElementById('p17-iv6-sandbox'); if (!sb || !window.P8Drag) return; const W = 560, H = 320; const canvas = document.createElement('canvas'); canvas.width = W; canvas.height = H; canvas.style.width = '100%'; canvas.style.height = '100%'; canvas.style.display = 'block'; sb.appendChild(canvas); const ctx = canvas.getContext('2d'); let charges = [ { x: 200, y: 160, sign: 1, r: 22 }, { x: 360, y: 160, sign: -1, r: 22 } ]; function E(x, y) { let ex = 0, ey = 0; charges.forEach(c => { const dx = x - c.x, dy = y - c.y; const r2 = dx*dx + dy*dy; if (r2 < 200) return; const r = Math.sqrt(r2); const k = 5000 * c.sign / r2; ex += k * dx / r; ey += k * dy / r; }); return { ex, ey, mag: Math.sqrt(ex*ex + ey*ey) }; } function draw(){ ctx.fillStyle = '#fafafa'; ctx.fillRect(0, 0, W, H); /* Draw field lines starting from + charges */ charges.filter(c => c.sign > 0).forEach(c => { for (let i = 0; i < 16; i++) { const a = i * 2 * Math.PI / 16; let x = c.x + 25 * Math.cos(a); let y = c.y + 25 * Math.sin(a); ctx.strokeStyle = '#dc2626'; ctx.lineWidth = 1.2; ctx.globalAlpha = 0.75; ctx.beginPath(); ctx.moveTo(x, y); for (let step = 0; step < 200; step++) { const e = E(x, y); if (e.mag < 0.01) break; const dx = e.ex / e.mag * 3; const dy = e.ey / e.mag * 3; x += dx; y += dy; if (x < 0 || x > W || y < 0 || y > H) break; /* Stop near - charge */ let nearNeg = false; for (const neg of charges) { if (neg.sign < 0 && (x - neg.x)**2 + (y - neg.y)**2 < 600) { nearNeg = true; break; } } ctx.lineTo(x, y); if (nearNeg) break; } ctx.stroke(); ctx.globalAlpha = 1; } }); /* Charges */ charges.forEach(c => { const color = c.sign > 0 ? '#dc2626' : '#2563eb'; const fill = c.sign > 0 ? '#fecaca' : '#bfdbfe'; ctx.fillStyle = fill; ctx.strokeStyle = color; ctx.lineWidth = 2.5; ctx.beginPath(); ctx.arc(c.x, c.y, 20, 0, 2 * Math.PI); ctx.fill(); ctx.stroke(); ctx.fillStyle = color; ctx.font = "bold 20px sans-serif"; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(c.sign > 0 ? '+' : '−', c.x, c.y + 1); }); } const drag = P8Drag.attachCanvas(canvas, { objects: charges, onDrag: () => draw() }); document.getElementById('p17-iv6-add-pos').onclick = () => { charges.push({ x: 100 + Math.random() * (W - 200), y: 80 + Math.random() * (H - 160), sign: 1, r: 22 }); drag.updateObjects(charges); draw(); }; document.getElementById('p17-iv6-add-neg').onclick = () => { charges.push({ x: 100 + Math.random() * (W - 200), y: 80 + Math.random() * (H - 160), sign: -1, r: 22 }); drag.updateObjects(charges); draw(); }; document.getElementById('p17-iv6-clear').onclick = () => { charges.length = 0; charges.push({ x: 200, y: 160, sign: 1, r: 22 }, { x: 360, y: 160, sign: -1, r: 22 }); drag.updateObjects(charges); draw(); }; draw(); } function _initP12_iv6(){ const sb = document.getElementById('p12-iv6-sandbox'); if (!sb || !window.P8Helpers || !window.P8Drag) return; const W = 560, H = 300; const canvas = document.createElement('canvas'); canvas.width = W; canvas.height = H; canvas.style.width = '100%'; canvas.style.height = '100%'; canvas.style.display = 'block'; sb.appendChild(canvas); const ctx = canvas.getContext('2d'); const charges = []; let nextSign = 1; function draw(){ ctx.fillStyle = '#fafafa'; ctx.fillRect(0, 0, W, H); /* Forces between pairs */ for (let i = 0; i < charges.length; i++) { for (let j = i + 1; j < charges.length; j++) { const a = charges[i], b = charges[j]; const dx = b.x - a.x, dy = b.y - a.y; const r2 = dx*dx + dy*dy; if (r2 < 100) continue; const r = Math.sqrt(r2); const F = 4e6 * a.sign * b.sign / r2; const fx = F * dx / r, fy = F * dy / r; /* Arrow from a in direction (-fx, -fy) means: force on a from b */ const len = Math.min(80, Math.abs(F) * 5); const dir = a.sign * b.sign > 0 ? -1 : 1; const aex = a.x + dir * fx / Math.abs(F) * len; const aey = a.y + dir * fy / Math.abs(F) * len; ctx.strokeStyle = a.sign * b.sign > 0 ? '#dc2626' : '#16a34a'; ctx.lineWidth = 1.5; ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(aex, aey); ctx.stroke(); /* Arrowhead */ const ang = Math.atan2(aey - a.y, aex - a.x); ctx.beginPath(); ctx.moveTo(aex, aey); ctx.lineTo(aex - 7 * Math.cos(ang - 0.3), aey - 7 * Math.sin(ang - 0.3)); ctx.lineTo(aex - 7 * Math.cos(ang + 0.3), aey - 7 * Math.sin(ang + 0.3)); ctx.closePath(); ctx.fillStyle = ctx.strokeStyle; ctx.fill(); } } /* Charges */ charges.forEach(c => { const color = c.sign > 0 ? '#dc2626' : '#2563eb'; const fill = c.sign > 0 ? '#fecaca' : '#bfdbfe'; ctx.fillStyle = fill; ctx.strokeStyle = color; ctx.lineWidth = 2.5; ctx.beginPath(); ctx.arc(c.x, c.y, 18, 0, 2 * Math.PI); ctx.fill(); ctx.stroke(); ctx.fillStyle = color; ctx.font = "bold 18px sans-serif"; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(c.sign > 0 ? '+' : '−', c.x, c.y + 1); }); document.getElementById('p12-iv6-count').textContent = charges.length; } const drag = P8Drag.attachCanvas(canvas, { objects: charges.map(c => ({ ...c, r: 22 })), onPickup: c => {}, onDrag: (c, pos) => { /* Sync back to charges by id */ const orig = charges.find(ch => ch === c || (ch.id === c.id)); if (orig) { orig.x = pos.x; orig.y = pos.y; } draw(); }, onClick: (pos) => { charges.push({ x: pos.x, y: pos.y, sign: nextSign, id: Date.now() + Math.random() }); drag.updateObjects(charges.map(c => ({ ...c, r: 22 }))); draw(); if (window.addXp && charges.length === 2) addXp(10, 'p12-iv6-first'); } }); document.getElementById('p12-iv6-add-pos').onclick = () => { nextSign = 1; charges.push({ x: 80 + Math.random() * (W - 160), y: 80 + Math.random() * (H - 160), sign: 1, id: Date.now() + Math.random() }); drag.updateObjects(charges.map(c => ({ ...c, r: 22 }))); draw(); }; document.getElementById('p12-iv6-add-neg').onclick = () => { nextSign = -1; charges.push({ x: 80 + Math.random() * (W - 160), y: 80 + Math.random() * (H - 160), sign: -1, id: Date.now() + Math.random() }); drag.updateObjects(charges.map(c => ({ ...c, r: 22 }))); draw(); }; document.getElementById('p12-iv6-clear').onclick = () => { charges.length = 0; drag.updateObjects([]); draw(); }; draw(); } function _initp31_iv5(){ const TASKS = [{"q":"У электромагнита было $N_1 = 100$ витков, его магнитное поле $B_1$. После добавления стало $N_2 = 500$ витков (тот же ток). Во сколько раз вырастет $B$?","ans":5,"tol":0.2,"why":"$B \\propto N$, поэтому $B_2/B_1 = N_2/N_1 = 5$."},{"q":"Ток в катушке вырос с $I_1 = 0{,}2$ А до $I_2 = 1$ А. Во сколько раз увеличилось магнитное поле электромагнита?","ans":5,"tol":0.2,"why":"$B \\propto I$, поэтому $B_2/B_1 = I_2/I_1 = 5$."},{"q":"Без сердечника поле электромагнита $B_0 = 1$ мТл. С железным сердечником стало $B = 1000$ мТл. Во сколько раз сердечник усилил поле?","ans":1000,"tol":10,"why":"Железо имеет магнитную проницаемость $\\mu \\sim 1000$. $B/B_0 = 1000$."},{"q":"Электромагнит подняет груз массой $m = 50$ кг с силой $F = 500$ Н. Какова перегрузка $F/(mg)$? ($g = 10$ м/с²)","ans":1,"tol":0.05,"why":"$F/(mg) = 500/(50 \\cdot 10) = 500/500 = 1$ — сила в точности уравновешивает вес."},{"q":"Если ток отключить, что произойдёт с магн. полем электромагнита? ($1$ — останется, $0$ — исчезнет)","ans":0,"tol":0.1,"why":"Магнитное поле электромагнита создаётся током. Нет тока — нет поля. (В отличие от постоянного магнита.)"}]; let i = 0, ok = 0, awarded = false; function render(){ const t = TASKS[i]; const wrap = document.getElementById('p31-tasks5'); if(!wrap) return; wrap.innerHTML = '
Заряды притягиваются и отталкиваются, образуют электрическое поле. По проводнику течёт ток, и закон Ома связывает $U$, $I$, $R$. У постоянных магнитов и проводников с током есть магнитное поле.