<commit_before>/**
 * @class  	Animator
 * @author 	<NAME> <<EMAIL>>
 */

var Matrix = require('T/matrix');

function noop() {}

function simpleFromTo(view, a, b, callback) {
	view.applyProperties(a);
	_.defer(function(){
		view.animate(b, _.isFunction(callback) ? callback : noop);
	});
}

/**
 * @method fadeIn
 */
exports.fadeIn = function(opt) {
	_.defaults(opt, {
		duration: 400
	});

	return simpleFromTo(opt.view,
	{ opacity: 0 },
	{ opacity: 1, duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeOut
 */
exports.fadeOut = function(opt) {
	_.defaults(opt, {
		duration: 400
	});

	return  simpleFromTo(opt.view,
	{ opacity: 1 },
	{ opacity: 0, duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInUp
 */
exports.fadeInUp = function(opt) {
	_.defaults(opt, {
		duration: 5000,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Ti.UI.create2DMatrix().translate(0, -opt.offset) },
	{ opacity: 1, transform: Ti.UI.create2DMatrix(), duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInDown
 */
exports.fadeInLeft = function(opt) {
	_.defaults(opt, {
		duration: 400,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Ti.UI.create2DMatrix().translate(-opt.offset, 0) },
	{ opacity: 1, transform: Ti.UI.create2DMatrix(), duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInBottom
 */
exports.fadeInBottom = function(opt) {
	_.defaults(opt, {
		duration: 400,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Ti.UI.create2DMatrix().translate(0, opt.offset) },
	{ opacity: 1, transform: Ti.UI.create2DMatrix(), duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInRight
 */
exports.fadeInRight = function(opt) {
	_.defaults(opt, {
		duration: 400,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Ti.UI.create2DMatrix().translate(opt.offset, 0) },
	{ opacity: 1, transform: Ti.UI.create2DMatrix(), duration: opt.duration },
	opt.callback);
};

/**
 * @method upAndDown
 * @return {Function}
 */
exports.upAndDown = function(opt) {
	var self = {};
	var run = true;

	self.stop = function() {
		run = false;
	};

	_.defaults(opt, {
		duration: 1000,
		y: 10
	});

	var index = 0;
	(function loop() {
		if (run === false) return;

		index = (index+1) % 2;
		_.defer(function(){
			opt.view.animate({
				transform: Ti.UI.create2DMatrix().translate(0, index ? opt.y : 0),
				duration: opt.duration
			}, loop);
		});
	})();

	return self;
};

/**
 * @method fallDownForGravity
 * @return {Function}
 */
exports.fallDownForGravity = function(opt) {
	var self = {};
	var run = true;
	var timeout = null;

	self.stop = function() {
		clearTimeout(timeout);
		run = false;
	};

	_.defaults(opt, {
		friction: 0.6,
		potentialEnergy: 10,
		y: 60,<commit_msg>animator now use matrix, really<commit_after>/**
 * @class  	Animator
 * @author 	<NAME> <<EMAIL>>
 */

var Matrix = require('T/matrix');

function noop() {}

function simpleFromTo(view, a, b, callback) {
	view.applyProperties(a);
	_.defer(function(){
		view.animate(b, _.isFunction(callback) ? callback : noop);
	});
}

/**
 * @method fadeIn
 */
exports.fadeIn = function(opt) {
	_.defaults(opt, {
		duration: 400
	});

	return simpleFromTo(opt.view,
	{ opacity: 0 },
	{ opacity: 1, duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeOut
 */
exports.fadeOut = function(opt) {
	_.defaults(opt, {
		duration: 400
	});

	return  simpleFromTo(opt.view,
	{ opacity: 1 },
	{ opacity: 0, duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInUp
 */
exports.fadeInUp = function(opt) {
	_.defaults(opt, {
		duration: 5000,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Matrix.i().t(0, -opt.offset) },
	{ opacity: 1, transform: Matrix.i(), duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInDown
 */
exports.fadeInLeft = function(opt) {
	_.defaults(opt, {
		duration: 400,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Matrix.i().t(-opt.offset, 0) },
	{ opacity: 1, transform: Matrix.i(), duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInBottom
 */
exports.fadeInBottom = function(opt) {
	_.defaults(opt, {
		duration: 400,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Matrix.i().t(0, opt.offset) },
	{ opacity: 1, transform: Matrix.i(), duration: opt.duration },
	opt.callback);
};

/**
 * @method fadeInRight
 */
exports.fadeInRight = function(opt) {
	_.defaults(opt, {
		duration: 400,
		offset: 50
	});

	return simpleFromTo(opt.view,
	{ opacity: 0, transform: Matrix.i().t(opt.offset, 0) },
	{ opacity: 1, transform: Matrix.i(), duration: opt.duration },
	opt.callback);
};

/**
 * @method upAndDown
 * @return {Function}
 */
exports.upAndDown = function(opt) {
	var self = {};
	var run = true;

	self.stop = function() {
		run = false;
	};

	_.defaults(opt, {
		duration: 1000,
		y: 10
	});

	var index = 0;
	(function loop() {
		if (run === false) return;

		index = (index+1) % 2;
		_.defer(function(){
			opt.view.animate({
				transform: Matrix.i().t(0, index ? opt.y : 0),
				duration: opt.duration
			}, loop);
		});
	})();

	return self;
};

/**
 * @method fallDownForGravity
 * @return {Function}
 */
exports.fallDownForGravity = function(opt) {
	var self = {};
	var run = true;
	var timeout = null;

	self.stop = function() {
		clearTimeout(timeout);
		run = false;
	};

	_.defaults(opt, {
		friction: 0.6,
		potentialEnergy: 10,
		y: 60,
{'fraction_non_alphanumeric': 0.18501086169442432, 'fraction_numerical': 0.02335264301230992, 'mean_word_length': 3.6506734006734005, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5409411', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2007, 'n_words': 435}