Skip to content

Instantly share code, notes, and snippets.

@misterbailey
Created February 6, 2021 09:07
Show Gist options
  • Save misterbailey/8ec921cd82d03bd49f195e7e614954fa to your computer and use it in GitHub Desktop.
Save misterbailey/8ec921cd82d03bd49f195e7e614954fa to your computer and use it in GitHub Desktop.
Javascript oscillation function
/**
* Ossilate - Make things go back and forth!
* TODO: Easings
* @param {Number} amplitude The distance from the center of motion to either extreme.
* @param {Number} interval The amount of time it takes for one complete cycle of motion in frames.
* @param {Number} time The current frame count, ideally a deltaTime value.
* @param {String} trigonometricFunction The function to be used to calculate the value. Defaults to 'sin'.
*/
oscillate = (amplitude, interval, time, trigonometricFunction = 'sin') => {
return amplitude * Math[trigonometricFunction]((Math.PI * 2.0) * time / interval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment