actuate
Version:
Actuate is a flexible, fast "tween" library for animations
119 lines (101 loc) • 3.16 kB
JavaScript
// Class: motion._MotionPath.BezierSplinePath
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../hxClasses_stub").default;
var $import = require("./../../import_stub").default;
var $extend = require("./../../extend_stub").default;
function motion__$MotionPath_ComponentPath() {return require("./../../motion/_MotionPath/ComponentPath");}
function motion__$MotionPath_BezierPath() {return require("./../../motion/_MotionPath/BezierPath");}
// Constructor
var BezierSplinePath = function(through,strength) {
(motion__$MotionPath_ComponentPath().default).call(this);
this.through = through;
this.strength = strength;
}
// Meta
BezierSplinePath.__name__ = ["motion","_MotionPath","BezierSplinePath"];
BezierSplinePath.__isInterface__ = false;
BezierSplinePath.__super__ = (motion__$MotionPath_ComponentPath().default);
BezierSplinePath.prototype = $extend((motion__$MotionPath_ComponentPath().default).prototype, {
computeControlPoints: function(start) {
var K = [start].concat(this.through);
var n = K.length;
var _g = [];
var _g2 = 0;
var _g1 = n;
while(_g2 < _g1) {
var _ = _g2++;
_g.push([0.0,0.0]);
}
var control = _g;
var a = [];
var b = [];
var c = [];
var r = [];
a[0] = 0;
b[0] = 2;
c[0] = 1;
r[0] = K[0] + 2 * K[1];
var _g21 = 1;
var _g11 = n - 1;
while(_g21 < _g11) {
var i = _g21++;
a[i] = 1;
b[i] = 4;
c[i] = 1;
r[i] = 4 * K[i] + 2 * K[i + 1];
}
a[n - 1] = 1;
b[n - 1] = 2;
c[n - 1] = 0;
r[n - 1] = 3 * K[n - 1];
var _g22 = 1;
var _g12 = n;
while(_g22 < _g12) {
var i1 = _g22++;
var m = a[i1] / b[i1 - 1];
b[i1] -= m * c[i1 - 1];
r[i1] -= m * r[i1 - 1];
}
control[n - 1][0] = r[n - 1] / b[n - 1];
var i2 = n - 2;
while(i2 >= 0) {
control[i2][0] = (r[i2] - c[i2] * control[i2 + 1][0]) / b[i2];
--i2;
}
var _g23 = 0;
var _g13 = n - 1;
while(_g23 < _g13) {
var i3 = _g23++;
control[i3][1] = 2 * K[i3 + 1] - control[i3 + 1][0];
}
control[n - 1][1] = 0.5 * (K[n] + control[n - 1][0]);
control.pop();
return control;
},
set_start: function(value) {
if(this.paths.length == 0 || Math.abs(value - this.get_start()) > 1e-7) {
var control = this.computeControlPoints(value);
var pathStrength = this.strength / control.length;
this.strength = 0;
this.paths.splice(0,this.paths.length);
var _g1 = 0;
var _g = control.length;
while(_g1 < _g) {
var i = _g1++;
this.addPath(new (motion__$MotionPath_BezierPath().default)(this.through[i],control[i],pathStrength));
}
}
return (motion__$MotionPath_ComponentPath().default).prototype.set_start.call(this,value);
},
get_end: function() {
return this.through[this.through.length - 1];
}
});
BezierSplinePath.prototype.__class__ = BezierSplinePath.prototype.constructor = $hxClasses["motion._MotionPath.BezierSplinePath"] = BezierSplinePath;
// Init
// Statics
// Export
exports.default = BezierSplinePath;