4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-fx-CubicBezier'>/**
19 </span> * @class Ext.fx.CubicBezier
22 Ext.define('Ext.fx.CubicBezier', {
24 /* Begin Definitions */
30 cubicBezierAtTime: function(t, p1x, p1y, p2x, p2y, duration) {
32 bx = 3 * (p2x - p1x) - cx,
35 by = 3 * (p2y - p1y) - cy,
37 function sampleCurveX(t) {
38 return ((ax * t + bx) * t + cx) * t;
40 function solve(x, epsilon) {
41 var t = solveCurveX(x, epsilon);
42 return ((ay * t + by) * t + cy) * t;
44 function solveCurveX(x, epsilon) {
45 var t0, t1, t2, x2, d2, i;
46 for (t2 = x, i = 0; i < 8; i++) {
47 x2 = sampleCurveX(t2) - x;
48 if (Math.abs(x2) < epsilon) {
51 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
52 if (Math.abs(d2) < 1e-6) {
67 x2 = sampleCurveX(t2);
68 if (Math.abs(x2 - x) < epsilon) {
76 t2 = (t1 - t0) / 2 + t0;
80 return solve(t, 1 / (200 * duration));
83 cubicBezier: function(x1, y1, x2, y2) {
84 var fn = function(pos) {
85 return Ext.fx.CubicBezier.cubicBezierAtTime(pos, x1, y1, x2, y2, 1);
87 fn.toCSS3 = function() {
88 return 'cubic-bezier(' + [x1, y1, x2, y2].join(',') + ')';
90 fn.reverse = function() {
91 return Ext.fx.CubicBezier.cubicBezier(1 - x2, 1 - y2, 1 - x1, 1 - y1);