Created
February 6, 2021 09:07
-
-
Save misterbailey/8ec921cd82d03bd49f195e7e614954fa to your computer and use it in GitHub Desktop.
Javascript oscillation function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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