Sounds like you may want to take a look at this.
Some of this is irrelevant to your problem but the parametric equation part and the fourier series part might be useful.
Also Daniel Shiffman’s fourier series challenge
This could be combined with some audio synth.
This last one is p5.js but it should give you so hints to the approach required.