index.html 33 KB

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