index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <!DOCTYPE html>
  2. <html lang="ru">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Датчик "Стекло-1" // Охрана</title>
  7. <style>
  8. :root {
  9. --bg: #2c2c2c; --panel: #1a1a1a; --metal: #444;
  10. --text: #33ff00; --red: #ff2222; --dim: #1f4d1f;
  11. }
  12. body {
  13. background: var(--bg); color: var(--text);
  14. font-family: 'Courier New', monospace;
  15. display: flex; justify-content: center; padding: 20px; margin: 0;
  16. }
  17. .console {
  18. background: var(--panel); border: 8px solid var(--metal);
  19. border-radius: 12px; width: 100%; max-width: 650px;
  20. padding: 20px; box-shadow: 0 15px 30px rgba(0,0,0,0.8), inset 0 0 20px #000;
  21. }
  22. h1 { text-align: center; font-size: 18px; border-bottom: 2px solid var(--dim); padding-bottom: 10px; text-transform: uppercase; letter-spacing: 2px; }
  23. .scene { display: none; flex-direction: column; gap: 15px; }
  24. .scene.active { display: flex; }
  25. .screen {
  26. background: #0a1a0a; border: 2px solid var(--dim); padding: 15px;
  27. border-radius: 4px; box-shadow: inset 0 0 15px #000; min-height: 120px;
  28. }
  29. .row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
  30. .value { font-size: 22px; font-weight: bold; }
  31. .led { width: 16px; height: 16px; border-radius: 50%; background: #333; border: 1px solid #000; transition: 0.1s; }
  32. .led.on { background: var(--red); box-shadow: 0 0 15px var(--red); }
  33. input[type=range] { width: 100%; accent-color: var(--text); cursor: pointer; }
  34. button {
  35. background: #333; color: var(--text); border: 2px solid var(--dim);
  36. padding: 10px; font-family: inherit; font-weight: bold;
  37. text-transform: uppercase; cursor: pointer; margin-bottom: 5px;
  38. }
  39. button:active { background: var(--dim); }
  40. button:disabled { opacity: 0.5; cursor: not-allowed; }
  41. canvas { width: 100%; height: 100px; background: #000; display: block; margin-top: 10px; border: 1px solid var(--dim); }
  42. .formula { font-size: 11px; color: #666; margin-top: 15px; border-top: 1px dashed #444; padding-top: 10px; }
  43. .question { margin-bottom: 15px; }
  44. .question label { display: block; margin-bottom: 5px; cursor: pointer; }
  45. </style>
  46. </head>
  47. <body>
  48. <div class="console">
  49. <h1>Акустический датчик "Стекло-1"</h1>
  50. <div id="scene1" class="scene active">
  51. <div class="screen">
  52. <p>СИСТЕМА ОХРАНЫ МУЗЕЯ АКТИВИРОВАНА.</p>
  53. <p>Вам необходимо настроить порог чувствительности акустического датчика. Он должен игнорировать шаги и голоса, но реагировать на разбитие стекла.</p>
  54. </div>
  55. <button onclick="initAudio(); nextScene(2)">▶ ВОЙТИ В РЕЖИМ НАСТРОЙКИ</button>
  56. </div>
  57. <div id="scene2" class="scene">
  58. <div class="screen">
  59. <div class="row">
  60. <span>ПОРОГ СРАБАТЫВАНИЯ:</span>
  61. <span class="value" id="thrVal">50</span> дБ
  62. </div>
  63. <input type="range" id="threshold" min="40" max="80" value="50" oninput="updateThreshold()">
  64. <canvas id="oscilloscope" width="600" height="100"></canvas>
  65. <div class="row" style="margin-top: 15px;">
  66. <span>ТРЕВОГА:</span>
  67. <div class="led" id="alarmLed"></div>
  68. </div>
  69. </div>
  70. <button onclick="triggerSound('steps')">Симулировать ШАГИ (1 кГц, 45 дБ)</button>
  71. <button onclick="triggerSound('scream')">Симулировать КРИК (2 кГц, 70 дБ)</button>
  72. <button onclick="triggerSound('glass')">Симулировать РАЗБИТИЕ СТЕКЛА (4 кГц + 200 Гц)</button>
  73. <div class="formula">
  74. <div>[ЛОГИКА] Тревога = (Пик_ВЧ > Порог) И (Есть_НЧ_Удар)</div>
  75. <div>[ФИЗИКА] Стекло: ВЧ-треск (3-5 кГц) + НЧ-гул (&lt;500 Гц)</div>
  76. </div>
  77. <button onclick="nextScene(3)">ЗАВЕРШИТЬ НАСТРОЙКУ ▶</button>
  78. </div>
  79. <div id="scene3" class="scene">
  80. <div class="screen" id="testContainer">
  81. <h3>ИТОГОВЫЙ ТЕСТ</h3>
  82. </div>
  83. <button onclick="checkTest()">ПРОВЕРИТЬ</button>
  84. </div>
  85. </div>
  86. <script>
  87. let audioCtx, threshold = 50;
  88. let canvas, ctx;
  89. let animationId;
  90. function initAudio() {
  91. audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  92. canvas = document.getElementById('oscilloscope');
  93. ctx = canvas.getContext('2d');
  94. drawScope(0); // Инициализация пустого экрана
  95. }
  96. function nextScene(n) {
  97. document.querySelectorAll('.scene').forEach(el => el.classList.remove('active'));
  98. document.getElementById('scene' + n).classList.add('active');
  99. if (n === 3) renderTest();
  100. }
  101. function updateThreshold() {
  102. threshold = parseInt(document.getElementById('threshold').value);
  103. document.getElementById('thrVal').innerText = threshold;
  104. }
  105. // Отрисовка осциллографа
  106. function drawScope(amplitude, freq = 0) {
  107. if (animationId) cancelAnimationFrame(animationId);
  108. let x = 0;
  109. ctx.clearRect(0, 0, canvas.width, canvas.height);
  110. ctx.beginPath();
  111. ctx.strokeStyle = '#33ff00';
  112. ctx.lineWidth = 2;
  113. function draw() {
  114. ctx.clearRect(0, 0, canvas.width, canvas.height);
  115. ctx.beginPath();
  116. for (let i = 0; i < canvas.width; i++) {
  117. let y = canvas.height / 2 + Math.sin(i * freq + x) * amplitude;
  118. if (i === 0) ctx.moveTo(i, y);
  119. else ctx.lineTo(i, y);
  120. }
  121. ctx.stroke();
  122. x += 0.2;
  123. animationId = requestAnimationFrame(draw);
  124. }
  125. draw();
  126. }
  127. // --- СИНТЕЗ ЗВУКА И ЛОГИКА ---
  128. function triggerSound(type) {
  129. if (audioCtx.state === 'suspended') audioCtx.resume();
  130. const now = audioCtx.currentTime;
  131. document.getElementById('alarmLed').classList.remove('on');
  132. if (type === 'steps') {
  133. // Шаги: низкий стук, 45 дБ, 1 кГц
  134. drawScope(10, 0.05);
  135. playBeep(1000, 0.1, 0.1); // 1 кГц, тихо
  136. // Тревоги нет, так как 45 < threshold (даже если 40, нет ВЧ профиля)
  137. }
  138. else if (type === 'scream') {
  139. // Крик: громко, но не стекло
  140. drawScope(40, 0.1);
  141. playBeep(2000, 0.5, 0.5); // 2 кГц, громко
  142. // ИИ-ОШИБКА (исправлено): Проверяем только ВЧ-профиль стекла
  143. if (threshold <= 50) {
  144. // Если порог слишком низкий, датчик ошибочно сработает
  145. triggerAlarm();
  146. }
  147. }
  148. else if (type === 'glass') {
  149. // Стекло: ВЧ треск + НЧ удар
  150. drawScope(60, 0.3);
  151. // Синтез ВЧ (треск)
  152. const bufferSize = audioCtx.sampleRate * 0.2;
  153. const buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate);
  154. const data = buffer.getChannelData(0);
  155. for (let i = 0; i < bufferSize; i++) data[i] = Math.random() * 2 - 1;
  156. const noise = audioCtx.createBufferSource();
  157. noise.buffer = buffer;
  158. const hpFilter = audioCtx.createBiquadFilter();
  159. hpFilter.type = 'highpass';
  160. hpFilter.frequency.value = 3000;
  161. noise.connect(hpFilter); hpFilter.connect(audioCtx.destination);
  162. noise.start(now);
  163. // Синтез НЧ (удар)
  164. const osc = audioCtx.createOscillator();
  165. osc.frequency.setValueAtTime(150, now);
  166. osc.frequency.exponentialRampToValueAtTime(50, now + 0.2);
  167. osc.connect(audioCtx.destination);
  168. osc.start(now);
  169. osc.stop(now + 0.2);
  170. // Проверка логики (у нас всегда ВЧ+НЧ, так что если порог <= 60, сработает)
  171. if (threshold <= 60) {
  172. triggerAlarm();
  173. }
  174. }
  175. }
  176. function playBeep(freq, duration, vol) {
  177. const osc = audioCtx.createOscillator();
  178. const gain = audioCtx.createGain();
  179. osc.frequency.value = freq;
  180. gain.gain.setValueAtTime(vol, audioCtx.currentTime);
  181. gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + duration);
  182. osc.connect(gain); gain.connect(audioCtx.destination);
  183. osc.start(); osc.stop(audioCtx.currentTime + duration);
  184. }
  185. function triggerAlarm() {
  186. document.getElementById('alarmLed').classList.add('on');
  187. // Звук сирены
  188. playBeep(800, 0.5, 0.2);
  189. setTimeout(() => playBeep(1000, 0.5, 0.2), 200);
  190. }
  191. const questions = [
  192. { q: "Почему датчик не срабатывает на шаги?", a: ["Они слишком тихие", "У них нет высокочастотного профиля стекла", "Они низкие"], c: 1 },
  193. { q: "Из каких двух фаз состоит звук разбития стекла?", a: ["Свист и гул", "Высокочастотный треск и низкочастотный удар", "Только треск"], c: 1 },
  194. { q: "Что произойдет, если поставить порог на 40 дБ?", a: ["Датчик перестанет работать", "Датчик будет реагировать на громкий крик (ложное срабатывание)", "Ничего не изменится"], c: 1 },
  195. { q: "Зачем нужен НЧ-фильтр в датчике?", a: ["Чтобы отсечь крик", "Чтобы поймать удар от стекла", "Для красоты"], c: 1 },
  196. { q: "Что означает 'ложное срабатывание'?", a: ["Датчик сломался", "Тревога без реальной угрозы", "Отключение питания"], c: 1 }
  197. ];
  198. function renderTest() {
  199. let html = '';
  200. questions.forEach((item, i) => {
  201. html += `<div class="question"><p><b>${i+1}. ${item.q}</b></p>`;
  202. item.a.forEach((ans, j) => {
  203. html += `<label><input type="radio" name="q${i}" value="${j}"> ${ans}</label>`;
  204. });
  205. html += `</div>`;
  206. });
  207. document.getElementById('testContainer').innerHTML = `<h3>ИТОГОВЫЙ ТЕСТ</h3>` + html;
  208. }
  209. function checkTest() {
  210. let score = 0;
  211. questions.forEach((item, i) => {
  212. const selected = document.querySelector(`input[name="q${i}"]:checked`);
  213. if (selected && parseInt(selected.value) === item.c) score++;
  214. });
  215. alert(`Результат: ${score} из ${questions.length}. ${score === 5 ? 'Допуск к службе охраны получен.' : 'Требуется повторный инструктаж.'}`);
  216. }
  217. </script>
  218. </body>
  219. </html>