-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.html
More file actions
703 lines (614 loc) · 25.3 KB
/
visualization.html
File metadata and controls
703 lines (614 loc) · 25.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zero Cross Detection</title>
<style>
body {
font-family: 'Helvetica', sans-serif;
background-color: #f4f4f9;
color: #333;
margin: 0;
padding: 0;
width: 100%;
justify-content: center;
align-items: center;
min-height: 100vh; /* Changed height to min-height */
}
.container {
text-align: center;
background-color: #fff;
padding: 40px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin: 0;
margin-top: 0px;
}
h1 {
font-family: 'Raveparty Narrow', sans-serif;
color: #1c3a58;
font-size: 8vh; /* Adjusted font-size */
margin-bottom: 10px; /* Added margin */
}
h2 {
font-family: 'Helvetica', sans-serif;
color: #1c3a58;
font-size: 3vh; /* Adjusted font-size */
margin-top: 10px; /* Added margin */
margin-bottom: 10px; /* Added margin */
}
p {
color: #1c3a58;
font-size: 2.5vh; /* Adjusted font-size */
margin-bottom: 15px; /* Added margin */
}
img {
max-width: 100%;
height: auto;
border-radius: 8px;
margin-top: 20px; /* Adjusted margin */
}
.video {
max-width: 100%;
height: auto;
margin: 20px auto;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: block;
}
.button-link {
display: block; /* Changed to block to force new line */
margin-top: 20px; /* Adjusted margin */
}
.button-71 {
background-color: #1c3a58;
border: 0;
border-radius: 56px;
color: #fff;
cursor: pointer;
display: inline-block; /* Changed to inline-block */
font-family: system-ui, -apple-system, system-ui, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
font-size: 18px;
font-weight: 600;
outline: 0;
padding: 16px 21px;
text-align: center;
text-decoration: none;
transition: all .3s;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
margin-top: 30px; /* Added margin */
}
.button-71:hover {
box-shadow: rgba(255, 255, 255, .2) 0 3px 15px inset, rgba(0, 0, 0, .1) 0 3px 5px, rgba(0, 0, 0, .1) 0 10px 13px;
transform: scale(1.05);
}
.graph-images {
display: flex;
justify-content: space-evenly;
margin-top: 20px;
}
.graph-images img {
height: 200px; /* Set the desired height */
width: auto;
object-fit: contain;
border-radius: 8px;
}
.internal-image img {
max-width: 100%;
height: auto;
border-radius: 8px;
margin-top: 20px; /* Adjusted margin */
}
nav {
background-color: #fff;
padding: 1em;
text-align: center;
}
nav a {
font-family: 'Helvetica', sans-serif;
color: #b8c7e0;
text-decoration: none;
margin: 0 1em;
transition: color 0.3s ease;
}
nav a:hover {
color: #1c3a58;;
}
main {
max-width: 1200px;
margin: 0 auto;
padding: 2em;
background-color: #fff;;
}
.video-container {
width: 100%;
height: 300px;
background-color: #0c0f1d;
margin-bottom: 1em;
position: relative;
overflow: hidden;
border: 2px solid #4a90e2;
border-radius: 10px;
}
.chart-label {
position: absolute;
top: 10px;
left: 10px;
color: #4a90e2;
font-size: 1.2em;
font-weight: bold;
text-shadow: 1px 1px 2px #000;
}
.ac-wave, .square-wave {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.zero-cross-point, .digital-output-indicator {
position: absolute;
width: 20px;
height: 20px;
background-color: #ff4b4b;
border-radius: 50%;
transform: translate(-50%, -50%);
opacity: 0;
box-shadow: 0 0 10px #ff4b4b;
transition: opacity 0.1s ease;
}
.zero-cross-point {
left: 50%;
top: 50%;
}
.digital-output-indicator {
left: 50%;
top: 25%;
}
.digital-output-label {
position: absolute;
left: calc(50% + 15px);
top: 80%;
color: #ff4b4b;
font-size: 1.2em;
font-weight: bold;
text-shadow: 1px 1px 2px #000;
}
.offset-controls {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 10px;
}
.offset-button {
background-color: #4a90e2;
color: white;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.offset-button:hover {
background-color: #3a7bc2;
}
.offset-button.active {
background-color: #ff4b4b;
}
.cta-button {
display: inline-block;
background-color: #4a90e2;
color: #ffffff;
padding: 0.5em 1em;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.cta-button:hover {
background-color: #3a7bc2;
}
.offset-area {
position: absolute;
height: 100%;
background-color: rgba(255, 75, 75, 0.2);
top: 0;
left: 50%;
transform: translateX(-50%);
display: none;
}
.toggle-controls {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 20px;
}
.toggle-button {
background-color: #4a90e2;
color: white;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.toggle-button:hover {
background-color: #3a7bc2;
}
/* Hide blue, green, and yellow square waves initially */
.square-wave use[stroke="#4a90e2"],
.square-wave use[stroke="#34a853"],
.square-wave use[stroke="#fbbc05"] {
display: none;
}
.square-wave use[stroke="#4a90e2"],
.square-wave use[stroke="#34a853"],
.square-wave use[stroke="#fbbc05"] {
display: none;
}
.indicator-dot.red {
background-color: #ff4b4b;
box-shadow: 0 0 10px #ff4b4b;
}
.indicator-dot.blue {
background-color: #4a90e2;
box-shadow: 0 0 10px #4a90e2;
}
.indicator-dot.green {
background-color: #34a853;
box-shadow: 0 0 10px #34a853;
}
.indicator-dot.yellow {
background-color: #fbbc05;
box-shadow: 0 0 10px #fbbc05;
}
.zero-cross-line {
stroke: #ff4b4b;
stroke-width: 2;
stroke-dasharray: 5,5;
opacity: 0.8;
}
@keyframes zeroCrossing {
0% {
transform: translateX(0);
}
50% {
transform: translateX(-100%);
}
100% {
transform: translateX(-200%);
}
}
.toggle-button.active {
background-color: #333; /* Dark background color */
color: #fff; /* White text color */
}
footer {
background-color: #fff;
color: #1c3a58;
text-align: center;
padding: 1em;
margin-top: 0;
}
footer a {
color: #1c3a58;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>SynchroPoint</h1>
<h2>Precision Zero Cross Detection</h2>
<nav>
<a href="https://tsltd.github.io/webpage.html">Home</a>
<a href="https://tsltd.github.io/about.html">About</a>
<a href="https://tsltd.github.io/product_detail.html">Our Product</a>
<a href="https://tsltd.github.io/contact.html">Contact</a>
</nav>
<h2>Animated Visualization</h2>
<main>
<div class="video-container">
<div class="chart-label">Input: AC Power Supply</div>
<svg class="ac-wave" viewBox="0 0 1000 300" preserveAspectRatio="none">
<defs>
<path id="sineWave" d="M0,150 Q125,350 250,150 T500,150" />
</defs>
<line x1="0" y1="150" x2="1000" y2="150" stroke="#4a90e2" stroke-width="2" />
<line x1="500" y1="0" x2="500" y2="300" stroke="#4a90e2" stroke-width="2" />
<use xlink:href="#sineWave" x="0" y="0" fill="none" stroke="#7a9fd1" stroke-width="4">
<animate attributeName="x" from="0" to="-500" dur="4s" repeatCount="indefinite" />
</use>
<use xlink:href="#sineWave" x="500" y="0" fill="none" stroke="#7a9fd1" stroke-width="4">
<animate attributeName="x" from="500" to="0" dur="4s" repeatCount="indefinite" />
</use>
<use xlink:href="#sineWave" x="1000" y="0" fill="none" stroke="#7a9fd1" stroke-width="4">
<animate attributeName="x" from="1000" to="500" dur="4s" repeatCount="indefinite" />
</use>
<!-- Zero-cross lines at correct intervals -->
<line class="zero-cross-line" x1="0" y1="0" x2="0" y2="300">
<animate attributeName="x1" from="250" to="0" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="250" to="0" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="500" y1="0" x2="0" y2="300">
<animate attributeName="x1" from="500" to="250" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="500" to="250" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="750" y1="0" x2="0" y2="300">
<animate attributeName="x1" from="750" to="500" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="750" to="500" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="1000" y1="0" x2="750" y2="300">
<animate attributeName="x1" from="1000" to="750" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="1000" to="750" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="1250" y1="0" x2="1000" y2="300">
<animate attributeName="x1" from="1250" to="1000" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="1250" to="1000" dur="2s" repeatCount="indefinite" />
</line>
</svg>
<div class="zero-cross-point"></div>
</div>
<div class="video-container">
<div class="chart-label">Output: DC Digital Signal</div>
<svg class="square-wave" viewBox="0 0 1000 300" preserveAspectRatio="none">
<defs>
<path id="squareWave" d="M-250,75 L-250,225 L0,225 L0,75 L250,75 L250,225 L500,225 L500,75 L750,75 L750,225 L1000,225 L1000,75 L1250,75 L1250,225" />
</defs>
<line x1="0" y1="225" x2="1000" y2="225" stroke="#4a90e2" stroke-width="2" />
<line x1="500" y1="0" x2="500" y2="300" stroke="#4a90e2" stroke-width="2" />
<polygon class="phase-offset" fill="rgba(255, 75, 75, 0.2)" stroke="none" />
<!-- Red waveform -->
<use xlink:href="#squareWave" x="0" y="0" fill="none" stroke="#ff4b4b" stroke-width="4">
<animate id="squareWaveAnim" attributeName="x" from="0" to="-1000" dur="8s" repeatCount="indefinite" />
</use>
<use xlink:href="#squareWave" x="1000" y="0" fill="none" stroke="#ff4b4b" stroke-width="4">
<animate id="squareWaveAnim2" attributeName="x" from="1000" to="0" dur="8s" repeatCount="indefinite" />
</use>
<!-- Blue waveform -->
<use xlink:href="#squareWave" x="0" y="0" fill="none" stroke="#4a90e2" stroke-width="4">
<animate id="squareWaveAnim3" attributeName="x" from="-24" to="-1024" dur="8s" repeatCount="indefinite" />
</use>
<use xlink:href="#squareWave" x="1000" y="0" fill="none" stroke="#4a90e2" stroke-width="4">
<animate id="squareWaveAnim4" attributeName="x" from="976" to="-24" dur="8s" repeatCount="indefinite" />
</use>
<!-- Green waveform -->
<use xlink:href="#squareWave" x="0" y="0" fill="none" stroke="#34a853" stroke-width="4">
<animate id="squareWaveAnim5" attributeName="x" from="-10" to="-1010" dur="8s" repeatCount="indefinite" />
</use>
<use xlink:href="#squareWave" x="1000" y="0" fill="none" stroke="#34a853" stroke-width="4">
<animate id="squareWaveAnim6" attributeName="x" from="990" to="-10" dur="8s" repeatCount="indefinite" />
</use>
<!-- Yellow waveform -->
<use xlink:href="#squareWave" x="0" y="0" fill="none" stroke="#fbbc05" stroke-width="4">
<animate id="squareWaveAnim7" attributeName="x" from="10" to="-990" dur="8s" repeatCount="indefinite" />
</use>
<use xlink:href="#squareWave" x="1000" y="0" fill="none" stroke="#fbbc05" stroke-width="4">
<animate id="squareWaveAnim8" attributeName="x" from="1010" to="10" dur="8s" repeatCount="indefinite" />
</use>
<line class="zero-cross-line" x1="0" y1="0" x2="0" y2="300">
<animate attributeName="x1" from="250" to="0" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="250" to="0" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="500" y1="0" x2="0" y2="300">
<animate attributeName="x1" from="500" to="250" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="500" to="250" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="750" y1="0" x2="0" y2="300">
<animate attributeName="x1" from="750" to="500" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="750" to="500" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="1000" y1="0" x2="750" y2="300">
<animate attributeName="x1" from="1000" to="750" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="1000" to="750" dur="2s" repeatCount="indefinite" />
</line>
<line class="zero-cross-line" x1="1250" y1="0" x2="1000" y2="300">
<animate attributeName="x1" from="1250" to="1000" dur="2s" repeatCount="indefinite" />
<animate attributeName="x2" from="1250" to="1000" dur="2s" repeatCount="indefinite" />
</line>
</svg>
<div class="digital-output-indicator indicator-dot red"></div>
<div class="digital-output-indicator indicator-dot blue"></div>
<div class="digital-output-indicator indicator-dot green"></div>
<div class="digital-output-indicator indicator-dot yellow"></div>
<div class="digital-output-label">OFF</div>
<div class="offset-area"></div>
</div>
<div class="toggle-controls">
<h2>Adjust Signal Phase Offset:</h2>
<button class="toggle-button" data-color="#ff4b4b">0uS</button>
<button class="toggle-button" data-color="#4a90e2">-480uS</button>
<button class="toggle-button" data-color="#34a853">-200uS</button>
<button class="toggle-button" data-color="#fbbc05">+200uS</button>
</div>
<div class="video-description">
<h2>Understanding Zero-Crossing Detection</h2>
<p>
<li>AC Power Supply: the red indicator appears when the the zero crossing is detected.</li>
<li>DC Digital Signal: the red indicator shows when the signal value is high (ON state), and disappears when the signal value is low (OFF state).</li>
<li>The effect of different offsets on the timing of the digital output can be observed by toggling the buttons.</li>
<li>Offsetting the phase of the signal can provide valuable extra time for external processes so that switching can be synchronized accurately.</li></p>
</div>
</main>
</div>
<footer>
<p>© 2024 SynchroPoint Ltd. All rights reserved.</p>
<p>
<a href="https://synchropoint.co.uk/privacy">Privacy Policy</a> |
<a href="https://synchropoint.co.uk/terms">Terms of Service</a>
</p>
</footer>
<script>
document.addEventListener('DOMContentLoaded', () => {
const zeroCrossDot = document.querySelector('.zero-cross-point');
const digitalOutputDots = {
'#ff4b4b': document.querySelector('.indicator-dot.red'),
'#4a90e2': document.querySelector('.indicator-dot.blue'),
'#34a853': document.querySelector('.indicator-dot.green'),
'#fbbc05': document.querySelector('.indicator-dot.yellow')
};
const offsets = {
'#ff4b4b': 0, // Red: 0uS
'#4a90e2': -480, // Blue: -480uS
'#34a853': -200, // Green: -200uS
'#fbbc05': 200 // Yellow: +200uS
};
const digitalOutputLabel = document.querySelector('.digital-output-label');
const squareWaveAnims = document.querySelectorAll('.square-wave use');
const offsetArea = document.querySelector('.offset-area');
const toggleButtons = document.querySelectorAll('.toggle-button');
const defaultColor = '#ff4b4b'; // Default color is red
const animationDuration = 4000; // 4000ms for 50Hz
const peakAmplitude = 75; // Half of the 150px vertical range
const thresholdPercentage = 0.15; // 15% of peak amplitude
let activeColor = defaultColor; // Track the currently active waveform color
function showZeroCrossDot() {
zeroCrossDot.style.opacity = '1';
}
function hideZeroCrossDot() {
zeroCrossDot.style.opacity = '0';
}
function updateDigitalOutput(isHigh) {
Object.keys(digitalOutputDots).forEach(color => {
const dot = digitalOutputDots[color];
dot.style.opacity = (isHigh && color === activeColor) ? '1' : '0';
});
digitalOutputLabel.textContent = isHigh ? 'ON' : 'OFF';
}
function calculateSineValue(t) {
return Math.sin(2 * Math.PI * t);
}
const crossingInterval = animationDuration / 2; // Two crossings per cycle
let startTime = Date.now();
let currentOffset = 0;
function checkStates() {
const elapsed = (Date.now() - startTime) % animationDuration;
const t = elapsed / animationDuration;
const sineValue = calculateSineValue(t);
const threshold = thresholdPercentage * peakAmplitude;
if (Math.abs(sineValue * peakAmplitude) < threshold) {
showZeroCrossDot();
} else {
hideZeroCrossDot();
}
// Adjust for the offset and determine the digital output state
const offset = offsets[activeColor] /2|| 0;
const totalDuration = animationDuration;
const cycleDuration = totalDuration / 2; // Duration of one high/low cycle
// Calculate the current position adjusted by the offset
const now = (Date.now() - startTime) % totalDuration;
const adjustedTime = (now - offset + totalDuration) % totalDuration; // Correcting offset inversion
// Determine if the adjusted time is within the high state period
const isHighState = adjustedTime >= 0 && adjustedTime < cycleDuration;
// Update digital output based on the high/low state
updateDigitalOutput(isHighState);
}
function animate() {
checkStates();
requestAnimationFrame(animate);
}
animate();
function updateSquareWaveAnimation() {
squareWaveAnims.forEach(anim => {
const color = anim.getAttribute('stroke');
const offset = offsets[color] || 0; // Get the specific offset for the color
const cycleDuration = animationDuration / 2; // Duration of one full cycle (high and low)
const totalDuration = animationDuration; // Full period duration
// Calculate the offset for this animation
const newFrom = (offset % totalDuration + totalDuration) % totalDuration;
const newTo = (newFrom + cycleDuration) % totalDuration;
anim.setAttribute('from', newFrom);
anim.setAttribute('to', newTo);
// Adjust indicator dot visibility
if (color in digitalOutputDots) {
const dot = digitalOutputDots[color];
dot.style.transition = 'opacity 0.1s ease';
// Determine if current time is in high state
const now = (Date.now() - startTime) % totalDuration;
const adjustedTime = (now + offset) % totalDuration;
const isHighState = adjustedTime >= newFrom && adjustedTime < newTo;
dot.style.opacity = isHighState ? '1' : '0';
}
});
// Offset area handling
const svgWidth = 1000; // Assuming the SVG width is 1000 pixels
const periodMicroseconds = 20000; // 10,000 microseconds half cycle for 50Hz wave
if (offsets[activeColor] !== 0) {
const offsetPixels = (Math.abs(offsets[activeColor]) / periodMicroseconds) * svgWidth;
const offsetPercentage = (offsetPixels / svgWidth) * 100;
offsetArea.style.width = `${offsetPercentage}%`;
offsetArea.style.left = offsets[activeColor] < 0
? `${50 - (offsetPixels/2) / svgWidth * 100}%`
: `${50 + (offsetPixels/2) / svgWidth * 100}%`;
offsetArea.style.display = 'block';
// Adjust indicator dot position
digitalOutputDots[activeColor].style.left = offsets[activeColor] < 0
? `${50}%`
: `${50}%`;
} else {
offsetArea.style.display = 'none';
}
}
function activateButton(button) {
const color = button.getAttribute('data-color');
const waveforms = document.querySelectorAll(`.square-wave use[stroke="${color}"]`);
button.classList.add('active');
waveforms.forEach(waveform => waveform.style.display = 'inline');
activeColor = color;
// Update the animation with the new color's offset
updateSquareWaveAnimation();
}
function deactivateButton(button) {
const color = button.getAttribute('data-color');
const waveforms = document.querySelectorAll(`.square-wave use[stroke="${color}"]`);
button.classList.remove('active');
waveforms.forEach(waveform => waveform.style.display = 'none');
// Check if any buttons are active
if (![...toggleButtons].some(btn => btn.classList.contains('active'))) {
activeColor = defaultColor;
// Hide offset area when no buttons are active
offsetArea.style.display = 'none';
// Update the animation with default offset
updateSquareWaveAnimation();
} else {
// If other buttons are active, update animation for the remaining active color
const activeButton = [...toggleButtons].find(btn => btn.classList.contains('active'));
if (activeButton) {
const color = activeButton.getAttribute('data-color');
activeColor = color;
updateSquareWaveAnimation();
}
}
}
function setDefaultButton() {
const defaultButton = [...toggleButtons].find(btn => btn.getAttribute('data-color') === defaultColor);
if (defaultButton) {
activateButton(defaultButton);
}
}
toggleButtons.forEach(button => {
button.addEventListener('click', function () {
toggleButtons.forEach(btn => {
if (btn !== this) {
deactivateButton(btn);
}
});
if (this.classList.contains('active')) {
deactivateButton(this);
setDefaultButton();
} else {
activateButton(this);
}
});
});
// Initialize the default button and update the animation
setDefaultButton();
});
</script>
</body>
</html>