79315032

Date: 2024-12-29 05:59:37
Score: 2
Natty:
Report link

@Meeesta I was looking create an effect similar to the mathisfun example you shared. I was successful by separating frequency from amplitude to generate the wave. So rather than:

const y = Math.sin(t + frequency) * amplitude); // Don't do this for this scenario

Instead I do this (pseudo code):

// calculate Y value
const frequencySpeed = frequency * deltaTime;
phase -= frequencySpeed; // cumulative phase shifts left
const y = Math.sin(phase + deltaTime) * amplitude;

// calculate X value
const waveSpeed = frequency * wavelength * deltaTime;
const x -= waveSpeed; // do this for each x value in your wave line

Here is a working example.

I am not sure the math is 100% accurate but it's close enough for my purposes.

Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Meeesta
  • Low reputation (1):
Posted by: Constructivist