index.html 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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>HarmoniX | Волновой Спектр</title>
  7. <style>
  8. :root {
  9. --bg-color: #fdfaf6;
  10. --panel-bg: rgba(255, 255, 255, 0.85);
  11. --text-color: #333;
  12. --border-color: rgba(204, 204, 204, 0.6);
  13. --accent: #4CAF50;
  14. --base-wave: #2196F3;
  15. --btn-glow: rgba(76, 175, 80, 0.6);
  16. --canvas-bg: rgba(250, 250, 250, 0.9);
  17. }
  18. [data-theme="dark"] { --bg-color: #121212; --panel-bg: rgba(30, 30, 30, 0.85); --text-color: #eee; --border-color: rgba(80, 80, 80, 0.6); --accent: #bb86fc; --base-wave: #03dac6; --btn-glow: rgba(187, 134, 252, 0.6); --canvas-bg: rgba(44, 44, 44, 0.9); }
  19. [data-theme="neon"] { --bg-color: #000016; --panel-bg: rgba(10, 10, 30, 0.85); --text-color: #0ff; --border-color: rgba(255, 0, 255, 0.6); --accent: #f0f; --base-wave: #0ff; --btn-glow: rgba(255, 0, 255, 0.8); --canvas-bg: rgba(0, 0, 0, 0.9); }
  20. /* Строгий запрет скролла. Приложение всегда 100% экрана */
  21. body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: var(--text-color); }
  22. #bg-layer { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--bg-color); background-size: cover; background-position: center; z-index: -2; transition: filter 0.3s, background-image 0.5s ease-in-out; }
  23. .gradient-text { background: linear-gradient(45deg, #ff00cc, #3333ff, #00ffcc, #ff00cc); background-size: 300% 300%; -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation: gradientFlow 5s ease infinite; font-weight: bold; }
  24. @keyframes gradientFlow { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
  25. #welcome-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; background: var(--bg-color); z-index: 1000; transition: opacity 0.5s; }
  26. .logo { font-size: 80px; margin-bottom: 20px; text-shadow: 0 0 30px rgba(0, 212, 255, 0.5); }
  27. .app-title { font-size: 56px; margin: 0; }
  28. .app-subtitle { font-size: 20px; color: var(--text-color); margin-bottom: 40px; opacity: 0.8; }
  29. .btn, .quiz-option, .tab, .sidebar-link { transition: all 0.2s ease; cursor: pointer; }
  30. .btn:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 4px 12px var(--btn-glow); filter: brightness(1.1); }
  31. .btn:active { transform: scale(0.95); box-shadow: none; }
  32. .btn-enter { padding: 15px 40px; font-size: 22px; font-weight: bold; color: #fff; background: linear-gradient(45deg, #ff00cc, #3333ff); border: none; border-radius: 30px; box-shadow: 0 0 20px rgba(51, 51, 255, 0.6); }
  33. #main-app { display: none; padding: 15px; box-sizing: border-box; height: 100%; flex-direction: column; }
  34. /* --- БОКОВАЯ ПАНЕЛЬ И НАВИГАЦИЯ --- */
  35. .top-bar { display: flex; align-items: center; gap: 15px; padding: 5px 10px; margin-bottom: 10px; flex-shrink: 0; }
  36. .menu-btn { font-size: 28px; background: var(--panel-bg); border: 1px solid var(--border-color); color: var(--text-color); cursor: pointer; transition: 0.3s; padding: 5px 15px; border-radius: 8px; backdrop-filter: blur(10px); }
  37. .menu-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
  38. .nav-logo { font-size: 28px; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 5px 15px; background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 8px; backdrop-filter: blur(10px); }
  39. #sidebar {
  40. position: fixed; left: -320px; top: 0; width: 300px; height: 100%; background: var(--panel-bg);
  41. box-shadow: 5px 0 20px rgba(0,0,0,0.3); backdrop-filter: blur(15px); z-index: 2000;
  42. transition: left 0.3s ease; padding: 20px; box-sizing: border-box; overflow-y: auto; display: flex; flex-direction: column;
  43. }
  44. #sidebar.open { left: 0; }
  45. .sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; }
  46. .close-sidebar { font-size: 30px; cursor: pointer; color: var(--text-color); transition: 0.2s; }
  47. .close-sidebar:hover { color: #f44336; transform: scale(1.1); }
  48. .sidebar-section { margin-bottom: 25px; }
  49. .sidebar-title { font-size: 14px; text-transform: uppercase; color: var(--accent); margin-bottom: 10px; letter-spacing: 1px; }
  50. .sidebar-link { padding: 10px; border-radius: 6px; margin-bottom: 5px; font-weight: bold; background: var(--canvas-bg); border: 1px solid var(--border-color); }
  51. .sidebar-link:hover { background: var(--accent); color: white; transform: translateX(5px); }
  52. .setting-block { margin-bottom: 15px; }
  53. .setting-block label { display: block; margin-bottom: 8px; font-weight: bold; font-size: 14px; }
  54. .setting-block select, .setting-block input[type="file"] { width: 100%; padding: 8px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--canvas-bg); color: var(--text-color); cursor: pointer; }
  55. #sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); z-index: 1999; backdrop-filter: blur(3px); }
  56. /* --- ИДЕАЛЬНАЯ АДАПТИВНАЯ СЕТКА ГРАФИКОВ --- */
  57. .grid-container {
  58. display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 15px;
  59. flex-grow: 1; min-height: 0; /* min-height: 0 позволяет сетке сжиматься */
  60. }
  61. .panel {
  62. background: var(--panel-bg); border: 1px solid var(--border-color); padding: 15px; border-radius: 8px;
  63. display: flex; flex-direction: column; backdrop-filter: blur(10px); min-height: 0;
  64. }
  65. .panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-shrink: 0; }
  66. /* Враппер подстраивается под оставшееся место, а canvas занимает 100% абсолютно */
  67. .canvas-wrapper { flex-grow: 1; position: relative; width: 100%; min-height: 0; background: var(--canvas-bg); border: 1px solid var(--border-color); border-radius: 4px; overflow: hidden; }
  68. canvas { display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
  69. .tabs { display: flex; gap: 5px; margin: 10px 0; flex-shrink: 0; }
  70. .tab { padding: 6px 12px; border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-color); background: var(--canvas-bg); }
  71. .tab:hover { background: rgba(128,128,128,0.1); }
  72. .tab.active { background: var(--accent); color: #fff; font-weight: bold; border-color: var(--accent); }
  73. .control-row { margin-bottom: 8px; display: flex; align-items: center; flex-shrink: 0; }
  74. .control-row label { display: inline-block; width: 120px; font-weight: bold; font-size: 14px; }
  75. input[type=range] { flex-grow: 1; margin-right: 15px; cursor: pointer; }
  76. .btn { padding: 8px 15px; border: none; border-radius: 4px; font-weight: bold; color: white; margin-right: 5px; margin-bottom: 5px; flex-shrink: 0; }
  77. .btn-audio { background: #2196F3; } .btn-dist { background: #9C27B0; } .btn-reset { background: #607D8B; } .btn-test { background: #FF9800; } .btn-icon { background: transparent; border: 1px solid var(--border-color); color: var(--text-color); padding: 5px 10px; font-size: 12px; }
  78. .btn-audio.active { background: #f44336; } .btn-dist.active { background: #d32f2f; }
  79. /* Подвал */
  80. .app-footer { text-align: center; font-size: 12px; opacity: 0.6; padding-top: 10px; flex-shrink: 0; font-weight: bold; }
  81. /* --- ТЕСТИРОВАНИЕ --- */
  82. .modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 2000; justify-content: center; align-items: center; backdrop-filter: blur(8px); }
  83. .modal-content { background: var(--bg-color); padding: 30px; border-radius: 12px; width: 700px; max-width: 95%; max-height: 85vh; overflow-y: auto; border: 2px solid var(--accent); position: relative; }
  84. .test-modes { display: flex; gap: 15px; justify-content: center; margin-top: 30px; }
  85. .test-modes .btn { font-size: 18px; padding: 15px 25px; flex: 1; }
  86. .btn-easy { background: #4CAF50; } .btn-medium { background: #FF9800; } .btn-hard { background: #f44336; }
  87. .question { margin-bottom: 20px; background: var(--panel-bg); padding: 15px; border-radius: 8px; border: 1px solid var(--border-color); }
  88. .question p { font-weight: bold; margin-top: 0; margin-bottom: 15px; font-size: 16px; }
  89. .quiz-option { display: block; padding: 12px; margin-bottom: 8px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--canvas-bg); }
  90. .quiz-option:hover { transform: translateX(8px); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
  91. .quiz-option input { margin-right: 10px; transform: scale(1.2); }
  92. .quiz-option.correct { background-color: rgba(76, 175, 80, 0.4); border-color: #4CAF50; color: #fff; box-shadow: 0 0 12px rgba(76, 175, 80, 0.5); }
  93. .quiz-option.wrong { background-color: rgba(244, 67, 54, 0.4); border-color: #f44336; color: #fff; box-shadow: 0 0 12px rgba(244, 67, 54, 0.5); }
  94. #test-result { margin-top: 20px; font-size: 22px; font-weight: bold; text-align: center; opacity: 0; transition: opacity 0.5s; }
  95. .test-controls { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
  96. </style>
  97. </head>
  98. <body onload="document.getElementById('main-app').style.display='none';">
  99. <div id="bg-layer"></div>
  100. <div id="sidebar-overlay" onclick="toggleSidebar()"></div>
  101. <!-- ВХОД -->
  102. <div id="welcome-screen">
  103. <div class="logo">🌊</div>
  104. <h1 class="app-title gradient-text">HarmoniX</h1>
  105. <h2 class="app-subtitle">Механические волны и Спектр Фурье</h2>
  106. <button class="btn-enter" onclick="startApp()">Начать работу</button>
  107. </div>
  108. <!-- БОКОВАЯ ПАНЕЛЬ -->
  109. <div id="sidebar">
  110. <div class="sidebar-header">
  111. <h2 class="gradient-text" style="margin:0;">Настройки</h2>
  112. <div class="close-sidebar" onclick="toggleSidebar()">&times;</div>
  113. </div>
  114. <div class="sidebar-section">
  115. <h3 class="sidebar-title">📌 Навигация сайта</h3>
  116. <div class="sidebar-link" onclick="toggleSidebar()">🏠 Главная панель</div>
  117. <div class="sidebar-link" onclick="openTestMenu(); toggleSidebar()">📝 Итоговое Тестирование</div>
  118. <div class="sidebar-link" onclick="alert('Справочник формул: \ny = A*cos(wt+θ)\nT = 1/V\nw = 2πV'); playUISound('click')">📚 Справочник формул</div>
  119. <div class="sidebar-link" onclick="alert('HarmoniX Версия 2.6\nИнтерактивное образовательное PWA приложение.'); playUISound('click')">ℹ️ О проекте</div>
  120. </div>
  121. <div class="sidebar-section">
  122. <h3 class="sidebar-title">🎨 Внешний вид</h3>
  123. <div class="setting-block">
  124. <label>Тема интерфейса:</label>
  125. <select onchange="changeTheme(this.value)">
  126. <option value="default">Светлая (Базовая)</option>
  127. <option value="dark">Темная (Ночная)</option>
  128. <option value="neon">Неон (Киберпанк)</option>
  129. </select>
  130. </div>
  131. <div class="setting-block">
  132. <label>Загрузить свои обои:</label>
  133. <input type="file" accept="image/*" id="bgUpload" onchange="uploadBackground(event)">
  134. <button class="btn btn-reset" style="width: 100%; margin-top: 8px; padding: 10px;" onclick="clearBackground()">🗑 Удалить обои</button>
  135. </div>
  136. <div class="setting-block">
  137. <label>Фильтры фона:</label>
  138. <select onchange="changeFilter(this.value)">
  139. <option value="none">Без фильтра</option>
  140. <option value="blur(8px)">Размытие</option>
  141. <option value="grayscale(100%)">Чёрно-белый</option>
  142. <option value="sepia(80%)">Сепия</option>
  143. <option value="hue-rotate(90deg)">Инверсия оттенков</option>
  144. </select>
  145. </div>
  146. </div>
  147. <div style="flex-grow: 1;"></div>
  148. <div style="text-align: center; font-size: 12px; opacity: 0.5;">v2.6 Dashboard App</div>
  149. </div>
  150. <!-- ОСНОВНОЙ ИНТЕРФЕЙС -->
  151. <div id="main-app">
  152. <div class="top-bar">
  153. <button class="menu-btn" onclick="toggleSidebar()">☰ Меню</button>
  154. <div class="nav-logo gradient-text"><span>🌊</span> HarmoniX</div>
  155. <button class="menu-btn" id="btnFullscreen" onclick="toggleFullscreen()">🔲 На весь экран</button>
  156. </div>
  157. <div class="grid-container">
  158. <div class="panel">
  159. <div class="panel-header"><h3 style="margin:0;">1. Базовое колебание</h3></div>
  160. <div class="canvas-wrapper"><canvas id="canvas-single"></canvas></div>
  161. </div>
  162. <div class="panel">
  163. <div class="panel-header">
  164. <h3 style="margin:0;">3. Теорема Фурье</h3>
  165. <button class="btn btn-icon" onclick="downloadGraph('canvas-sum')">💾 Скачать график</button>
  166. </div>
  167. <div class="canvas-wrapper"><canvas id="canvas-sum"></canvas></div>
  168. </div>
  169. <div class="panel">
  170. <h3 style="margin:0">2. Панель Управления</h3>
  171. <div class="tabs">
  172. <div class="tab active" onclick="switchTab(0)">V1</div><div class="tab" onclick="switchTab(1)">V2</div><div class="tab" onclick="switchTab(2)">V3</div>
  173. </div>
  174. <div class="control-row">
  175. <label>Шаг частоты:</label>
  176. <input type="radio" name="step" value="10" onchange="updateStep(10); playUISound('click')"> 10 Гц
  177. <input type="radio" name="step" value="100" onchange="updateStep(100); playUISound('click')" checked> 100 Гц
  178. </div>
  179. <div class="control-row">
  180. <label>Частота V:</label>
  181. <input type="range" id="freq" min="0" max="20000" step="100" value="440" oninput="updateWave(); playSliderSound(this.value, 20000)">
  182. <div style="width: 60px; text-align:right"><span id="valV">440</span> Гц</div>
  183. </div>
  184. <div class="control-row">
  185. <label>Амплитуда A:</label>
  186. <input type="range" id="amp" min="0" max="100" value="80" oninput="updateWave(); playSliderSound(this.value, 100, 0, 'low')">
  187. <div style="width: 60px; text-align:right"><span id="valA">80</span>%</div>
  188. </div>
  189. <div style="margin-top: auto;">
  190. <button class="btn btn-audio" onclick="toggleAudio(); playUISound('action')" id="btnAudio">🔊 Динамик</button>
  191. <button class="btn btn-dist" onclick="toggleClip(); playUISound('action')" id="btnClip">⚡ Нелин. преобр. (Искажение)</button>
  192. <button class="btn btn-reset" onclick="resetAll(); playUISound('error')">🔄 Сброс</button>
  193. </div>
  194. </div>
  195. <div class="panel">
  196. <h3 style="margin:0; margin-bottom: 10px;">4. Спектрограмма</h3>
  197. <div class="canvas-wrapper"><canvas id="canvas-spectrum"></canvas></div>
  198. </div>
  199. </div>
  200. <div class="app-footer">HarmoniX v2.6 | Разработано для интерактивного изучения физики © 2026</div>
  201. </div>
  202. <!-- ТЕСТИРОВАНИЕ -->
  203. <div id="test-overlay" class="modal-overlay">
  204. <div class="modal-content">
  205. <span class="close-btn" onclick="closeTest()">&times;</span>
  206. <h2 class="gradient-text" style="text-align: center; margin-top: 0; font-size: 32px;">Итоговое тестирование</h2>
  207. <div id="test-start-menu">
  208. <p style="text-align:center; font-size: 18px;">Выберите режим тестирования:</p>
  209. <div class="test-modes">
  210. <button class="btn btn-easy" onclick="startQuiz(5)">Легкий<br><small>5 вопросов</small></button>
  211. <button class="btn btn-medium" onclick="startQuiz(15)">Средний<br><small>15 вопросов</small></button>
  212. <button class="btn btn-hard" onclick="startQuiz(30)">Сложный<br><small>30 вопросов</small></button>
  213. </div>
  214. <div style="text-align: center; margin-top: 30px;">
  215. <button class="btn btn-reset" onclick="closeTest()" style="padding: 10px 30px;">🚪 Выйти</button>
  216. </div>
  217. </div>
  218. <div id="quiz-process" style="display: none;">
  219. <div id="quiz-container"></div>
  220. <div class="test-controls" id="quiz-buttons">
  221. <button class="btn btn-test" id="checkBtn" style="font-size: 18px; padding: 10px 30px;" onclick="checkTest()">✅ Проверить ответы</button>
  222. <button class="btn btn-reset" onclick="closeTest()" style="font-size: 18px; padding: 10px 30px;">🚪 Выйти</button>
  223. </div>
  224. <div id="test-result"></div>
  225. <div class="test-controls" id="post-quiz-buttons" style="display: none;">
  226. <button class="btn btn-audio" onclick="openTestMenu()" style="font-size: 18px; padding: 10px 30px;">🔄 Начать сначала</button>
  227. <button class="btn btn-reset" onclick="closeTest()" style="font-size: 18px; padding: 10px 30px;">🚪 Выйти</button>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <script>
  233. // --- БАЗА ИЗ 30 ВОПРОСОВ ---
  234. const masterQuizData = [
  235. { q: "Что утверждает теорема Фурье?", opts: [{t:"Любое сложное колебание есть сумма простых гармонических.", c:true}, {t:"Энергия системы всегда постоянна.", c:false}, {t:"Частота обратно пропорциональна амплитуде.", c:false}] },
  236. { q: "Формула циклической частоты (w)?", opts: [{t:"w = 2πV", c:true}, {t:"w = V / T", c:false}, {t:"w = 2π / V", c:false}] },
  237. { q: "В каких единицах измеряется частота (V)?", opts: [{t:"В Герцах (Гц)", c:true}, {t:"В Радианах (рад)", c:false}, {t:"В Децибелах (дБ)", c:false}] },
  238. { q: "Что показывает амплитудно-частотный спектр?", opts: [{t:"Зависимость амплитуды гармоник от их частоты.", c:true}, {t:"Изменение формы волны во времени.", c:false}, {t:"Скорость распространения звука.", c:false}] },
  239. { q: "К чему визуально приводит нелинейное преобразование (клиппинг)?", opts: [{t:"К обрезке амплитудных пиков и появлению паразитных гармоник.", c:true}, {t:"К сдвигу фазы на 180 градусов.", c:false}, {t:"К плавному затуханию сигнала.", c:false}] },
  240. { q: "Единица измерения периода колебаний (T)?", opts: [{t:"Секунды (с)", c:true}, {t:"Метры (м)", c:false}, {t:"Герцы (Гц)", c:false}] },
  241. { q: "Как математически связаны период (T) и частота (V)?", opts: [{t:"Они обратно пропорциональны (V = 1/T)", c:true}, {t:"Они прямо пропорциональны", c:false}, {t:"Связь определяется логарифмом", c:false}] },
  242. { q: "Какую частоту имеет нота 'Ля' первой октавы (стандарт)?", opts: [{t:"440 Гц", c:true}, {t:"220 Гц", c:false}, {t:"1000 Гц", c:false}] },
  243. { q: "Что такое амплитуда колебания?", opts: [{t:"Максимальное отклонение от положения равновесия", c:true}, {t:"Число колебаний в секунду", c:false}, {t:"Скорость волны", c:false}] },
  244. { q: "Что происходит с графиком волны при изменении фазы (θ)?", opts: [{t:"График сдвигается вдоль оси времени", c:true}, {t:"Изменяется высота пиков", c:false}, {t:"График сжимается по горизонтали", c:false}] },
  245. { q: "Если период T = 0.1 с, то чему равна частота V?", opts: [{t:"10 Гц", c:true}, {t:"100 Гц", c:false}, {t:"1 Гц", c:false}] },
  246. { q: "Как выглядит амплитудный спектр идеального синусоидального сигнала?", opts: [{t:"Один единственный пик на графике спектра", c:true}, {t:"Сплошная линия (белый шум)", c:false}, {t:"Множество убывающих пиков", c:false}] },
  247. { q: "Какие гармоники появляются при симметричном ограничении (клиппинге)?", opts: [{t:"Преимущественно нечетные (3, 5, 7...)", c:true}, {t:"Только четные", c:false}, {t:"Никакие", c:false}] },
  248. { q: "Что означает 'w' в уравнении y = A cos(wt)?", opts: [{t:"Скорость изменения фазы (циклическая частота)", c:true}, {t:"Длину волны", c:false}, {t:"Мощность сигнала", c:false}] },
  249. { q: "Что мы услышим при сложении волн 440 Гц и 442 Гц?", opts: [{t:"Биения (пульсацию громкости)", c:true}, {t:"Белый шум", c:false}, {t:"Чистый аккорд", c:false}] },
  250. { q: "Какой формы станет синусоида при экстремально сильном клиппинге?", opts: [{t:"Почти прямоугольной (меандр)", c:true}, {t:"Треугольной", c:false}, {t:"Пилообразной", c:false}] },
  251. { q: "Влияет ли фаза (θ) одной гармоники на восприятие высоты ее тона ухом?", opts: [{t:"Нет, ухо не чувствительно к абсолютной фазе", c:true}, {t:"Да, тон становится выше", c:false}, {t:"Да, тон становится ниже", c:false}] },
  252. { q: "Если частота звука увеличивается в 2 раза, то на слух это звучит как:", opts: [{t:"Повышение на одну октаву", c:true}, {t:"Увеличение громкости в 2 раза", c:false}, {t:"Появление эха", c:false}] },
  253. { q: "Какой сигнал содержит только нечетные гармоники с амплитудами 1/n?", opts: [{t:"Прямоугольный (меандр)", c:true}, {t:"Пилообразный", c:false}, {t:"Треугольный", c:false}] },
  254. { q: "Согласно теореме Котельникова, какой должна быть частота дискретизации для сигнала 20 кГц?", opts: [{t:"Не менее 40 кГц (удвоенная)", c:true}, {t:"Не менее 10 кГц", c:false}, {t:"Точно 20 кГц", c:false}] },
  255. { q: "От чего зависит полная энергия гармонического осциллятора?", opts: [{t:"Пропорциональна квадрату амплитуды", c:true}, {t:"Обратно пропорциональна частоте", c:false}, {t:"Пропорциональна корню амплитуды", c:false}] },
  256. { q: "Если на спектре есть пики на 100, 200 и 300 Гц, какова основная (фундаментальная) частота?", opts: [{t:"100 Гц", c:true}, {t:"300 Гц", c:false}, {t:"200 Гц", c:false}] },
  257. { q: "Чем отличается спектр шума от спектра гармонического сигнала?", opts: [{t:"У шума сплошной спектр, у гармонического - линейчатый", c:true}, {t:"У шума спектр линейный, у гармонического - сплошной", c:false}, {t:"Разницы нет", c:false}] },
  258. { q: "Как изменится циклическая частота (w), если период уменьшить в 4 раза?", opts: [{t:"Увеличится в 4 раза", c:true}, {t:"Уменьшится в 4 раза", c:false}, {t:"Останется прежней", c:false}] },
  259. { q: "Что такое резонанс?", opts: [{t:"Резкое возрастание амплитуды при совпадении частот", c:true}, {t:"Затухание волны в среде", c:false}, {t:"Отражение волны от препятствия", c:false}] },
  260. { q: "В уравнении колебаний аргумент косинуса (wt + θ) называется:", opts: [{t:"Фазой колебания", c:true}, {t:"Спектром колебания", c:false}, {t:"Декрементом", c:false}] },
  261. { q: "Влияет ли нелинейное искажение на тембр звука?", opts: [{t:"Да, так как меняется спектр (добавляются обертоны)", c:true}, {t:"Нет, меняется только громкость", c:false}, {t:"Нет, меняется только основная частота", c:false}] },
  262. { q: "Сколько гармоник необходимо для идеального воссоздания прямоугольного импульса?", opts: [{t:"Бесконечно много", c:true}, {t:"Ровно три", c:false}, {t:"Десять", c:false}] },
  263. { q: "Почему столбцы спектра при клиппинге в приложении рисуются красным?", opts: [{t:"Потому что это паразитные (искажающие) частоты", c:true}, {t:"Это ошибка рендера Canvas", c:false}, {t:"Это основные тона", c:false}] },
  264. { q: "При сложении двух волн в противофазе (сдвиг 180°) с одинаковыми амплитудами:", opts: [{t:"Волны полностью гасят друг друга (сумма равна 0)", c:true}, {t:"Амплитуда удваивается", c:false}, {t:"Частота удваивается", c:false}] }
  265. ];
  266. let uiAudioCtx = null, audioCtx = null, oscillators = [];
  267. let waves = [{ f: 440, a: 80 }, { f: 880, a: 0 }, { f: 1320, a: 0 }];
  268. let currentWave = 0, freqStep = 100, time = 0, isClipped = false, isAudioOn = false;
  269. let animationFrameId = null;
  270. // --- Умный Resize Observer для идеальной сетки (всегда вписывается в контейнер) ---
  271. const resizeObserver = new ResizeObserver(entries => {
  272. for (let entry of entries) {
  273. const canvas = entry.target.querySelector('canvas');
  274. if (canvas) {
  275. canvas.width = entry.contentRect.width;
  276. canvas.height = entry.contentRect.height;
  277. }
  278. }
  279. });
  280. // --- ЛОГИКА ПОЛНОЭКРАННОГО РЕЖИМА И КНОПКИ ---
  281. function toggleFullscreen() {
  282. if (!document.fullscreenElement) { document.documentElement.requestFullscreen().catch(err=>{}); }
  283. else { if (document.exitFullscreen) document.exitFullscreen(); }
  284. }
  285. document.addEventListener('fullscreenchange', () => {
  286. const btn = document.getElementById('btnFullscreen');
  287. if (document.fullscreenElement) { btn.innerHTML = '✖ Выйти из полноэкранного'; }
  288. else { btn.innerHTML = '🔲 На весь экран'; }
  289. playUISound('action');
  290. });
  291. function startApp() {
  292. document.getElementById('welcome-screen').style.opacity = '0';
  293. setTimeout(() => {
  294. document.getElementById('welcome-screen').style.display = 'none';
  295. document.getElementById('main-app').style.display = 'flex';
  296. document.querySelectorAll('.canvas-wrapper').forEach(wrapper => resizeObserver.observe(wrapper));
  297. uiAudioCtx = new (window.AudioContext || window.webkitAudioContext)();
  298. playUISound('action');
  299. if (!animationFrameId) draw();
  300. }, 500);
  301. }
  302. function toggleSidebar() {
  303. const sidebar = document.getElementById('sidebar'); const overlay = document.getElementById('sidebar-overlay');
  304. if (sidebar.classList.contains('open')) { sidebar.classList.remove('open'); overlay.style.display = 'none'; playUISound('click'); }
  305. else { sidebar.classList.add('open'); overlay.style.display = 'block'; playUISound('action'); }
  306. }
  307. // --- ЛОГИКА ТЕСТА ---
  308. function shuffle(array) { return array.sort(() => Math.random() - 0.5); }
  309. function openTestMenu() {
  310. document.getElementById('test-overlay').style.display = 'flex';
  311. document.getElementById('test-start-menu').style.display = 'block';
  312. document.getElementById('quiz-process').style.display = 'none';
  313. playUISound('click');
  314. }
  315. function startQuiz(numQuestions) {
  316. document.getElementById('test-start-menu').style.display = 'none';
  317. document.getElementById('quiz-process').style.display = 'block';
  318. document.getElementById('test-result').style.opacity = '0';
  319. document.getElementById('quiz-buttons').style.display = 'flex';
  320. document.getElementById('post-quiz-buttons').style.display = 'none';
  321. const container = document.getElementById('quiz-container'); container.innerHTML = '';
  322. let shuffledQuestions = shuffle([...masterQuizData]).slice(0, numQuestions);
  323. shuffledQuestions.forEach((item, qIndex) => {
  324. let qDiv = document.createElement('div'); qDiv.className = 'question';
  325. qDiv.innerHTML = `<p>${qIndex + 1}. ${item.q}</p>`;
  326. let shuffledOpts = shuffle([...item.opts]);
  327. shuffledOpts.forEach((opt) => {
  328. let lbl = document.createElement('label'); lbl.className = 'quiz-option';
  329. lbl.innerHTML = `<input type="radio" name="q${qIndex}" value="${opt.c ? '1' : '0'}" onclick="playUISound('click')"> ${opt.t}`;
  330. qDiv.appendChild(lbl);
  331. });
  332. container.appendChild(qDiv);
  333. });
  334. playUISound('action');
  335. }
  336. function closeTest() { document.getElementById('test-overlay').style.display = 'none'; playUISound('click'); }
  337. async function checkTest() {
  338. document.getElementById('quiz-buttons').style.display = 'none';
  339. let score = 0; const questions = document.querySelectorAll('.question'); let total = questions.length;
  340. for (let q of questions) {
  341. let selected = q.querySelector('input:checked'); let lbl = selected ? selected.parentElement : null;
  342. if (selected && selected.value === '1') {
  343. score++; if(lbl) lbl.classList.add('correct'); playQuizSound('ding');
  344. } else {
  345. if(lbl) lbl.classList.add('wrong');
  346. let correctInput = q.querySelector('input[value="1"]');
  347. if(correctInput) correctInput.parentElement.classList.add('correct');
  348. playQuizSound('buzz');
  349. }
  350. await new Promise(r => setTimeout(r, 200)); // Ускорено для 30 вопросов
  351. }
  352. let percent = Math.round((score / total) * 100);
  353. let resDiv = document.getElementById('test-result');
  354. resDiv.innerHTML = `Правильных ответов: ${score} из ${total} (${percent}%)<br><br>`;
  355. if(percent >= 90) { resDiv.style.color = "var(--accent)"; resDiv.innerHTML += "🎉 Великолепно! Вы настоящий гений физики! 🎉"; playQuizSound('win'); }
  356. else if (percent >= 60) { resDiv.style.color = "#FF9800"; resDiv.innerHTML += "👍 Хороший результат! Но есть куда расти."; playQuizSound('win'); }
  357. else { resDiv.style.color = "#f44336"; resDiv.innerHTML += "😅 Упс... Нужно серьезно повторить конспект."; playQuizSound('lose'); }
  358. resDiv.style.opacity = '1'; document.getElementById('post-quiz-buttons').style.display = 'flex';
  359. }
  360. // --- ФОНЫ, ТЕМЫ И ЗВУКИ ---
  361. function clearBackground() { document.getElementById('bg-layer').style.backgroundImage = 'none'; document.getElementById('bgUpload').value = ''; playUISound('error'); }
  362. function uploadBackground(event) {
  363. if (event.target.files[0]) {
  364. const reader = new FileReader();
  365. reader.onload = e => { document.getElementById('bg-layer').style.backgroundImage = `url('${e.target.result}')`; playUISound('action'); };
  366. reader.readAsDataURL(event.target.files[0]);
  367. }
  368. }
  369. function changeTheme(themeName) { document.documentElement.setAttribute('data-theme', themeName); playUISound('action'); }
  370. function changeFilter(filterValue) { document.getElementById('bg-layer').style.filter = filterValue; playUISound('click'); }
  371. function downloadGraph(canvasId) {
  372. const canvas = document.getElementById(canvasId); const link = document.createElement('a'); link.download = 'HarmoniX_Graph.png';
  373. const tempCanvas = document.createElement('canvas'); tempCanvas.width = canvas.width; tempCanvas.height = canvas.height;
  374. const tCtx = tempCanvas.getContext('2d'); tCtx.fillStyle = '#ffffff'; tCtx.fillRect(0,0, tempCanvas.width, tempCanvas.height); tCtx.drawImage(canvas, 0, 0);
  375. link.href = tempCanvas.toDataURL(); link.click(); playUISound('action');
  376. }
  377. function playUISound(type) {
  378. if (!uiAudioCtx) return;
  379. const osc = uiAudioCtx.createOscillator(), gain = uiAudioCtx.createGain();
  380. osc.connect(gain); gain.connect(uiAudioCtx.destination); let now = uiAudioCtx.currentTime;
  381. if (type === 'click' || type === 'hover') { osc.type = 'sine'; osc.frequency.setValueAtTime(800, now); gain.gain.setValueAtTime(0.05, now); gain.gain.exponentialRampToValueAtTime(0.001, now + 0.1); osc.start(now); osc.stop(now + 0.1); }
  382. else if (type === 'action') { osc.type = 'triangle'; osc.frequency.setValueAtTime(400, now); osc.frequency.exponentialRampToValueAtTime(800, now + 0.15); gain.gain.setValueAtTime(0.1, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.15); osc.start(now); osc.stop(now + 0.15); }
  383. else if (type === 'error') { osc.type = 'sawtooth'; osc.frequency.setValueAtTime(150, now); gain.gain.setValueAtTime(0.1, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.2); osc.start(now); osc.stop(now + 0.2); }
  384. }
  385. function playQuizSound(type) {
  386. if (!uiAudioCtx) return;
  387. const osc = uiAudioCtx.createOscillator(), gain = uiAudioCtx.createGain();
  388. osc.connect(gain); gain.connect(uiAudioCtx.destination); let now = uiAudioCtx.currentTime;
  389. if (type === 'ding') { osc.type = 'sine'; osc.frequency.setValueAtTime(600, now); osc.frequency.setValueAtTime(900, now + 0.1); gain.gain.setValueAtTime(0.05, now); gain.gain.exponentialRampToValueAtTime(0.001, now + 0.3); osc.start(now); osc.stop(now + 0.3); }
  390. else if (type === 'buzz') { osc.type = 'sawtooth'; osc.frequency.setValueAtTime(200, now); osc.frequency.setValueAtTime(150, now + 0.1); gain.gain.setValueAtTime(0.05, now); gain.gain.exponentialRampToValueAtTime(0.001, now + 0.3); osc.start(now); osc.stop(now + 0.3); }
  391. else if (type === 'win') { osc.type = 'triangle'; [440, 554, 659, 880].forEach((f, i) => osc.frequency.setValueAtTime(f, now + i*0.1)); gain.gain.setValueAtTime(0.1, now); gain.gain.linearRampToValueAtTime(0, now + 0.5); osc.start(now); osc.stop(now + 0.5); }
  392. else if (type === 'lose') { osc.type = 'sawtooth'; [300, 280, 260, 200].forEach((f, i) => osc.frequency.setValueAtTime(f, now + i*0.2)); gain.gain.setValueAtTime(0.1, now); gain.gain.linearRampToValueAtTime(0, now + 0.8); osc.start(now); osc.stop(now + 0.8); }
  393. }
  394. function playSliderSound(value, max, min = 0, type = 'high') {
  395. if (!uiAudioCtx) return;
  396. const osc = uiAudioCtx.createOscillator(), gain = uiAudioCtx.createGain();
  397. osc.connect(gain); gain.connect(uiAudioCtx.destination);
  398. let freq = type === 'high' ? 300 + ((value - min) / (max - min)) * 1000 : 150 + ((value - min) / (max - min)) * 300;
  399. osc.type = 'sine'; let now = uiAudioCtx.currentTime;
  400. osc.frequency.setValueAtTime(freq, now); gain.gain.setValueAtTime(0.05, now); gain.gain.exponentialRampToValueAtTime(0.001, now + 0.05);
  401. osc.start(now); osc.stop(now + 0.05);
  402. }
  403. // --- УПРАВЛЕНИЕ ВОЛНАМИ ---
  404. function switchTab(index) {
  405. currentWave = index; document.querySelectorAll('.tab').forEach((el, i) => el.classList.toggle('active', i === index));
  406. document.getElementById('freq').value = waves[index].f; document.getElementById('amp').value = waves[index].a;
  407. updateLabels(); playUISound('click');
  408. }
  409. function updateStep(step) { freqStep = step; document.getElementById('freq').step = step; }
  410. function updateLabels() { document.getElementById('valV').innerText = waves[currentWave].f; document.getElementById('valA').innerText = waves[currentWave].a; }
  411. function updateWave() { waves[currentWave].f = parseInt(document.getElementById('freq').value); waves[currentWave].a = parseInt(document.getElementById('amp').value); updateLabels(); updateAudio(); }
  412. function toggleClip() {
  413. isClipped = !isClipped; let btn = document.getElementById('btnClip');
  414. if (isClipped) { btn.classList.add('active'); btn.innerText = "⚡ Убрать искажение"; }
  415. else { btn.classList.remove('active'); btn.innerText = "⚡ Нелин. преобр. (Искажение)"; }
  416. updateAudio();
  417. }
  418. function resetAll() {
  419. waves = [{ f: 440, a: 80 }, { f: 880, a: 0 }, { f: 1320, a: 0 }]; isClipped = false; clearBackground();
  420. let btnClip = document.getElementById('btnClip'); btnClip.classList.remove('active'); btnClip.innerText = "⚡ Нелин. преобр. (Искажение)";
  421. switchTab(0); updateAudio();
  422. }
  423. function toggleAudio() {
  424. if (!audioCtx) {
  425. audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  426. for (let i = 0; i < 3; i++) {
  427. let osc = audioCtx.createOscillator(), gain = audioCtx.createGain();
  428. osc.type = 'sine'; osc.connect(gain); gain.connect(audioCtx.destination);
  429. osc.start(); oscillators.push({ osc: osc, gain: gain });
  430. }
  431. }
  432. isAudioOn = !isAudioOn; let btn = document.getElementById('btnAudio');
  433. if (isAudioOn) { audioCtx.resume(); btn.classList.add('active'); btn.innerText = "🔇 Выкл. Динамик"; }
  434. else { audioCtx.suspend(); btn.classList.remove('active'); btn.innerText = "🔊 Динамик"; }
  435. updateAudio();
  436. }
  437. function updateAudio() {
  438. if (!audioCtx) return;
  439. for (let i = 0; i < 3; i++) {
  440. oscillators[i].osc.frequency.setValueAtTime(waves[i].f, audioCtx.currentTime);
  441. let vol = isAudioOn ? (waves[i].a * 0.005) : 0;
  442. if (isClipped && isAudioOn && waves[i].a > 0) vol *= 2.5;
  443. oscillators[i].gain.gain.setTargetAtTime(vol, audioCtx.currentTime, 0.05);
  444. oscillators[i].osc.type = isClipped ? 'square' : 'sine';
  445. }
  446. }
  447. function draw() {
  448. time += 0.08;
  449. let baseColor = getComputedStyle(document.documentElement).getPropertyValue('--base-wave').trim();
  450. let sumColor = "#E91E63", gridColor = "rgba(128,128,128,0.3)";
  451. let c1 = document.getElementById('canvas-single'), ctx1 = c1.getContext('2d');
  452. ctx1.clearRect(0, 0, c1.width, c1.height);
  453. ctx1.beginPath(); ctx1.strokeStyle = gridColor; ctx1.moveTo(0, c1.height/2); ctx1.lineTo(c1.width, c1.height/2); ctx1.stroke();
  454. ctx1.beginPath(); ctx1.strokeStyle = baseColor; ctx1.lineWidth = 2;
  455. for (let x = 0; x < c1.width; x+=2) {
  456. let visualF = (waves[currentWave].f / 200) || 1;
  457. let y = Math.cos(x * 0.02 * visualF - time) * (waves[currentWave].a / 100) * (c1.height/2.5);
  458. if(x===0) ctx1.moveTo(x, c1.height/2 - y); else ctx1.lineTo(x, c1.height/2 - y);
  459. }
  460. ctx1.stroke();
  461. let c2 = document.getElementById('canvas-sum'), ctx2 = c2.getContext('2d');
  462. ctx2.clearRect(0, 0, c2.width, c2.height);
  463. ctx2.beginPath(); ctx2.strokeStyle = gridColor; ctx2.moveTo(0, c2.height/2); ctx2.lineTo(c2.width, c2.height/2); ctx2.stroke();
  464. ctx2.beginPath(); ctx2.strokeStyle = sumColor; ctx2.lineWidth = 2;
  465. for (let x = 0; x < c2.width; x+=2) {
  466. let sumY = 0;
  467. for (let i = 0; i < 3; i++) {
  468. let visualF = (waves[i].f / 200) || 1; sumY += Math.cos(x * 0.02 * visualF - time) * (waves[i].a / 100) * (c2.height/2.5);
  469. }
  470. if (isClipped) {
  471. let limit = c2.height / 4;
  472. if (sumY > limit) sumY = limit; if (sumY < -limit) sumY = -limit;
  473. }
  474. if(x===0) ctx2.moveTo(x, c2.height/2 - sumY/1.5); else ctx2.lineTo(x, c2.height/2 - sumY/1.5);
  475. }
  476. ctx2.stroke();
  477. let c3 = document.getElementById('canvas-spectrum'), ctx3 = c3.getContext('2d');
  478. ctx3.clearRect(0, 0, c3.width, c3.height);
  479. ctx3.beginPath(); ctx3.strokeStyle = gridColor; ctx3.moveTo(0, c3.height - 15); ctx3.lineTo(c3.width, c3.height - 15); ctx3.stroke();
  480. ctx3.fillStyle = "rgba(128,128,128,0.8)"; ctx3.font = "10px Arial";
  481. ctx3.fillText("5кГц", (5000 / 20000) * c3.width, c3.height - 2);
  482. ctx3.fillText("10кГц", (10000 / 20000) * c3.width, c3.height - 2);
  483. ctx3.fillText("15кГц", (15000 / 20000) * c3.width, c3.height - 2);
  484. ctx3.fillStyle = "#4CAF50";
  485. for (let i = 0; i < 3; i++) {
  486. if (waves[i].a > 0) {
  487. let xPos = (waves[i].f / 20000) * c3.width; let h = (waves[i].a / 100) * (c3.height - 30);
  488. ctx3.fillRect(Math.max(xPos, 5), c3.height - 15 - h, 10, h);
  489. }
  490. }
  491. if (isClipped && waves[0].a > 0) {
  492. ctx3.fillStyle = "rgba(233, 30, 99, 0.6)";
  493. for (let i = 3; i <= 9; i += 2) {
  494. let fakeF = waves[0].f * i; if (fakeF > 20000) break;
  495. let xPos = (fakeF / 20000) * c3.width; let h = (waves[0].a / (i*2) / 100) * (c3.height - 30);
  496. ctx3.fillRect(Math.max(xPos, 5), c3.height - 15 - h, 6, h);
  497. }
  498. }
  499. animationFrameId = requestAnimationFrame(draw);
  500. }
  501. updateLabels();
  502. </script>
  503. </body>
  504. </html>