|
10 | 10 | background: #f0f0f0; |
11 | 11 | color: #333; |
12 | 12 | } |
| 13 | + |
13 | 14 | h1 { text-align: center; } |
| 15 | + |
14 | 16 | input, textarea, button { |
15 | 17 | font-size: 1rem; |
16 | 18 | margin: 5px 0; |
17 | 19 | width: 100%; |
| 20 | + box-sizing: border-box; |
18 | 21 | } |
| 22 | + |
19 | 23 | textarea { height: 80px; } |
20 | 24 | label { font-weight: bold; } |
| 25 | + div { width: 100%; } |
| 26 | + |
21 | 27 | button { |
22 | | - border-radius: 20px; |
23 | | - padding-top: 10px; |
24 | | - padding-bottom: 10px; |
25 | | - flex: 0 0 50%; |
| 28 | + border-radius: 10px; |
| 29 | + padding-top: 10px; |
| 30 | + padding-bottom: 10px; |
| 31 | + width: 120px; |
26 | 32 | } |
27 | | - .buttons { |
28 | | - display: flex; |
29 | | - gap: 0.5rem; |
| 33 | + |
| 34 | + .buttons{ |
| 35 | + display: flex; |
| 36 | + flex-direction: row; |
| 37 | + justify-content: space-between; |
| 38 | + flex: 0 0 100% |
| 39 | + } |
| 40 | + |
| 41 | + .buttons .main-buttons{ |
| 42 | + display: flex; |
| 43 | + flex: 4; |
| 44 | + gap: 0.5rem; |
| 45 | + flex-direction: row; |
| 46 | + justify-content: start; |
| 47 | + } |
| 48 | + |
| 49 | + .buttons .load-preset { |
| 50 | + display: flex; |
| 51 | + gap: 0; |
| 52 | + justify-content: end; |
| 53 | + } |
| 54 | + |
| 55 | + #dark-button { |
| 56 | + position: absolute; |
| 57 | + width: 120px; |
| 58 | + top: 41px; |
| 59 | + right: 28px; |
30 | 60 | } |
31 | 61 | </style> |
32 | 62 | </head> |
33 | 63 | <body> |
34 | | - |
35 | | -<h1>WavePlayerJS</h1> |
36 | | - |
37 | | -<label for="formula">Enter your waveform formula (use "t" as time in seconds):</label> |
38 | | -<textarea id="formula">(2/Math.PI)*Math.asin(Math.sin(2*t*vf))*va + (2/Math.PI)*Math.tan(Math.sin(t*vf))*va*vp</textarea> |
39 | | - |
40 | | -<label for="vf">Frequency (vf, Hz):</label> |
41 | | -<input type="number" id="vf" value="2000" step="0.1"> |
42 | | - |
43 | | -<label for="va">Amplitude (va, 0-1):</label> |
44 | | -<input type="number" id="va" value="0.5" step="0.1" min="0" max="1"> |
45 | | - |
46 | | -<label for="vp">Parameter (vp):</label> |
47 | | -<input type="number" id="vp" value="1" step="0.1"> |
48 | | - |
49 | | -<div class="buttons"> |
50 | | - <button id="playBtn">Play Wave</button> |
51 | | - <button id="stopBtn">Stop Wave</button> |
52 | | -</div> |
53 | | - |
54 | | -<br/> |
55 | | -<p>Use ** instead of ^ for exponents</p> |
| 64 | + <header> |
| 65 | + <div id="dark-button"> |
| 66 | + <button onclick="switchTheme();" id="theme-button">Dark Mode</button> |
| 67 | + </div> |
| 68 | + <h1>WavePlayerJS</h1> |
| 69 | + </header> |
| 70 | + |
| 71 | + <label for="formula">Enter your waveform formula (use "t" as time in seconds):</label> |
| 72 | + <textarea id="formula">(2/Math.PI)*Math.asin(Math.sin(2*t*vf))*va + (2/Math.PI)*Math.tan(Math.sin(t*vf))*va*vp</textarea> |
| 73 | + |
| 74 | + <label for="vf">Frequency (vf, Hz):</label> |
| 75 | + <input type="number" id="vf" value="2000" step="1"> |
| 76 | + |
| 77 | + <label for="va">Amplitude (va, 0-1):</label> |
| 78 | + <input type="number" id="va" value="0.5" step="0.1" min="0" max="1"> |
| 79 | + |
| 80 | + <label for="vp">Parameter (vp):</label> |
| 81 | + <input type="number" id="vp" value="1" step="1"> |
| 82 | + |
| 83 | + <div style="display: flex; margin-top: 8px"> |
| 84 | + <div class="buttons"> |
| 85 | + <div class="main-buttons"> |
| 86 | + <button id="playBtn">Play Wave</button> |
| 87 | + <button id="stopBtn">Stop Wave</button> |
| 88 | + </div> |
| 89 | + <button id="loadPresetBtn" style="margin-left: auto;" onclick="alert('This feature hasn\'t been added yet.');">Load Preset</button> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + |
| 93 | + <br/> |
| 94 | + <p>Use ** instead of ^ for exponents</p> |
56 | 95 |
|
57 | 96 | <script> |
58 | 97 | let audioCtx; |
59 | 98 | let bufferSource; |
60 | 99 |
|
| 100 | +var dark; |
| 101 | +dark=0; |
| 102 | + |
61 | 103 | document.getElementById("playBtn").addEventListener("click", playWave); |
62 | 104 | document.getElementById("stopBtn").addEventListener("click", stopWave); |
63 | 105 |
|
@@ -100,8 +142,34 @@ <h1>WavePlayerJS</h1> |
100 | 142 | bufferSource.disconnect(); |
101 | 143 | } |
102 | 144 | } |
| 145 | + |
| 146 | +function switchTheme() { |
| 147 | + let themeBtn = document.getElementById("theme-button"); |
| 148 | + let pagebody = document.body; |
| 149 | + let elements = document.querySelectorAll("button, input, textarea"); |
| 150 | + |
| 151 | + if (dark==0) { |
| 152 | + // Switch to dark mode |
| 153 | + themeBtn.textContent = "Light Mode"; |
| 154 | + pagebody.style.background = "#232323"; |
| 155 | + pagebody.style.color = "#f0f0f0"; |
| 156 | + for (let el of elements) { |
| 157 | + el.style.background = "#323232"; |
| 158 | + el.style.color = "#f0f0f0"; |
| 159 | + } |
| 160 | + dark = 1; |
| 161 | + } else if (dark==1) { |
| 162 | + // Switch to light mode |
| 163 | + themeBtn.textContent = "Dark Mode"; |
| 164 | + pagebody.style.background = "#f0f0f0"; |
| 165 | + pagebody.style.color = "#333"; |
| 166 | + for (let el of elements) { |
| 167 | + el.style.background = ""; |
| 168 | + el.style.color = ""; |
| 169 | + } |
| 170 | + dark = 0; |
| 171 | + } |
| 172 | +} |
103 | 173 | </script> |
104 | 174 | </body> |
105 | 175 | </html> |
106 | | - |
107 | | - |
|
0 commit comments