Last active
October 26, 2021 12:15
-
-
Save william-silversmith/370702d7d50b1ac02a15 to your computer and use it in GitHub Desktop.
An ease-in-out curve that has customizable steepness.
This file contains hidden or 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
| /* sigmoidFactory | |
| * | |
| * Generate an ease-in-out function with desired steepness. | |
| * Accompanying article: https://medium.com/analytic-animations/ease-in-out-the-sigmoid-factory-c5116d8abce9 | |
| * | |
| * Required: | |
| * k: (float != 0), sharpness of ease | |
| * | |
| * Return: f(t), t in 0..1 | |
| */ | |
| function sigmoidFactory (k) { | |
| function base (t) { | |
| return (1 / (1 + Math.exp(-k * t))) - 0.5; | |
| } | |
| var correction = 0.5 / base(1); | |
| return function (t) { | |
| t = clamp(t, 0, 1); | |
| return correction * base(2 * t - 1) + 0.5; | |
| }; | |
| } | |
| function clamp (val, lower, upper) { | |
| return Math.max(Math.min(val, upper), lower); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment