-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
287 lines (251 loc) · 8.42 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AC Wave Generator</title>
<style>
body {
background-color: #57575b;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
min-height: 1570px; /* Increased the minimum height by 3% */
}
header {
background-color: #333;
color: #fff;
padding: 10px;
text-align: center;
}
footer {
background-color: #333;
color: #fff;
padding: 10px;
text-align: center;
position: fixed;
bottom: 0;
width: 100%;
}
.introduction {
background-color: #f0f0f0;
padding: 20px;
text-align: left;
max-width: 800px;
margin: 20px auto;
border-radius: 10px;
}
.introduction p {
font-size: 18px;
line-height: 1.6;
}
.waveform-container {
width: 100%;
height: 400px;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
overflow: auto;
margin-top: 20px;
}
#waveform {
width: 200%;
height: 80%;
border: 1px solid #000;
}
.coordinate-system {
position: absolute;
bottom: 0;
left: 0;
transform: translateY(50%);
font-size: 12px;
color: #888;
}
.controls {
text-align: center;
margin-top: 20px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
justify-content: center;
padding-bottom: 60px;
/* Add padding to avoid overlap with footer */
}
.controls label,
.controls input[type="checkbox"],
.controls input[type="number"] {
width: 100%;
box-sizing: border-box;
margin: 5px;
}
.controls div {
margin: 10px;
}
</style>
</head>
<body>
<header>
<h1>AC Wave Generator</h1>
</header>
<div class="introduction">
<p>Welcome to the AC Wave Generator!</p>
<p>This tool Created by <b>Ank Gupta of class 12th Science A</b> allows you to visualize and manipulate
alternating
current (AC) waveforms. You can adjust
parameters such as amplitude, frequency, phase, DC offset, harmonics, and noise to observe their effects on
the wave.</p>
<p>Experiment with different wave types including sine, square, triangular, and sawtooth waves to understand
their characteristics.</p>
<p>Have fun exploring!</p>
</div>
<div class="waveform-container">
<canvas id="waveform"></canvas>
<div class="coordinate-system">
<span>Amplitude ↑</span><br>
<span>|</span><br>
<span>|</span><br>
<span>|</span><br>
<span>|</span><br>
<span>|</span><br>
<span>|</span><br>
<span>|</span><br>
<span>|</span><br>
<span>|</span><br>
<span>----------------------------> Time ↓</span>
</div>
</div>
<div class="controls">
<div>
<label for="amplitude">Amplitude:</label>
<input type="number" id="amplitude" min="0" max="200" value="100" oninput="updateAmplitude(this.value)">
</div>
<div>
<label for="frequency">Frequency:</label>
<input type="number" id="frequency" min="0" max="10" value="1" step="0.1"
oninput="updateFrequency(this.value)">
</div>
<div>
<label for="phase">Phase (degrees):</label>
<input type="number" id="phase" min="0" max="360" value="0" oninput="updatePhase(this.value)">
</div>
<div>
<label for="dcOffset">DC Offset:</label>
<input type="number" id="dcOffset" min="-100" max="100" value="0" oninput="updateDCOffset(this.value)">
</div>
<div>
<label for="harmonics">Harmonics:</label>
<input type="number" id="harmonics" min="0" max="10" value="0" oninput="updateHarmonics(this.value)">
</div>
<div>
<label for="noise">Noise:</label>
<input type="number" id="noise" min="0" max="100" value="0" oninput="updateNoise(this.value)">
</div>
<div>
<input type="checkbox" id="squareWave" onchange="updateWaveType()">
<label for="squareWave">Square Wave</label>
</div>
<div>
<input type="checkbox" id="triangularWave" onchange="updateWaveType()">
<label for="triangularWave">Triangular Wave</label>
</div>
<div>
<input type="checkbox" id="sawtoothWave" onchange="updateWaveType()">
<label for="sawtoothWave">Sawtooth Wave</label>
</div>
<br>
<button id="toggleButton" onclick="toggleWave()">Start Wave</button>
</div>
<footer>
<p>Made with ❤️ by Ank Gupta</p>
</footer>
<script>
let angle = 0;
let amplitude = 100;
let frequency = 1;
let phase = 0;
let dcOffset = 0;
let harmonics = 0;
let noise = 0;
let canvas;
let isWaveRunning = false;
let waveType = 'sine';
function setup() {
canvas = document.getElementById('waveform');
canvas.width = window.innerWidth * 1.8;
canvas.height = 400;
draw();
}
function draw() {
let ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.moveTo(0, canvas.height / 2);
for (let i = 0; i < canvas.width; i += 4) {
let n = i * frequency / canvas.width;
let r = amplitude * Math.sin(2 * Math.PI * n + phase * Math.PI / 180);
if (waveType === 'square') {
r = r >= 0 ? amplitude : -amplitude;
} else if (waveType === 'triangular') {
r = amplitude * (2 * Math.abs(n - Math.floor(n + 0.5)) - 1);
} else if (waveType === 'sawtooth') {
r = amplitude * (n - Math.floor(n));
}
// Add harmonics
for (let h = 2; h <= harmonics; h++) {
r += amplitude / h * Math.sin(2 * Math.PI * h * n + phase * Math.PI / 180);
}
// Add noise
r += (Math.random() - 0.5) * noise;
let y = canvas.height / 2 + r * Math.sin(angle) + dcOffset;
ctx.lineTo(i, y);
}
ctx.stroke();
angle += 0.1;
if (isWaveRunning) {
requestAnimationFrame(draw);
}
}
function updateAmplitude(value) {
amplitude = value;
}
function updateFrequency(value) {
frequency = value;
}
function updatePhase(value) {
phase = value;
}
function updateDCOffset(value) {
dcOffset = value;
}
function updateHarmonics(value) {
harmonics = value;
}
function updateNoise(value) {
noise = value;
}
function updateWaveType() {
if (document.getElementById('squareWave').checked) {
waveType = 'square';
} else if (document.getElementById('triangularWave').checked) {
waveType = 'triangular';
} else if (document.getElementById('sawtoothWave').checked) {
waveType = 'sawtooth';
} else {
waveType = 'sine';
}
}
function toggleWave() {
isWaveRunning = !isWaveRunning;
if (isWaveRunning) {
draw();
document.getElementById('toggleButton').textContent = 'Stop Wave';
} else {
document.getElementById('toggleButton').textContent = 'Start Wave';
}
}
setup();
</script>
</body>
</html>