1 // ========================================================================== 2 // Project: SproutCore - JavaScript Application Framework 3 // Copyright: ©2014 7x7 Software Inc. All rights reserved. 4 // Portions ©2008-2011 Apple Inc. All rights reserved. 5 // License: Licensed under MIT license (see license.js) 6 // ========================================================================== 7 8 /** @private Kept private until fully fleshed out. 9 A cubic bezier equation. Used by the SC.easingCurve function. 10 */ 11 SC.CubicBezierEquation = function (C1, C2, C3, C4) { 12 13 var B1 = function (t) { return (1 - t) * (1 - t) * (1 - t); }; 14 var B2 = function (t) { return 3 * t * (1 - t) * (1 - t); }; 15 var B3 = function (t) { return 3 * t * t * (1 - t); }; 16 var B4 = function (t) { return t * t * t; }; 17 18 this.position = function (percent) { 19 var pos = {}; 20 21 pos.x = C1.x * B1(percent) + C2.x * B2(percent) + C3.x * B3(percent) + C4.x * B4(percent); 22 pos.y = C1.y * B1(percent) + C2.y * B2(percent) + C3.y * B3(percent) + C4.y * B4(percent); 23 24 return pos; 25 }; 26 27 }; 28 29 /** @private Kept private until fully fleshed out (name change?). 30 A specialized bezier curve with fixed start at 0,0 and fixed end at 1,1. 31 32 */ 33 SC.easingCurve = function (C2x, C2y, C3x, C3y) { 34 35 var C1 = { x: 0, y: 0 }, 36 C2 = { x: C2x, y: C2y }, 37 C3 = { x: C3x, y: C3y }, 38 C4 = { x: 1, y: 1 }; 39 40 var equation = new SC.CubicBezierEquation(C1, C2, C3, C4); 41 42 equation.value = function (percent) { 43 percent = Math.max(0, Math.min(percent, 1)); 44 return this.position(percent).y; 45 }; 46 47 equation.toString = function () { 48 return "cubic-bezier(%@, %@, %@, %@)".fmt(C2x, C2y, C3x, C3y); 49 }; 50 51 return equation; 52 }; 53