Last active
August 29, 2015 14:26
-
-
Save cmargroff/a34f9627a9b873a338c0 to your computer and use it in GitHub Desktop.
Cubic Bezier interpolation class for javascript animation.
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
| function cubicBezier(x1, y1, x2, y2){ | |
| var p1 = [x1, y1], p2 = [x2, y2]; | |
| this.calculate = function(t){ | |
| return [ | |
| 0 * Math.pow(1-t, 3) + p1[0] * 3 * Math.pow(1-t, 2) * t + p2[0] * 3 * (1-t) * Math.pow(t, 2) + 1 * Math.pow(t, 3), | |
| 0 * Math.pow(1-t, 3) + p1[1] * 3 * Math.pow(1-t, 2) * t + p2[1] * 3 * (1-t) * Math.pow(t, 2) + 1 * Math.pow(t, 3), | |
| ]; | |
| }; | |
| } | |
| // Example | |
| // var easeOut = new cubicBezier(0,0,0.6,1); | |
| // easeOut.calculate(0.5); //[0.35, 0.5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment