24 lines
407 B
JavaScript
24 lines
407 B
JavaScript
/* Crude approximation of a sine wave
|
|
|
|
node gen_wave_form.js
|
|
|
|
Or paste in browser developer console.
|
|
*/
|
|
|
|
const steps = 180;
|
|
|
|
let output = `
|
|
const char SINE_WAVEFORM[${steps}] = {`;
|
|
|
|
for (let i = 0; i < steps; i++) {
|
|
if (i % 5 === 0) {
|
|
output += `
|
|
/* ${i} */`
|
|
}
|
|
output += ` ${Math.floor(255 * (1 + Math.sin(2 * Math.PI / steps * i)) / 2)},`;
|
|
}
|
|
|
|
output += `
|
|
};`;
|
|
|
|
console.log(output);
|