DEV Community

Cover image for Playing with a sine wave
Matt Ellen
Matt Ellen

Posted on

Playing with a sine wave

I was inspired to make a this toy project by a question on Stack Overflow asking about generating sine waves.

You can adjust the frequency, amplitude and phase of the wave. The chart spans two seconds. Frequency can be set between 1 and 100Hz, mostly because anything above 100hz becomes indistinguishable at this resolution. Amplitude can be set between 0 and 1. Phase can be set between 0 and 2π (well kinda, javascript maths being what it is).

There is a validation error that pops up on the phase slider, due to ieee floating point rounding and me wanting the slider to move in steps of π/100. I'm not sure the best way to get rid of that.

Top comments (0)