Created
January 5, 2015 16:37
-
-
Save drhayes/7749fea12dd634ac03fe to your computer and use it in GitHub Desktop.
bezier curve functions for ImpactJS.
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
| ig.module( | |
| 'game.util.bezier' | |
| ) | |
| .defines(function() { | |
| 'use strict'; | |
| // With the help of: http://www.moshplant.com/direct-or/bezier/math.html | |
| // Code totally stolen from processing.js. | |
| // 0 <= t <= 1 | |
| window.bezierPoint = function bezierPoint(a,b,c,d,t) { | |
| return (1-t)*(1-t)*(1-t)*a+3*(1-t)*(1-t)*t*b+3*(1-t)*t*t*c+t*t*t*d; | |
| } | |
| window.bezierTangent = function bezierTangent(a,b,c,d,t) { | |
| return (3*t*t*(-a+3*b-3*c+d)+6*t*(a-2*b+c)+3*(-a+b)); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment