|
@@ -0,0 +1,477 @@
|
|
|
|
|
+document.documentElement.classList.replace('no-js', 'js');
|
|
|
|
|
+
|
|
|
|
|
+/* ===================== УТИЛИТЫ ===================== */
|
|
|
|
|
+const $ = (s, r = document) => r.querySelector(s);
|
|
|
|
|
+const $$ = (s, r = document) => [...r.querySelectorAll(s)];
|
|
|
|
|
+const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
|
|
|
|
|
+const esc = s => String(s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
|
|
|
+
|
|
|
|
|
+/* Палитра «печатного листа» */
|
|
|
|
|
+const INK = '#2b2118', RED = '#b0161a', PAPER = '#f6ecd0', WALL = '#d7bd7c', SOFT = '#6a5a3e';
|
|
|
|
|
+
|
|
|
|
|
+/* Единый цикл анимации: компоненты подключаются и отключаются */
|
|
|
|
|
+const loops = new Map();
|
|
|
|
|
+let lastTs = performance.now();
|
|
|
|
|
+function frame(ts) {
|
|
|
|
|
+ const dt = Math.min((ts - lastTs) / 1000, .05);
|
|
|
|
|
+ lastTs = ts;
|
|
|
|
|
+ loops.forEach(fn => fn(dt));
|
|
|
|
|
+ requestAnimationFrame(frame);
|
|
|
|
|
+}
|
|
|
|
|
+requestAnimationFrame(frame);
|
|
|
|
|
+const addLoop = (name, fn) => loops.set(name, fn);
|
|
|
|
|
+const removeLoop = name => loops.delete(name);
|
|
|
|
|
+
|
|
|
|
|
+/* Холст с учётом плотности пикселей */
|
|
|
|
|
+function setupCanvas(canvas) {
|
|
|
|
|
+ const c = { canvas, ctx: canvas.getContext('2d'), w: 0, h: 0 };
|
|
|
|
|
+ c.resize = () => {
|
|
|
|
|
+ const r = canvas.getBoundingClientRect();
|
|
|
|
|
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
|
|
|
+ canvas.width = Math.max(1, Math.round(r.width * dpr));
|
|
|
|
|
+ canvas.height = Math.max(1, Math.round(r.height * dpr));
|
|
|
|
|
+ c.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
|
|
|
+ c.w = r.width; c.h = r.height;
|
|
|
|
|
+ };
|
|
|
|
|
+ c.resize();
|
|
|
|
|
+ if ('ResizeObserver' in window) new ResizeObserver(c.resize).observe(canvas);
|
|
|
|
|
+ else window.addEventListener('resize', c.resize);
|
|
|
|
|
+ return c;
|
|
|
|
|
+}
|
|
|
|
|
+function say(ctx, s, x, y, color, sz = 10, align = 'left', bold = false) {
|
|
|
|
|
+ ctx.fillStyle = color;
|
|
|
|
|
+ ctx.font = `${bold ? '700 ' : ''}${sz}px "PT Serif", Georgia, serif`;
|
|
|
|
|
+ ctx.textAlign = align; ctx.textBaseline = 'middle';
|
|
|
|
|
+ ctx.fillText(s, x, y);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Короткий звуковой сигнал (только по действию пользователя) */
|
|
|
|
|
+function beep(freq) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!TR.actx) TR.actx = new (window.AudioContext || window.webkitAudioContext)();
|
|
|
|
|
+ const o = TR.actx.createOscillator(), g = TR.actx.createGain();
|
|
|
|
|
+ o.frequency.value = freq;
|
|
|
|
|
+ g.gain.value = .08;
|
|
|
|
|
+ o.connect(g); g.connect(TR.actx.destination);
|
|
|
|
|
+ o.start(); o.stop(TR.actx.currentTime + .12);
|
|
|
|
|
+ } catch (e) { /* звук недоступен: прибор работает без него */ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* ===================== НАВИГАЦИЯ И ПОЯВЛЕНИЕ ===================== */
|
|
|
|
|
+const progressEl = $('#progress');
|
|
|
|
|
+const onScroll = () => {
|
|
|
|
|
+ const max = document.documentElement.scrollHeight - innerHeight;
|
|
|
|
|
+ progressEl.style.transform = `scaleX(${max > 0 ? scrollY / max : 0})`;
|
|
|
|
|
+};
|
|
|
|
|
+addEventListener('scroll', onScroll, { passive: true });
|
|
|
|
|
+onScroll();
|
|
|
|
|
+
|
|
|
|
|
+const revealIO = new IntersectionObserver(entries => entries.forEach(e => {
|
|
|
|
|
+ if (e.isIntersecting) { e.target.classList.add('in'); revealIO.unobserve(e.target); }
|
|
|
|
|
+}), { threshold: .08 });
|
|
|
|
|
+$$('.reveal').forEach(el => revealIO.observe(el));
|
|
|
|
|
+
|
|
|
|
|
+/* ===================== ЖУРНАЛ СРАБАТЫВАНИЙ ===================== */
|
|
|
|
|
+const jList = $('#jList');
|
|
|
|
|
+const jPlace = $('#jPlace');
|
|
|
|
|
+
|
|
|
|
|
+function jEmpty() {
|
|
|
|
|
+ jList.innerHTML = '<li class="jempty">Записей пока нет.</li>';
|
|
|
|
|
+}
|
|
|
|
|
+function jLog(place, status) {
|
|
|
|
|
+ const empty = $('.jempty', jList);
|
|
|
|
|
+ if (empty) empty.remove();
|
|
|
|
|
+ const t = new Date().toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
|
|
|
+ const li = document.createElement('li');
|
|
|
|
|
+ li.innerHTML = `<span class="jt">${t}</span><span class="jp">${esc(place || 'место не указано')}</span><span class="js">${esc(status)}</span>`;
|
|
|
|
|
+ jList.appendChild(li);
|
|
|
|
|
+ jList.scrollTop = jList.scrollHeight; // прокручиваем только сам список, не страницу
|
|
|
|
|
+}
|
|
|
|
|
+function jAdd() {
|
|
|
|
|
+ jLog(jPlace.value.trim(), 'статус демонстрации: ' + $('#flagMetal').textContent.toLowerCase());
|
|
|
|
|
+ jPlace.value = '';
|
|
|
|
|
+}
|
|
|
|
|
+$('#jAdd').addEventListener('click', jAdd);
|
|
|
|
|
+$('#jClear').addEventListener('click', jEmpty);
|
|
|
|
|
+jPlace.addEventListener('keydown', e => { if (e.key === 'Enter') jAdd(); });
|
|
|
|
|
+
|
|
|
|
|
+/* ===================== РАЗДЕЛ IV. ТРЕНАЖЁР ===================== */
|
|
|
|
|
+/*
|
|
|
|
|
+ Учебная модель: катушка движется вдоль стены на высоте h над поверхностью.
|
|
|
|
|
+ Предмет на глубине 2 см, положение 60% длины стены.
|
|
|
|
|
+ Сигнал = min(1, 1.2 / расстояние) × 1/(1 + (h/2)²) × k(скорость).
|
|
|
|
|
+ k(скорость) = 1 до 6 см/с, далее снижается до 0.5 (пропуски слабых предметов).
|
|
|
|
|
+ Порог срабатывания: 0.3.
|
|
|
|
|
+*/
|
|
|
|
|
+const TR_L = 40; // длина стены в тренажёре, см
|
|
|
|
|
+const TR_OBJ = .6; // положение предмета (доля длины)
|
|
|
|
|
+const TR_D = 2; // глубина предмета, см
|
|
|
|
|
+const TR_THR = .3; // порог срабатывания
|
|
|
|
|
+const TR_PX = 8; // пикселей на сантиметр (высота и глубина)
|
|
|
|
|
+
|
|
|
|
|
+const trC = setupCanvas($('#cvTrain'));
|
|
|
|
|
+const TR = {
|
|
|
|
|
+ v: 5, h: 1, x: 0, t: 0,
|
|
|
|
|
+ show: false, snd: false,
|
|
|
|
|
+ marks: [], hover: null,
|
|
|
|
|
+ above: false, lastRead: '', actx: null
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const trAtt = h => 1 / (1 + (h / 2) ** 2);
|
|
|
|
|
+const trSpd = v => v <= 6 ? 1 : Math.max(.5, 1 - (v - 6) * .1);
|
|
|
|
|
+function trSignal(xcm) {
|
|
|
|
|
+ const dx = xcm - TR_OBJ * TR_L;
|
|
|
|
|
+ const dist = Math.hypot(TR_D, dx);
|
|
|
|
|
+ return Math.min(1, 1.2 / dist) * trAtt(TR.h) * trSpd(TR.v);
|
|
|
|
|
+}
|
|
|
|
|
+const fmtCm = v => String(v).replace('.', ',') + ' см';
|
|
|
|
|
+
|
|
|
|
|
+function spdHint() {
|
|
|
|
|
+ const v = TR.v;
|
|
|
|
|
+ $('#spdHint').textContent = v < 3
|
|
|
|
|
+ ? 'Медленно: проверка идёт долго, но сигнал надёжен.'
|
|
|
|
|
+ : v <= 7
|
|
|
|
|
+ ? 'Рекомендуемая зона: 3–7 см/с. Сигнал надёжен, проверка идёт с разумной скоростью.'
|
|
|
|
|
+ : v <= 9
|
|
|
|
|
+ ? 'Быстро: слабые предметы могут быть пропущены.'
|
|
|
|
|
+ : 'Слишком быстро: пропуск предметов вероятен.';
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function updateTrainReadout(s, on) {
|
|
|
|
|
+ let text;
|
|
|
|
|
+ if (TR.hover !== null) {
|
|
|
|
|
+ const sv = trSignal(TR.hover);
|
|
|
|
|
+ text = `Точка ${TR.hover.toFixed(0)} см: ожидаемый сигнал ${sv.toFixed(2)}. ${sv >= TR_THR ? 'Срабатывание.' : 'Ниже порога, не срабатывает.'}`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ text = `Катушка над точкой ${TR.x.toFixed(0)} см: сигнал ${s.toFixed(2)}. ${on ? 'Срабатывание: остановите катушку и отметьте место щелчком по стене.' : 'Ниже порога.'}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TR.h > 2) text += ' Высота больше 2 см: предмет почти не виден.';
|
|
|
|
|
+ if (TR.v >= 8) text += ' Скорость велика: слабые предметы могут быть пропущены.';
|
|
|
|
|
+ if (text !== TR.lastRead) { TR.lastRead = text; $('#trRead').textContent = text; }
|
|
|
|
|
+ const f = $('#trFlag');
|
|
|
|
|
+ f.classList.toggle('on', on);
|
|
|
|
|
+ f.textContent = on ? 'СРАБАТЫВАНИЕ' : 'сигнала нет';
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function drawTrain(dt) {
|
|
|
|
|
+ const { ctx, w, h } = trC;
|
|
|
|
|
+ if (!w) return;
|
|
|
|
|
+ TR.t += dt;
|
|
|
|
|
+ TR.x = (TR.x + TR.v * dt) % TR_L;
|
|
|
|
|
+
|
|
|
|
|
+ const base = h * .3, sc = h * .22, wallY = h * .62;
|
|
|
|
|
+ const toX = cm => cm / TR_L * w;
|
|
|
|
|
+
|
|
|
|
|
+ ctx.fillStyle = PAPER; ctx.fillRect(0, 0, w, h);
|
|
|
|
|
+
|
|
|
|
|
+ /* ожидаемый профиль (верхняя часть) */
|
|
|
|
|
+ ctx.strokeStyle = 'rgba(43,33,24,.22)'; ctx.lineWidth = 1;
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, base); ctx.lineTo(w, base); ctx.stroke();
|
|
|
|
|
+ const yTh = base - TR_THR * sc;
|
|
|
|
|
+ ctx.setLineDash([6, 4]); ctx.strokeStyle = RED; ctx.lineWidth = 1.2;
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, yTh); ctx.lineTo(w, yTh); ctx.stroke(); ctx.setLineDash([]);
|
|
|
|
|
+ say(ctx, 'порог срабатывания', w - 8, yTh - 9, RED, 11, 'right', true);
|
|
|
|
|
+
|
|
|
|
|
+ let peak = 0;
|
|
|
|
|
+ ctx.beginPath();
|
|
|
|
|
+ for (let x = 0; x <= w; x += 2) {
|
|
|
|
|
+ const s = trSignal(x / w * TR_L);
|
|
|
|
|
+ if (s > peak) peak = s;
|
|
|
|
|
+ const y = base - s * sc;
|
|
|
|
|
+ if (x) ctx.lineTo(x, y); else ctx.moveTo(x, y);
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.strokeStyle = peak >= TR_THR ? RED : INK; ctx.lineWidth = 2.4; ctx.stroke();
|
|
|
|
|
+ say(ctx, 'ожидаемый профиль при текущих высоте и скорости', 8, 12, SOFT, 11, 'left', true);
|
|
|
|
|
+
|
|
|
|
|
+ /* стена (нижняя часть) */
|
|
|
|
|
+ ctx.fillStyle = WALL; ctx.fillRect(0, wallY, w, h - wallY);
|
|
|
|
|
+ ctx.strokeStyle = 'rgba(43,33,24,.28)'; ctx.lineWidth = 1;
|
|
|
|
|
+ for (let y = wallY + 12, row = 0; y < h; y += 14, row++) {
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(w, y); ctx.stroke();
|
|
|
|
|
+ for (let x = (row % 2) * 28; x < w; x += 56) { ctx.beginPath(); ctx.moveTo(x, y - 14); ctx.lineTo(x, y); ctx.stroke(); }
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.strokeStyle = INK; ctx.lineWidth = 2;
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, wallY); ctx.lineTo(w, wallY); ctx.stroke();
|
|
|
|
|
+ say(ctx, 'СТЕНА', 8, wallY + 12, INK, 11, 'left', true);
|
|
|
|
|
+
|
|
|
|
|
+ /* предмет (по подсказке) */
|
|
|
|
|
+ if (TR.show) {
|
|
|
|
|
+ const ox = toX(TR_OBJ * TR_L), oy = wallY + TR_D * TR_PX;
|
|
|
|
|
+ ctx.fillStyle = INK;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(ox, oy, 6, 0, Math.PI * 2); ctx.fill();
|
|
|
|
|
+ say(ctx, 'предмет', ox + 10, oy, INK, 11);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* метки, поставленные щелчком */
|
|
|
|
|
+ ctx.strokeStyle = RED; ctx.lineWidth = 2.5;
|
|
|
|
|
+ TR.marks.forEach(m => {
|
|
|
|
|
+ const mxp = toX(m);
|
|
|
|
|
+ ctx.beginPath();
|
|
|
|
|
+ ctx.moveTo(mxp - 6, wallY - 6); ctx.lineTo(mxp + 6, wallY + 6);
|
|
|
|
|
+ ctx.moveTo(mxp + 6, wallY - 6); ctx.lineTo(mxp - 6, wallY + 6);
|
|
|
|
|
+ ctx.stroke();
|
|
|
|
|
+ });
|
|
|
|
|
+ ctx.lineWidth = 1;
|
|
|
|
|
+
|
|
|
|
|
+ /* перекрестие под курсором */
|
|
|
|
|
+ if (TR.hover !== null) {
|
|
|
|
|
+ const hx = toX(TR.hover);
|
|
|
|
|
+ ctx.strokeStyle = 'rgba(43,33,24,.4)'; ctx.setLineDash([3, 3]);
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(hx, 0); ctx.lineTo(hx, h); ctx.stroke();
|
|
|
|
|
+ ctx.setLineDash([]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* катушка и поле, уходящее в стену */
|
|
|
|
|
+ const px = toX(TR.x);
|
|
|
|
|
+ const cy = wallY - TR.h * TR_PX - 12;
|
|
|
|
|
+ for (let i = 0; i < 3; i++) {
|
|
|
|
|
+ const r = 14 + ((TR.t * 40 + i * 8) % 24);
|
|
|
|
|
+ const a = 1 - (r - 14) / 24;
|
|
|
|
|
+ ctx.strokeStyle = `rgba(176,22,26,${(a * .75).toFixed(2)})`; ctx.lineWidth = 1.6;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(px, cy, r, 0, Math.PI); ctx.stroke();
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.lineWidth = 1;
|
|
|
|
|
+ ctx.fillStyle = RED;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(px, cy, 7, 0, Math.PI * 2); ctx.fill();
|
|
|
|
|
+ ctx.strokeStyle = INK; ctx.lineWidth = 2.2;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(px, cy, 12, 0, Math.PI * 2); ctx.stroke();
|
|
|
|
|
+ ctx.lineWidth = 1;
|
|
|
|
|
+ say(ctx, 'высота ' + fmtCm(TR.h), Math.min(px + 18, w - 8), cy, SOFT, 11, px + 18 > w - 8 ? 'right' : 'left');
|
|
|
|
|
+
|
|
|
|
|
+ /* звук при появлении срабатывания */
|
|
|
|
|
+ const s = trSignal(TR.x), on = s >= TR_THR;
|
|
|
|
|
+ if (on && !TR.above && TR.snd) beep(500 + 800 * Math.min(1, s));
|
|
|
|
|
+ TR.above = on;
|
|
|
|
|
+
|
|
|
|
|
+ updateTrainReadout(s, on);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* управление тренажёром */
|
|
|
|
|
+$('#spd').addEventListener('input', e => {
|
|
|
|
|
+ TR.v = +e.target.value;
|
|
|
|
|
+ $('#spdVal').textContent = TR.v + ' см/с';
|
|
|
|
|
+ spdHint();
|
|
|
|
|
+});
|
|
|
|
|
+$('#hgt').addEventListener('input', e => {
|
|
|
|
|
+ TR.h = +e.target.value;
|
|
|
|
|
+ $('#hVal').textContent = fmtCm(TR.h);
|
|
|
|
|
+});
|
|
|
|
|
+$('#trShow').addEventListener('change', e => { TR.show = e.target.checked; });
|
|
|
|
|
+$('#snd').addEventListener('change', e => {
|
|
|
|
|
+ TR.snd = e.target.checked;
|
|
|
|
|
+ if (TR.snd) beep(660); // подтверждение включения звука
|
|
|
|
|
+});
|
|
|
|
|
+$('#trClear').addEventListener('click', () => { TR.marks = []; });
|
|
|
|
|
+
|
|
|
|
|
+/* курсор и щелчок по стене тренажёра */
|
|
|
|
|
+const trCv = $('#cvTrain');
|
|
|
|
|
+const trCmAt = e => {
|
|
|
|
|
+ const r = trCv.getBoundingClientRect();
|
|
|
|
|
+ return clamp((e.clientX - r.left) / r.width * TR_L, 0, TR_L);
|
|
|
|
|
+};
|
|
|
|
|
+trCv.addEventListener('pointermove', e => { TR.hover = trCmAt(e); });
|
|
|
|
|
+trCv.addEventListener('pointerleave', () => { TR.hover = null; });
|
|
|
|
|
+trCv.addEventListener('pointerdown', e => {
|
|
|
|
|
+ const x = trCmAt(e);
|
|
|
|
|
+ TR.marks.push(x);
|
|
|
|
|
+ const sv = trSignal(x);
|
|
|
|
|
+ jLog(`тренажёр, ${x.toFixed(0)} см`,
|
|
|
|
|
+ `метка, сигнал ${sv.toFixed(2)}${sv >= TR_THR ? ' (выше порога)' : ' (ниже порога)'}`);
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+spdHint();
|
|
|
|
|
+addLoop('train', drawTrain);
|
|
|
|
|
+
|
|
|
|
|
+/* ===================== РАЗДЕЛ V. ПРОФИЛЬ СИГНАЛА ===================== */
|
|
|
|
|
+/*
|
|
|
|
|
+ Модель (учебная): катушка движется вдоль поверхности стены.
|
|
|
|
|
+ Сигнал от предмета на глубине D и смещении dx: s = min(1, 12 / sqrt(D² + dx²)).
|
|
|
|
|
+ Труба (или арматура) добавляет ровный сигнал по всей длине участка (+0.35).
|
|
|
|
|
+ Порог срабатывания: 0.3.
|
|
|
|
|
+ Выводы делаются только по ПОЛНОМУ проходу катушки (последний завершённый).
|
|
|
|
|
+*/
|
|
|
|
|
+const MD_L = 300; // длина участка, мм
|
|
|
|
|
+const MD_X0 = 150; // положение предмета по X, мм
|
|
|
|
|
+const MD_SPEED = 40; // скорость катушки, мм/с
|
|
|
|
|
+const MD_THR = .3; // порог срабатывания
|
|
|
|
|
+const MD_PIPE_D = 15; // глубина трубы, мм
|
|
|
|
|
+const MD_PIPE_ADD = .35; // вклад трубы в сигнал
|
|
|
|
|
+
|
|
|
|
|
+const mdC = setupCanvas($('#cvMetal'));
|
|
|
|
|
+const MD = {
|
|
|
|
|
+ depth: 30, obj: true, pipe: false, showObj: false,
|
|
|
|
|
+ t: 0, prevX: 0, lastIdx: -1,
|
|
|
|
|
+ cur: null, // профиль текущего прохода
|
|
|
|
|
+ full: null, // профиль последнего полного прохода
|
|
|
|
|
+ W: 0, lastRead: ''
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+function mdSignal(xmm) {
|
|
|
|
|
+ const dx = xmm - MD_X0, D = MD.depth;
|
|
|
|
|
+ let s = MD.obj ? Math.min(1, 12 / Math.sqrt(D * D + dx * dx)) : 0;
|
|
|
|
|
+ if (MD.pipe) s += MD_PIPE_ADD;
|
|
|
|
|
+ return s;
|
|
|
|
|
+}
|
|
|
|
|
+const mdDepthY = (face, h, mm) => face + mm / 100 * (h - face);
|
|
|
|
|
+
|
|
|
|
|
+function mdReset() {
|
|
|
|
|
+ if (MD.cur) MD.cur.fill(NaN);
|
|
|
|
|
+ MD.lastIdx = -1;
|
|
|
|
|
+ MD.full = null;
|
|
|
|
|
+ MD.lastRead = '';
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Профиль -> максимум и покрытие */
|
|
|
|
|
+function profStats(arr) {
|
|
|
|
|
+ let mx = 0, n = 0;
|
|
|
|
|
+ for (let x = 0; x < arr.length; x++) {
|
|
|
|
|
+ const v = arr[x];
|
|
|
|
|
+ if (!Number.isNaN(v)) { n++; if (v > mx) mx = v; }
|
|
|
|
|
+ }
|
|
|
|
|
+ return { mx, coverage: n / arr.length };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function drawMetal(dt) {
|
|
|
|
|
+ const { ctx, w, h } = mdC;
|
|
|
|
|
+ if (!w) return;
|
|
|
|
|
+ const W = Math.floor(w);
|
|
|
|
|
+ if (!MD.cur || MD.W !== W) { MD.cur = new Float32Array(W).fill(NaN); MD.W = W; MD.full = null; MD.lastIdx = -1; }
|
|
|
|
|
+
|
|
|
|
|
+ MD.t += dt;
|
|
|
|
|
+ const xmm = (MD.t * MD_SPEED) % MD_L;
|
|
|
|
|
+ // заполняем все пиксели между предыдущим и текущим положением катушки,
|
|
|
|
|
+ // чтобы при низкой частоте кадров в профиле не было пропусков
|
|
|
|
|
+ const fillTo = (from, to) => {
|
|
|
|
|
+ for (let i = Math.max(0, from); i <= Math.min(W - 1, to); i++) {
|
|
|
|
|
+ MD.cur[i] = mdSignal((i + .5) / W * MD_L);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ if (xmm < MD.prevX) { // начался новый проход
|
|
|
|
|
+ fillTo(MD.lastIdx + 1, W - 1);
|
|
|
|
|
+ if (profStats(MD.cur).coverage >= .98) MD.full = Float32Array.from(MD.cur);
|
|
|
|
|
+ MD.cur.fill(NaN);
|
|
|
|
|
+ MD.lastIdx = -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ MD.prevX = xmm;
|
|
|
|
|
+ const idx = clamp(Math.floor(xmm / MD_L * w), 0, W - 1);
|
|
|
|
|
+ fillTo(MD.lastIdx + 1, idx);
|
|
|
|
|
+ MD.lastIdx = Math.max(MD.lastIdx, idx);
|
|
|
|
|
+ const px = xmm / MD_L * w;
|
|
|
|
|
+
|
|
|
|
|
+ /* фон листа */
|
|
|
|
|
+ ctx.fillStyle = PAPER; ctx.fillRect(0, 0, w, h);
|
|
|
|
|
+ const face = h * .5;
|
|
|
|
|
+
|
|
|
|
|
+ /* график сигнала (верхняя половина) */
|
|
|
|
|
+ const base = h * .4, sc = h * .32;
|
|
|
|
|
+ ctx.strokeStyle = 'rgba(43,33,24,.22)'; ctx.lineWidth = 1;
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, base); ctx.lineTo(w, base); ctx.stroke();
|
|
|
|
|
+ const yTh = base - MD_THR * sc;
|
|
|
|
|
+ ctx.setLineDash([6, 4]); ctx.strokeStyle = RED; ctx.lineWidth = 1.2;
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, yTh); ctx.lineTo(w, yTh); ctx.stroke(); ctx.setLineDash([]);
|
|
|
|
|
+ say(ctx, 'порог срабатывания', w - 8, yTh - 9, RED, 11, 'right', true);
|
|
|
|
|
+
|
|
|
|
|
+ const drawProf = (arr, color, lw) => {
|
|
|
|
|
+ ctx.beginPath(); let started = false;
|
|
|
|
|
+ for (let x = 0; x < W; x++) {
|
|
|
|
|
+ const v = arr[x];
|
|
|
|
|
+ if (Number.isNaN(v)) { started = false; continue; }
|
|
|
|
|
+ const y = base - v * sc;
|
|
|
|
|
+ if (!started) { ctx.moveTo(x, y); started = true; } else ctx.lineTo(x, y);
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.strokeStyle = color; ctx.lineWidth = lw; ctx.stroke();
|
|
|
|
|
+ };
|
|
|
|
|
+ drawProf(MD.cur, 'rgba(43,33,24,.4)', 1.4); // текущий проход
|
|
|
|
|
+ if (MD.full) {
|
|
|
|
|
+ const fs = profStats(MD.full);
|
|
|
|
|
+ drawProf(MD.full, fs.mx >= MD_THR ? RED : INK, 2.6); // последний полный проход
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.strokeStyle = 'rgba(43,33,24,.45)'; ctx.lineWidth = 1;
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(px, 0); ctx.lineTo(px, base + 6); ctx.stroke();
|
|
|
|
|
+ say(ctx, 'СИГНАЛ ПРИЁМНИКА', 8, 12, SOFT, 11, 'left', true);
|
|
|
|
|
+
|
|
|
|
|
+ /* стена (нижняя половина) */
|
|
|
|
|
+ ctx.fillStyle = WALL; ctx.fillRect(0, face, w, h - face);
|
|
|
|
|
+ ctx.strokeStyle = 'rgba(43,33,24,.28)'; ctx.lineWidth = 1;
|
|
|
|
|
+ for (let y = face + 12, row = 0; y < h; y += 14, row++) {
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(w, y); ctx.stroke();
|
|
|
|
|
+ for (let x = (row % 2) * 28; x < w; x += 56) { ctx.beginPath(); ctx.moveTo(x, y - 14); ctx.lineTo(x, y); ctx.stroke(); }
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.strokeStyle = INK; ctx.lineWidth = 2;
|
|
|
|
|
+ ctx.beginPath(); ctx.moveTo(0, face); ctx.lineTo(w, face); ctx.stroke();
|
|
|
|
|
+ say(ctx, 'СТЕНА', 8, face + 12, INK, 11, 'left', true);
|
|
|
|
|
+ say(ctx, '0 мм', w - 8, face + 12, INK, 11, 'right');
|
|
|
|
|
+
|
|
|
|
|
+ /* труба */
|
|
|
|
|
+ if (MD.pipe) {
|
|
|
|
|
+ const py = mdDepthY(face, h, MD_PIPE_D);
|
|
|
|
|
+ const grd = ctx.createLinearGradient(0, py - 4, 0, py + 4);
|
|
|
|
|
+ grd.addColorStop(0, '#9a8a66'); grd.addColorStop(1, INK);
|
|
|
|
|
+ ctx.fillStyle = grd; ctx.fillRect(0, py - 4, w, 8);
|
|
|
|
|
+ say(ctx, 'труба / арматура', w - 8, py + 15, INK, 11, 'right');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* предмет (для наглядности, по желанию) */
|
|
|
|
|
+ if (MD.showObj && MD.obj) {
|
|
|
|
|
+ const ox = MD_X0 / MD_L * w, oy = mdDepthY(face, h, MD.depth);
|
|
|
|
|
+ ctx.fillStyle = INK;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(ox, oy, 6, 0, Math.PI * 2); ctx.fill();
|
|
|
|
|
+ say(ctx, 'предмет', ox + 10, oy, INK, 11);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* катушка и поле, уходящее в стену */
|
|
|
|
|
+ for (let i = 0; i < 3; i++) {
|
|
|
|
|
+ const r = 14 + ((MD.t * 40 + i * 8) % 24);
|
|
|
|
|
+ const a = 1 - (r - 14) / 24;
|
|
|
|
|
+ ctx.strokeStyle = `rgba(176,22,26,${(a * .75).toFixed(2)})`; ctx.lineWidth = 1.6;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(px, face, r, 0, Math.PI); ctx.stroke();
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.lineWidth = 1;
|
|
|
|
|
+ ctx.fillStyle = RED;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(px, face, 7, 0, Math.PI * 2); ctx.fill();
|
|
|
|
|
+ ctx.strokeStyle = INK; ctx.lineWidth = 2.2;
|
|
|
|
|
+ ctx.beginPath(); ctx.arc(px, face, 12, 0, Math.PI * 2); ctx.stroke();
|
|
|
|
|
+ ctx.lineWidth = 1;
|
|
|
|
|
+
|
|
|
|
|
+ updateMetalReadout();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Вывод строится только по последнему полному проходу */
|
|
|
|
|
+function updateMetalReadout() {
|
|
|
|
|
+ let text, on = false, flagText;
|
|
|
|
|
+ if (!MD.full) {
|
|
|
|
|
+ text = 'Идёт первый проход катушки. Дождитесь полного прохода: по неполному профилю выводы делать нельзя.';
|
|
|
|
|
+ flagText = 'сканирование…';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const { mx } = profStats(MD.full);
|
|
|
|
|
+ let above = 0;
|
|
|
|
|
+ for (let x = 0; x < MD.W; x++) if (!Number.isNaN(MD.full[x]) && MD.full[x] >= MD_THR) above++;
|
|
|
|
|
+ const widthMm = Math.round(above / MD.W * MD_L);
|
|
|
|
|
+ on = mx >= MD_THR;
|
|
|
|
|
+ if (!on) {
|
|
|
|
|
+ text = `Максимум ${mx.toFixed(2)}: ниже порога ${MD_THR}. Металл на этой глубине не обнаружен, либо он далеко от катушки.`;
|
|
|
|
|
+ } else if (widthMm > 120) {
|
|
|
|
|
+ text = `Максимум ${mx.toFixed(2)}. Широкий ровный сигнал (${widthMm} мм) — характерно для трубы или арматуры.`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ text = `Максимум ${mx.toFixed(2)}. Узкий пик (${widthMm} мм) — характерно для небольшого металлического предмета.`;
|
|
|
|
|
+ }
|
|
|
|
|
+ text += ' Срабатывание не доказывает наличие средства съёма: металл есть в проводке, креплениях и технике.';
|
|
|
|
|
+ flagText = on ? 'СИГНАЛ ВЫШЕ ПОРОГА: ПРОВЕРИТЬ' : 'признаков нет';
|
|
|
|
|
+ }
|
|
|
|
|
+ if (text !== MD.lastRead) { MD.lastRead = text; $('#mdRead').textContent = text; }
|
|
|
|
|
+ const flag = $('#flagMetal');
|
|
|
|
|
+ flag.classList.toggle('on', on);
|
|
|
|
|
+ flag.textContent = flagText;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function mdChanged() { mdReset(); }
|
|
|
|
|
+$('#depth').addEventListener('input', e => {
|
|
|
|
|
+ MD.depth = +e.target.value;
|
|
|
|
|
+ $('#depthVal').textContent = MD.depth + ' мм';
|
|
|
|
|
+ mdChanged();
|
|
|
|
|
+});
|
|
|
|
|
+$('#obj').addEventListener('change', e => { MD.obj = e.target.checked; mdChanged(); });
|
|
|
|
|
+$('#pipe').addEventListener('change', e => { MD.pipe = e.target.checked; mdChanged(); });
|
|
|
|
|
+$('#showObj').addEventListener('change', e => { MD.showObj = e.target.checked; });
|
|
|
|
|
+
|
|
|
|
|
+addLoop('metal', drawMetal);
|