From 3d3c7b47e4250f449089877202afa2fa18ff59cd Mon Sep 17 00:00:00 2001 From: David Figatner Date: Tue, 5 Jun 2018 09:18:48 +0800 Subject: [PATCH] better bundling --- {dist => bundle}/pixi-ease.js | 7005 +++++++++-------- bundle/pixi-ease.min.js | 1 + dist/pixi-ease.min.js | 3992 ---------- docs/jsdoc/Ease.html | 2 +- docs/jsdoc/EventEmitter.html | 2 +- docs/jsdoc/face.html | 2 +- docs/jsdoc/global.html | 2 +- docs/jsdoc/index.html | 2 +- docs/jsdoc/movie.html | 2 +- .../node_modules_eventemitter3_index.js.html | 2 +- ...es_eventemitter3_umd_eventemitter3.js.html | 2 +- docs/jsdoc/shake.html | 2 +- docs/jsdoc/src_face.js.html | 2 +- docs/jsdoc/src_list.js.html | 2 +- docs/jsdoc/src_load.js.html | 2 +- docs/jsdoc/src_movie.js.html | 2 +- docs/jsdoc/src_shake.js.html | 2 +- docs/jsdoc/src_target.js.html | 2 +- docs/jsdoc/src_tint.js.html | 2 +- docs/jsdoc/src_to.js.html | 2 +- docs/jsdoc/src_wait.js.html | 2 +- docs/jsdoc/target.html | 2 +- docs/jsdoc/tint.html | 2 +- docs/jsdoc/to.html | 2 +- docs/jsdoc/wait.html | 2 +- package.json | 4 +- 26 files changed, 3644 insertions(+), 7402 deletions(-) rename {dist => bundle}/pixi-ease.js (58%) create mode 100644 bundle/pixi-ease.min.js delete mode 100644 dist/pixi-ease.min.js diff --git a/dist/pixi-ease.js b/bundle/pixi-ease.js similarity index 58% rename from dist/pixi-ease.js rename to bundle/pixi-ease.js index 5f36fe2..69eb038 100644 --- a/dist/pixi-ease.js +++ b/bundle/pixi-ease.js @@ -1,3857 +1,4090 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o difference ? difference : change; + this.object.rotation += delta * sign; + } + } + }]); - for (i = 0; i < length; i++) { - if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); + return face; +}(wait); - switch (len) { - case 1: listeners[i].fn.call(listeners[i].context); break; - case 2: listeners[i].fn.call(listeners[i].context, a1); break; - case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; - case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; - default: - if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { - args[j - 1] = arguments[j]; - } +module.exports = face; - listeners[i].fn.apply(listeners[i].context, args); - } - } - } +},{"./wait":11,"yy-angle":22}],3:[function(require,module,exports){ +'use strict'; - return true; +var Ease = { + list: require('./list'), + wait: require('./wait'), + to: require('./to'), + shake: require('./shake'), + tint: require('./tint'), + face: require('./face'), + angle: require('./angle'), + target: require('./target'), + movie: require('./movie'), + load: require('./load') }; -/** - * Add a listener for a given event. - * - * @param {(String|Symbol)} event The event name. - * @param {Function} fn The listener function. - * @param {*} [context=this] The context to invoke the listener with. - * @returns {EventEmitter} `this`. - * @public - */ -EventEmitter.prototype.on = function on(event, fn, context) { - return addListener(this, event, fn, context, false); -}; +PIXI.extras.Ease = Ease; -/** - * Add a one-time listener for a given event. - * - * @param {(String|Symbol)} event The event name. - * @param {Function} fn The listener function. - * @param {*} [context=this] The context to invoke the listener with. - * @returns {EventEmitter} `this`. - * @public - */ -EventEmitter.prototype.once = function once(event, fn, context) { - return addListener(this, event, fn, context, true); -}; +module.exports = Ease; -/** - * Remove the listeners of a given event. - * - * @param {(String|Symbol)} event The event name. - * @param {Function} fn Only remove the listeners that match this function. - * @param {*} context Only remove the listeners that have this context. - * @param {Boolean} once Only remove one-time listeners. - * @returns {EventEmitter} `this`. - * @public - */ -EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { - var evt = prefix ? prefix + event : event; +},{"./angle":1,"./face":2,"./list":4,"./load":5,"./movie":6,"./shake":7,"./target":8,"./tint":9,"./to":10,"./wait":11}],4:[function(require,module,exports){ +'use strict'; - if (!this._events[evt]) return this; - if (!fn) { - clearEvent(this, evt); - return this; - } +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - var listeners = this._events[evt]; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - if (listeners.fn) { - if ( - listeners.fn === fn && - (!once || listeners.once) && - (!context || listeners.context === context) - ) { - clearEvent(this, evt); - } - } else { - for (var i = 0, events = [], length = listeners.length; i < length; i++) { - if ( - listeners[i].fn !== fn || - (once && !listeners[i].once) || - (context && listeners[i].context !== context) - ) { - events.push(listeners[i]); - } +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Events = require('eventemitter3'); + +var Angle = require('./angle'); +var Face = require('./face'); +var Load = require('./load'); +var Movie = require('./movie'); +var Shake = require('./shake'); +var Target = require('./target'); +var Tint = require('./tint'); +var To = require('./to'); +var Wait = require('./wait'); + +var Ease = function (_Events) { + _inherits(Ease, _Events); + + /** + * Main class for creating eases + * @param {object} [options] + * @param {boolean} [options.noTicker] don't add the update function to PIXI.ticker + * @param {PIXI.ticker} [options.ticker=PIXI.ticker.shared] use this PIXI.ticker for the list + * @extends eventemitter + * @fire done + * @fire each + */ + function Ease(options) { + _classCallCheck(this, Ease); + + options = options || {}; + + var _this = _possibleConstructorReturn(this, (Ease.__proto__ || Object.getPrototypeOf(Ease)).call(this)); + + if (!options.noTicker) { + var ticker = options.ticker || PIXI.ticker.shared; + ticker.add(function () { + return _this.update(ticker.elapsedMS); + }); + } + _this.list = []; + _this.empty = true; + _this.removeWaiting = []; + _this.removeAllWaiting = false; + return _this; } - // - // Reset the array, or remove it completely if we have no more listeners. - // - if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; - else clearEvent(this, evt); - } + /** + * Add animation(s) to animation list + * @param {(object|object[])} any animation class + * @return {object} first animation + */ - return this; -}; -/** - * Remove all listeners, or those of the specified event. - * - * @param {(String|Symbol)} [event] The event name. - * @returns {EventEmitter} `this`. - * @public - */ -EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { - var evt; + _createClass(Ease, [{ + key: 'add', + value: function add() { + var first = void 0; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = arguments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var arg = _step.value; + + if (Array.isArray(arg)) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = arg[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var entry = _step2.value; + + if (!first) { + first = entry; + } + this.list.push(entry); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } else { + first = arg; + this.list.push(arg); + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } - if (event) { - evt = prefix ? prefix + event : event; - if (this._events[evt]) clearEvent(this, evt); - } else { - this._events = new Events(); - this._eventsCount = 0; - } + this.empty = false; + return first; + } - return this; -}; + /** + * remove animation(s) + * @param {object|array} animate - the animation (or array of animations) to remove; can be null + */ -// -// Alias methods names because people roll like that. -// -EventEmitter.prototype.off = EventEmitter.prototype.removeListener; -EventEmitter.prototype.addListener = EventEmitter.prototype.on; + }, { + key: 'remove', + value: function remove(animate) { + if (this.inUpdate) { + this.removeWaiting.push(animate); + } else { + var index = this.list.indexOf(animate); + if (index !== -1) { + this.list.splice(index, 1); + } + } + } -// -// Expose the prefix. -// -EventEmitter.prefixed = prefix; + /** + * remove all animations from list + * @inherited from yy-loop + */ -// -// Allow `EventEmitter` to be imported as module namespace. -// -EventEmitter.EventEmitter = EventEmitter; + }, { + key: 'removeAll', + value: function removeAll() { + if (this.inUpdate) { + this.removeAllWaiting = true; + } else { + this.list = []; + } + } -// -// Expose the module. -// -if ('undefined' !== typeof module) { - module.exports = EventEmitter; -} + /** + * update frame + * this is automatically added to PIXI.ticker unless options.noTicker is set + * if using options.noTicker, this should be called manually + * @param {number} elasped time in MS since last update + */ -},{}],2:[function(require,module,exports){ + }, { + key: 'update', + value: function update(elapsed) { + this.inUpdate = true; + for (var i = 0, _i = this.list.length; i < _i; i++) { + if (this.list[i] && this.list[i].update(elapsed)) { + this.list.splice(i, 1); + i--; + _i--; + } + } + this.emit('each', this); + if (this.list.length === 0 && !this.empty) { + this.emit('done', this); + this.empty = true; + } + this.inUpdate = false; + if (this.removeAllWaiting) { + this.removeAll(); + this.removeAllWaiting = false; + } + while (this.removeWaiting.length) { + this.remove(this.removeWaiting.pop()); + } + } -/* - Copyright © 2001 Robert Penner - All rights reserved. + /** + * number of animations + * @type {number} + */ - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: + }, { + key: 'to', - Redistributions of source code must retain the above copyright notice, this list of - conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other materials - provided with the distribution. - Neither the name of the author nor the names of contributors may be used to endorse - or promote products derived from this software without specific prior written permission. + /** + * default options for all eases + * @typedef {object} EaseOptions + * @param {object} [EaseOptions.options] + * @param {number} [EaseOptions.options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) + * @param {boolean} [EaseOptions.options.pause] start the animation paused + * @param {boolean|number} [EaseOptions.options.repeat] true: repeat animation forever n: repeat animation n times + * @param {boolean|number} [EaseOptions.options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times + * @param {Function} [EaseOptions.options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set + * @param {string|Function} [EaseOptions.options.ease] name or function from easing.js (see http://easings.net for examples) + */ - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - */ + /** + * ease parameters of object + * @param {PIXI.DisplayObject} object to animate + * @param {object} goto - parameters to animate, e.g.: {alpha: 5, scale: {3, 5}, scale: 5, rotation: Math.PI} + * @param {number} duration - time to run + * @fires done + * @fires wait + * @fires first + * @fires each + * @fires loop + * @fires reverse + */ + value: function to() { + return this.add(new (Function.prototype.bind.apply(To, [null].concat(Array.prototype.slice.call(arguments))))()); + } -(function() { - var penner, umd; + /** + * animate object's {x, y} using an angle + * @param {object} object to animate + * @param {number} angle in radians + * @param {number} speed in pixels/millisecond + * @param {number} [duration=0] in milliseconds; if 0, then continues forever + * @param {object} [options] @see {@link Wait} + */ - umd = function(factory) { - if (typeof exports === 'object') { - return module.exports = factory; - } else if (typeof define === 'function' && define.amd) { - return define([], factory); - } else { - return this.penner = factory; - } - }; + }, { + key: 'angle', + value: function angle() { + return this.add(new (Function.prototype.bind.apply(Angle, [null].concat(Array.prototype.slice.call(arguments))))()); + } - penner = { - linear: function(t, b, c, d) { - return c * t / d + b; - }, - easeInQuad: function(t, b, c, d) { - return c * (t /= d) * t + b; - }, - easeOutQuad: function(t, b, c, d) { - return -c * (t /= d) * (t - 2) + b; - }, - easeInOutQuad: function(t, b, c, d) { - if ((t /= d / 2) < 1) { - return c / 2 * t * t + b; - } else { - return -c / 2 * ((--t) * (t - 2) - 1) + b; - } - }, - easeInCubic: function(t, b, c, d) { - return c * (t /= d) * t * t + b; - }, - easeOutCubic: function(t, b, c, d) { - return c * ((t = t / d - 1) * t * t + 1) + b; - }, - easeInOutCubic: function(t, b, c, d) { - if ((t /= d / 2) < 1) { - return c / 2 * t * t * t + b; - } else { - return c / 2 * ((t -= 2) * t * t + 2) + b; - } - }, - easeInQuart: function(t, b, c, d) { - return c * (t /= d) * t * t * t + b; - }, - easeOutQuart: function(t, b, c, d) { - return -c * ((t = t / d - 1) * t * t * t - 1) + b; - }, - easeInOutQuart: function(t, b, c, d) { - if ((t /= d / 2) < 1) { - return c / 2 * t * t * t * t + b; - } else { - return -c / 2 * ((t -= 2) * t * t * t - 2) + b; - } - }, - easeInQuint: function(t, b, c, d) { - return c * (t /= d) * t * t * t * t + b; - }, - easeOutQuint: function(t, b, c, d) { - return c * ((t = t / d - 1) * t * t * t * t + 1) + b; - }, - easeInOutQuint: function(t, b, c, d) { - if ((t /= d / 2) < 1) { - return c / 2 * t * t * t * t * t + b; - } else { - return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; - } - }, - easeInSine: function(t, b, c, d) { - return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; - }, - easeOutSine: function(t, b, c, d) { - return c * Math.sin(t / d * (Math.PI / 2)) + b; - }, - easeInOutSine: function(t, b, c, d) { - return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; - }, - easeInExpo: function(t, b, c, d) { - if (t === 0) { - return b; - } else { - return c * Math.pow(2, 10 * (t / d - 1)) + b; - } - }, - easeOutExpo: function(t, b, c, d) { - if (t === d) { - return b + c; - } else { - return c * (-Math.pow(2, -10 * t / d) + 1) + b; - } - }, - easeInOutExpo: function(t, b, c, d) { - if (t === 0) { - b; - } - if (t === d) { - b + c; - } - if ((t /= d / 2) < 1) { - return c / 2 * Math.pow(2, 10 * (t - 1)) + b; - } else { - return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; - } - }, - easeInCirc: function(t, b, c, d) { - return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b; - }, - easeOutCirc: function(t, b, c, d) { - return c * Math.sqrt(1 - (t = t / d - 1) * t) + b; - }, - easeInOutCirc: function(t, b, c, d) { - if ((t /= d / 2) < 1) { - return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; - } else { - return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b; - } - }, - easeInElastic: function(t, b, c, d) { - var a, p, s; - s = 1.70158; - p = 0; - a = c; - if (t === 0) { - b; - } else if ((t /= d) === 1) { - b + c; - } - if (!p) { - p = d * .3; - } - if (a < Math.abs(c)) { - a = c; - s = p / 4; - } else { - s = p / (2 * Math.PI) * Math.asin(c / a); - } - return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; - }, - easeOutElastic: function(t, b, c, d) { - var a, p, s; - s = 1.70158; - p = 0; - a = c; - if (t === 0) { - b; - } else if ((t /= d) === 1) { - b + c; - } - if (!p) { - p = d * .3; - } - if (a < Math.abs(c)) { - a = c; - s = p / 4; - } else { - s = p / (2 * Math.PI) * Math.asin(c / a); - } - return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b; - }, - easeInOutElastic: function(t, b, c, d) { - var a, p, s; - s = 1.70158; - p = 0; - a = c; - if (t === 0) { - b; - } else if ((t /= d / 2) === 2) { - b + c; - } - if (!p) { - p = d * (.3 * 1.5); - } - if (a < Math.abs(c)) { - a = c; - s = p / 4; - } else { - s = p / (2 * Math.PI) * Math.asin(c / a); - } - if (t < 1) { - return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; - } else { - return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b; - } - }, - easeInBack: function(t, b, c, d, s) { - if (s === void 0) { - s = 1.70158; - } - return c * (t /= d) * t * ((s + 1) * t - s) + b; - }, - easeOutBack: function(t, b, c, d, s) { - if (s === void 0) { - s = 1.70158; - } - return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; - }, - easeInOutBack: function(t, b, c, d, s) { - if (s === void 0) { - s = 1.70158; - } - if ((t /= d / 2) < 1) { - return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b; - } else { - return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b; - } - }, - easeInBounce: function(t, b, c, d) { - var v; - v = penner.easeOutBounce(d - t, 0, c, d); - return c - v + b; - }, - easeOutBounce: function(t, b, c, d) { - if ((t /= d) < 1 / 2.75) { - return c * (7.5625 * t * t) + b; - } else if (t < 2 / 2.75) { - return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b; - } else if (t < 2.5 / 2.75) { - return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b; - } else { - return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b; - } - }, - easeInOutBounce: function(t, b, c, d) { - var v; - if (t < d / 2) { - v = penner.easeInBounce(t * 2, 0, c, d); - return v * .5 + b; - } else { - v = penner.easeOutBounce(t * 2 - d, 0, c, d); - return v * .5 + c * .5 + b; - } - } - }; + /** helper to add to the list a new Ease.face class; see Ease.to class below for parameters */ - umd(penner); + }, { + key: 'face', + value: function face() { + return this.add(new (Function.prototype.bind.apply(Face, [null].concat(Array.prototype.slice.call(arguments))))()); + } -}).call(this); + /** helper to add to the list a new Ease.load class; see Ease.to class below for parameters */ -},{}],3:[function(require,module,exports){ -// A library of seedable RNGs implemented in Javascript. -// -// Usage: -// -// var seedrandom = require('seedrandom'); -// var random = seedrandom(1); // or any seed. -// var x = random(); // 0 <= x < 1. Every bit is random. -// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness. + }, { + key: 'load', + value: function load() { + return this.add(new (Function.prototype.bind.apply(Load, [null].concat(Array.prototype.slice.call(arguments))))()); + } -// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe. -// Period: ~2^116 -// Reported to pass all BigCrush tests. -var alea = require('./lib/alea'); + /** helper to add to the list a new Ease.movie class; see Ease.to class below for parameters */ -// xor128, a pure xor-shift generator by George Marsaglia. -// Period: 2^128-1. -// Reported to fail: MatrixRank and LinearComp. -var xor128 = require('./lib/xor128'); + }, { + key: 'movie', + value: function movie() { + return this.add(new (Function.prototype.bind.apply(Movie, [null].concat(Array.prototype.slice.call(arguments))))()); + } -// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl. -// Period: 2^192-2^32 -// Reported to fail: CollisionOver, SimpPoker, and LinearComp. -var xorwow = require('./lib/xorwow'); + /** helper to add to the list a new Ease.shake class; see Ease.to class below for parameters */ -// xorshift7, by François Panneton and Pierre L'ecuyer, takes -// a different approach: it adds robustness by allowing more shifts -// than Marsaglia's original three. It is a 7-shift generator -// with 256 bits, that passes BigCrush with no systmatic failures. -// Period 2^256-1. -// No systematic BigCrush failures reported. -var xorshift7 = require('./lib/xorshift7'); + }, { + key: 'shake', + value: function shake() { + return this.add(new (Function.prototype.bind.apply(Shake, [null].concat(Array.prototype.slice.call(arguments))))()); + } -// xor4096, by Richard Brent, is a 4096-bit xor-shift with a -// very long period that also adds a Weyl generator. It also passes -// BigCrush with no systematic failures. Its long period may -// be useful if you have many generators and need to avoid -// collisions. -// Period: 2^4128-2^32. -// No systematic BigCrush failures reported. -var xor4096 = require('./lib/xor4096'); + /** helper to add to the list a new Ease.target class; see Ease.to class below for parameters */ -// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random -// number generator derived from ChaCha, a modern stream cipher. -// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf -// Period: ~2^127 -// No systematic BigCrush failures reported. -var tychei = require('./lib/tychei'); + }, { + key: 'target', + value: function target() { + return this.add(new (Function.prototype.bind.apply(Target, [null].concat(Array.prototype.slice.call(arguments))))()); + } -// The original ARC4-based prng included in this library. -// Period: ~2^1600 -var sr = require('./seedrandom'); + /** helper to add to the list a new Ease.angle tint; see Ease.to class below for parameters */ -sr.alea = alea; -sr.xor128 = xor128; -sr.xorwow = xorwow; -sr.xorshift7 = xorshift7; -sr.xor4096 = xor4096; -sr.tychei = tychei; + }, { + key: 'tint', + value: function tint() { + return this.add(new (Function.prototype.bind.apply(Tint, [null].concat(Array.prototype.slice.call(arguments))))()); + } -module.exports = sr; + /** helper to add to the list a new Ease.wait class; see Ease.to class below for parameters */ -},{"./lib/alea":4,"./lib/tychei":5,"./lib/xor128":6,"./lib/xor4096":7,"./lib/xorshift7":8,"./lib/xorwow":9,"./seedrandom":10}],4:[function(require,module,exports){ -// A port of an algorithm by Johannes Baagøe , 2010 -// http://baagoe.com/en/RandomMusings/javascript/ -// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror -// Original work is under MIT license - + }, { + key: 'wait', + value: function wait() { + return this.add(new (Function.prototype.bind.apply(Wait, [null].concat(Array.prototype.slice.call(arguments))))()); + } + }, { + key: 'count', + get: function get() { + return this.list.length; + } -// Copyright (C) 2010 by Johannes Baagøe -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. + /** + * number of active animations + * @type {number} + */ + }, { + key: 'countRunning', + get: function get() { + var count = 0; + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + try { + for (var _iterator3 = this.list[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var entry = _step3.value; -(function(global, module, define) { - -function Alea(seed) { - var me = this, mash = Mash(); + if (!entry.pause) { + count++; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } - me.next = function() { - var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32 - me.s0 = me.s1; - me.s1 = me.s2; - return me.s2 = t - (me.c = t | 0); - }; + return count; + } + }]); - // Apply the seeding algorithm from Baagoe. - me.c = 1; - me.s0 = mash(' '); - me.s1 = mash(' '); - me.s2 = mash(' '); - me.s0 -= mash(seed); - if (me.s0 < 0) { me.s0 += 1; } - me.s1 -= mash(seed); - if (me.s1 < 0) { me.s1 += 1; } - me.s2 -= mash(seed); - if (me.s2 < 0) { me.s2 += 1; } - mash = null; -} + return Ease; +}(Events); -function copy(f, t) { - t.c = f.c; - t.s0 = f.s0; - t.s1 = f.s1; - t.s2 = f.s2; - return t; -} +module.exports = Ease; -function impl(seed, opts) { - var xg = new Alea(seed), - state = opts && opts.state, - prng = xg.next; - prng.int32 = function() { return (xg.next() * 0x100000000) | 0; } - prng.double = function() { - return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 - }; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} +},{"./angle":1,"./face":2,"./load":5,"./movie":6,"./shake":7,"./target":8,"./tint":9,"./to":10,"./wait":11,"eventemitter3":12}],5:[function(require,module,exports){ +'use strict'; -function Mash() { - var n = 0xefc8249d; +var wait = require('./wait'); +var to = require('./to'); +var tint = require('./tint'); +var shake = require('./shake'); +var angle = require('./angle'); +var face = require('./face'); +var target = require('./target'); +var movie = require('./movie'); - var mash = function(data) { - data = data.toString(); - for (var i = 0; i < data.length; i++) { - n += data.charCodeAt(i); - var h = 0.02519603282416938 * n; - n = h >>> 0; - h -= n; - h *= n; - n = h >>> 0; - h -= n; - n += h * 0x100000000; // 2^32 +/** + * restart an animation = requires a saved state + * @param {object} object(s) to animate + */ +function load(object, load) { + if (!load) { + return null; + } + var options = { load: load }; + switch (load.type) { + case 'Wait': + return new wait(object, options); + case 'To': + return new to(object, null, null, options); + case 'Tint': + return new tint(object, null, null, options); + case 'Shake': + return new shake(object, null, null, options); + case 'Angle': + return new angle(object, null, null, null, options); + case 'Face': + return new face(object[0], object[1], null, options); + case 'Target': + return new target(object[0], object[1], null, options); + case 'Movie': + return new movie(object, object[1], null, options); } - return (n >>> 0) * 2.3283064365386963e-10; // 2^-32 - }; - - return mash; } +module.exports = load; -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.alea = impl; -} +},{"./angle":1,"./face":2,"./movie":6,"./shake":7,"./target":8,"./tint":9,"./to":10,"./wait":11}],6:[function(require,module,exports){ +'use strict'; -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); +var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -},{}],5:[function(require,module,exports){ -// A Javascript implementaion of the "Tyche-i" prng algorithm by -// Samuel Neves and Filipe Araujo. -// See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } -(function(global, module, define) { +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -function XorGen(seed) { - var me = this, strseed = ''; +var wait = require('./wait'); - // Set up generator function. - me.next = function() { - var b = me.b, c = me.c, d = me.d, a = me.a; - b = (b << 25) ^ (b >>> 7) ^ c; - c = (c - d) | 0; - d = (d << 24) ^ (d >>> 8) ^ a; - a = (a - b) | 0; - me.b = b = (b << 20) ^ (b >>> 12) ^ c; - me.c = c = (c - d) | 0; - me.d = (d << 16) ^ (c >>> 16) ^ a; - return me.a = (a - b) | 0; - }; +/** + * animate a movie of textures + */ - /* The following is non-inverted tyche, which has better internal - * bit diffusion, but which is about 25% slower than tyche-i in JS. - me.next = function() { - var a = me.a, b = me.b, c = me.c, d = me.d; - a = (me.a + me.b | 0) >>> 0; - d = me.d ^ a; d = d << 16 ^ d >>> 16; - c = me.c + d | 0; - b = me.b ^ c; b = b << 12 ^ d >>> 20; - me.a = a = a + b | 0; - d = d ^ a; me.d = d = d << 8 ^ d >>> 24; - me.c = c = c + d | 0; - b = b ^ c; - return me.b = (b << 7 ^ b >>> 25); - } - */ +var movie = function (_wait) { + _inherits(movie, _wait); - me.a = 0; - me.b = 0; - me.c = 2654435769 | 0; - me.d = 1367130551; + /** + * @param {object} object to animate + * @param {PIXI.Texture[]} textures + * @param {number} [duration=0] time to run (use 0 for infinite duration--should only be used with customized easing functions) + * @param {object} [options] + * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) + * @param {boolean} [options.pause] start the animation paused + * @param {(boolean|number)} [options.repeat] true: repeat animation forever n: repeat animation n times + * @param {(boolean|number)} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times + * @param {(boolean|number)} [options.continue] true: continue animation with new starting values n: continue animation n times + * @param {Function} [options.load] loads an animation using a .save() object note the * parameters below cannot be loaded and must be re-set + * @param {Function} [options.ease] function from easing.js (see http://easings.net for examples) + * @emits {done} animation expires + * @emits {wait} each update during a wait + * @emits {first} first update when animation starts + * @emits {each} each update while animation is running + * @emits {loop} when animation is repeated + * @emits {reverse} when animation is reversed + */ + function movie(object, textures, duration, options) { + _classCallCheck(this, movie); - if (seed === Math.floor(seed)) { - // Integer seed. - me.a = (seed / 0x100000000) | 0; - me.b = seed | 0; - } else { - // String seed. - strseed += seed; - } + options = options || {}; - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 20; k++) { - me.b ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} + var _this = _possibleConstructorReturn(this, (movie.__proto__ || Object.getPrototypeOf(movie)).call(this, object, options)); -function copy(f, t) { - t.a = f.a; - t.b = f.b; - t.c = f.c; - t.d = f.d; - return t; -}; + _this.type = 'Movie'; + if (Array.isArray(object)) { + _this.list = object; + _this.object = _this.list[0]; + } + if (options.load) { + _this.load(options.load); + } else { + _this.textures = textures; + _this.duration = duration; + _this.current = 0; + _this.length = textures.length; + _this.interval = duration / _this.length; + _this.isReverse = false; + _this.restart(); + } + return _this; + } -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} + _createClass(movie, [{ + key: 'save', + value: function save() { + var save = _get(movie.prototype.__proto__ || Object.getPrototypeOf(movie.prototype), 'save', this).call(this); + save.goto = this.goto; + save.current = this.current; + save.length = this.length; + save.interval = this.interval; + return save; + } + }, { + key: 'load', + value: function load(_load) { + _get(movie.prototype.__proto__ || Object.getPrototypeOf(movie.prototype), 'load', this).call(this, _load); + this.goto = _load.goto; + this.current = _load.current; + this.interval = _load.current; + } + }, { + key: 'restart', + value: function restart() { + this.current = 0; + this.time = 0; + this.isReverse = false; + } + }, { + key: 'reverse', + value: function reverse() { + this.isReverse = !this.isReverse; + } + }, { + key: 'calculate', + value: function calculate() { + var index = Math.round(this.options.ease(this.time, 0, this.length - 1, this.duration)); + if (this.isReverse) { + index = this.length - 1 - index; + } + if (this.list) { + for (var i = 0; i < this.list.length; i++) { + this.list[i].texture = this.textures[index]; + } + } else { + this.object.texture = this.textures[index]; + } + } + }]); -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.tychei = impl; -} + return movie; +}(wait); -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); +module.exports = movie; +},{"./wait":11}],7:[function(require,module,exports){ +'use strict'; +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); -},{}],6:[function(require,module,exports){ -// A Javascript implementaion of the "xor128" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper +var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; -(function(global, module, define) { +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -function XorGen(seed) { - var me = this, strseed = ''; +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - // Set up generator function. - me.next = function() { - var t = me.x ^ (me.x << 11); - me.x = me.y; - me.y = me.z; - me.z = me.w; - return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8); - }; +var wait = require('./wait'); - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} +/** + * shakes an object or list of objects + */ -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - return t; -} +var shake = function (_wait) { + _inherits(shake, _wait); -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} + /** + * @param {object|array} object or list of objects to shake + * @param {number} amount to shake + * @param {number} duration (in milliseconds) to shake + * @param {object} options (see Animate.wait) + */ + function shake(object, amount, duration, options) { + _classCallCheck(this, shake); -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor128 = impl; -} + options = options || {}; -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); + var _this = _possibleConstructorReturn(this, (shake.__proto__ || Object.getPrototypeOf(shake)).call(this, object, options)); + _this.type = 'Shake'; + if (Array.isArray(object)) { + _this.array = true; + _this.list = object; + } + if (options.load) { + _this.load(options.load); + } else { + if (_this.list) { + _this.start = []; + for (var i = 0; i < object.length; i++) { + var target = object[i]; + _this.start[i] = { x: target.x, y: target.y }; + } + } else { + _this.start = { x: object.x, y: object.y }; + } + _this.amount = amount; + _this.duration = duration; + } + return _this; + } + _createClass(shake, [{ + key: 'save', + value: function save() { + var save = _get(shake.prototype.__proto__ || Object.getPrototypeOf(shake.prototype), 'save', this).call(this); + save.start = this.start; + save.amount = this.amount; + return save; + } + }, { + key: 'load', + value: function load(_load) { + _get(shake.prototype.__proto__ || Object.getPrototypeOf(shake.prototype), 'load', this).call(this, _load); + this.start = _load.start; + this.amount = _load.amount; + } + }, { + key: 'calculate', + value: function calculate() /*elapsed*/{ + var object = this.object; + var start = this.start; + var amount = this.amount; + if (this.array) { + var list = this.list; + for (var i = 0; i < list.length; i++) { + var _object = list[i]; + var actual = start[i]; + _object.x = actual.x + Math.floor(Math.random() * amount * 2) - amount; + _object.y = actual.y + Math.floor(Math.random() * amount * 2) - amount; + } + } + object.x = start.x + Math.floor(Math.random() * amount * 2) - amount; + object.y = start.y + Math.floor(Math.random() * amount * 2) - amount; + } + }, { + key: 'done', + value: function done() { + var object = this.object; + var start = this.start; + if (this.array) { + var list = this.list; + for (var i = 0; i < list.length; i++) { + var _object2 = list[i]; + var actual = start[i]; + _object2.x = actual.x; + _object2.y = actual.y; + } + } else { + object.x = start.x; + object.y = start.y; + } + } + }]); -},{}],7:[function(require,module,exports){ -// A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm. -// -// This fast non-cryptographic random number generator is designed for -// use in Monte-Carlo algorithms. It combines a long-period xorshift -// generator with a Weyl generator, and it passes all common batteries -// of stasticial tests for randomness while consuming only a few nanoseconds -// for each prng generated. For background on the generator, see Brent's -// paper: "Some long-period random number generators using shifts and xors." -// http://arxiv.org/pdf/1004.3115v1.pdf -// -// Usage: -// -// var xor4096 = require('xor4096'); -// random = xor4096(1); // Seed with int32 or string. -// assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits. -// assert.equal(random.int32(), 1806534897); // signed int32, 32 bits. -// -// For nonzero numeric keys, this impelementation provides a sequence -// identical to that by Brent's xorgens 3 implementaion in C. This -// implementation also provides for initalizing the generator with -// string seeds, or for saving and restoring the state of the generator. -// -// On Chrome, this prng benchmarks about 2.1 times slower than -// Javascript's built-in Math.random(). + return shake; +}(wait); -(function(global, module, define) { +module.exports = shake; -function XorGen(seed) { - var me = this; +},{"./wait":11}],8:[function(require,module,exports){ +'use strict'; - // Set up generator function. - me.next = function() { - var w = me.w, - X = me.X, i = me.i, t, v; - // Update Weyl generator. - me.w = w = (w + 0x61c88647) | 0; - // Update xor generator. - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - // Update Xor generator array state. - v = X[i] = v ^ t; - me.i = i; - // Result is the combination. - return (v + (w ^ (w >>> 16))) | 0; - }; +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - function init(me, seed) { - var t, v, i, j, w, X = [], limit = 128; - if (seed === (seed | 0)) { - // Numeric seeds initialize v, which is used to generates X. - v = seed; - seed = null; - } else { - // String seeds are mixed into v and X one character at a time. - seed = seed + '\0'; - v = 0; - limit = Math.max(limit, seed.length); - } - // Initialize circular array and weyl value. - for (i = 0, j = -32; j < limit; ++j) { - // Put the unicode characters into the array, and shuffle them. - if (seed) v ^= seed.charCodeAt((j + 32) % seed.length); - // After 32 shuffles, take v as the starting w value. - if (j === 0) w = v; - v ^= v << 10; - v ^= v >>> 15; - v ^= v << 4; - v ^= v >>> 13; - if (j >= 0) { - w = (w + 0x61c88647) | 0; // Weyl. - t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array. - i = (0 == t) ? i + 1 : 0; // Count zeroes. - } - } - // We have detected all zeroes; make the key nonzero. - if (i >= 128) { - X[(seed && seed.length || 0) & 127] = -1; - } - // Run the generator 512 times to further mix the state before using it. - // Factoring this as a function slows the main generator, so it is just - // unrolled here. The weyl generator is not advanced while warming up. - i = 127; - for (j = 4 * 128; j > 0; --j) { - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - X[i] = v ^ t; - } - // Storing state as object members is faster than using closure variables. - me.w = w; - me.X = X; - me.i = i; - } +var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - init(me, seed); -} +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -function copy(f, t) { - t.i = f.i; - t.w = f.w; - t.X = f.X.slice(); - return t; -}; +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.X) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor4096 = impl; -} +var wait = require('./wait'); -})( - this, // window object or global - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); +/** move an object to a target's location */ -},{}],8:[function(require,module,exports){ -// A Javascript implementaion of the "xorshift7" algorithm by -// François Panneton and Pierre L'ecuyer: -// "On the Xorgshift Random Number Generators" -// http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf +var target = function (_wait) { + _inherits(target, _wait); -(function(global, module, define) { + /** + * move to a target + * @param {object} object - object to animate + * @param {object} target - object needs to contain {x: x, y: y} + * @param {number} speed - number of pixels to move per millisecond + * @param {object} [options] @see {@link Wait} + * @param {boolean} [options.keepAlive] don't cancel the animation when target is reached + */ + function target(object, _target, speed, options) { + _classCallCheck(this, target); -function XorGen(seed) { - var me = this; + options = options || {}; - // Set up generator function. - me.next = function() { - // Update xor generator. - var X = me.x, i = me.i, t, v, w; - t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24); - t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10); - t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3); - t = X[(i + 4) & 7]; v ^= t ^ (t << 7); - t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9); - X[i] = v; - me.i = (i + 1) & 7; - return v; - }; + var _this = _possibleConstructorReturn(this, (target.__proto__ || Object.getPrototypeOf(target)).call(this, object, options)); - function init(me, seed) { - var j, w, X = []; + _this.type = 'Target'; + _this.target = _target; + if (options.load) { + _this.load(options.load); + } else { + _this.speed = speed; + } + return _this; + } - if (seed === (seed | 0)) { - // Seed state array using a 32-bit integer. - w = X[0] = seed; - } else { - // Seed state using a string. - seed = '' + seed; - for (j = 0; j < seed.length; ++j) { - X[j & 7] = (X[j & 7] << 15) ^ - (seed.charCodeAt(j) + X[(j + 1) & 7] << 13); - } - } - // Enforce an array length of 8, not all zeroes. - while (X.length < 8) X.push(0); - for (j = 0; j < 8 && X[j] === 0; ++j); - if (j == 8) w = X[7] = -1; else w = X[j]; + _createClass(target, [{ + key: 'save', + value: function save() { + var save = _get(target.prototype.__proto__ || Object.getPrototypeOf(target.prototype), 'save', this).call(this); + save.speed = this.speed; + save.keepAlive = this.options.keepAlive; + return save; + } + }, { + key: 'load', + value: function load(_load) { + _get(target.prototype.__proto__ || Object.getPrototypeOf(target.prototype), 'load', this).call(this, _load); + this.speed = _load.speed; + this.options.keepAlive = _load.keepAlive; + } + }, { + key: 'calculate', + value: function calculate(elapsed) { + var deltaX = this.target.x - this.object.x; + var deltaY = this.target.y - this.object.y; + if (deltaX === 0 && deltaY === 0) { + this.emit('done', this.object); + if (!this.options.keepAlive) { + return true; + } + } else { + var angle = Math.atan2(deltaY, deltaX); + this.object.x += Math.cos(angle) * elapsed * this.speed; + this.object.y += Math.sin(angle) * elapsed * this.speed; + if (deltaX >= 0 !== this.target.x - this.object.x >= 0) { + this.object.x = this.target.x; + } + if (deltaY >= 0 !== this.target.y - this.object.y >= 0) { + this.object.y = this.target.y; + } + } + } + }]); - me.x = X; - me.i = 0; + return target; +}(wait); - // Discard an initial 256 values. - for (j = 256; j > 0; --j) { - me.next(); - } - } +module.exports = target; - init(me, seed); -} +},{"./wait":11}],9:[function(require,module,exports){ +'use strict'; -function copy(f, t) { - t.x = f.x.slice(); - t.i = f.i; - return t; -} +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.x) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} +var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorshift7 = impl; -} +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } -},{}],9:[function(require,module,exports){ -// A Javascript implementaion of the "xorwow" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -(function(global, module, define) { +var Color = require('yy-color'); +var wait = require('./wait'); -function XorGen(seed) { - var me = this, strseed = ''; +var tint = function (_wait) { + _inherits(tint, _wait); - // Set up generator function. - me.next = function() { - var t = (me.x ^ (me.x >>> 2)); - me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v; - return (me.d = (me.d + 362437 | 0)) + - (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0; - }; + /** + * @param {PIXI.DisplayObject|PIXI.DisplayObject[]} object + * @param {number|number[]} tint + * @param {number} [duration] in milliseconds + * @param {object} [options] @see {@link Wait} + */ + function tint(object, _tint, duration, options) { + _classCallCheck(this, tint); - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - me.v = 0; + options = options || {}; - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } + var _this = _possibleConstructorReturn(this, (tint.__proto__ || Object.getPrototypeOf(tint)).call(this, object, options)); - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - if (k == strseed.length) { - me.d = me.x << 10 ^ me.x >>> 4; + _this.type = 'Tint'; + if (Array.isArray(object)) { + _this.list = object; + _this.object = _this.list[0]; + } + _this.duration = duration; + if (options.load) { + _this.load(options.load); + } else if (Array.isArray(_tint)) { + _this.tints = [_this.object.tint].concat(_toConsumableArray(_tint)); + } else { + _this.start = _this.object.tint; + _this.to = _tint; + } + return _this; } - me.next(); - } -} -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - t.v = f.v; - t.d = f.d; - return t; -} + _createClass(tint, [{ + key: 'save', + value: function save() { + var save = _get(tint.prototype.__proto__ || Object.getPrototypeOf(tint.prototype), 'save', this).call(this); + save.start = this.start; + save.to = this.to; + return save; + } + }, { + key: 'load', + value: function load(_load) { + _get(tint.prototype.__proto__ || Object.getPrototypeOf(tint.prototype), 'load', this).call(this, _load); + this.start = _load.start; + this.to = _load.to; + } + }, { + key: 'calculate', + value: function calculate() { + var percent = this.options.ease(this.time, 0, 1, this.duration); + if (this.tints) { + var each = 1 / (this.tints.length - 1); + var per = each; + for (var i = 1; i < this.tints.length; i++) { + if (percent <= per) { + var color = Color.blend(1 - (per - percent) / each, this.tints[i - 1], this.tints[i]); + if (this.list) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var object = _step.value; + + object.tint = color; + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } else { + this.object.tint = color; + } + break; + } + per += each; + } + } else { + var _color = Color.blend(percent, this.start, this.to); + if (this.list) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} + try { + for (var _iterator2 = this.list[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var _object = _step2.value; -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorwow = impl; -} + _object.tint = _color; + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } else { + this.object.tint = _color; + } + } + } + }, { + key: 'reverse', + value: function reverse() { + if (this.tints) { + var tints = []; + for (var i = this.tints.length - 1; i >= 0; i--) { + tints.push(this.tints[i]); + } + this.tints = tints; + } else { + var swap = this.to; + this.to = this.start; + this.start = swap; + } + } + }]); -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); + return tint; +}(wait); +module.exports = tint; +},{"./wait":11,"yy-color":23}],10:[function(require,module,exports){ +'use strict'; -},{}],10:[function(require,module,exports){ -/* -Copyright 2014 David Bau. +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: +var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } -*/ +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -(function (pool, math) { -// -// The following constants are related to IEEE 754 limits. -// -var global = this, - width = 256, // each RC4 output is 0 <= x < 256 - chunks = 6, // at least six RC4 outputs for each double - digits = 52, // there are 52 significant digits in a double - rngname = 'random', // rngname: name for Math.random and Math.seedrandom - startdenom = math.pow(width, chunks), - significance = math.pow(2, digits), - overflow = significance * 2, - mask = width - 1, - nodecrypto; // node.js crypto module, initialized at the bottom. +var wait = require('./wait'); -// -// seedrandom() -// This is the seedrandom function described above. -// -function seedrandom(seed, options, callback) { - var key = []; - options = (options == true) ? { entropy: true } : (options || {}); +/** animate any numeric parameter of an object or array of objects */ - // Flatten the seed string or build one from local entropy if needed. - var shortseed = mixkey(flatten( - options.entropy ? [seed, tostring(pool)] : - (seed == null) ? autoseed() : seed, 3), key); +var to = function (_wait) { + _inherits(to, _wait); - // Use the seed to initialize an ARC4 generator. - var arc4 = new ARC4(key); + /** + * @private + * @param {object} object to animate + * @param {object} goto - parameters to animate, e.g.: {alpha: 5, scale: {3, 5}, scale: 5, rotation: Math.PI} + * @param {number} duration - time to run + * @param {object} [options] + * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) + * @param {boolean} [options.pause] start the animation paused + * @param {boolean|number} [options.repeat] true: repeat animation forever n: repeat animation n times + * @param {boolean|number} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times + * @param {Function} [options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set + * @param {string|Function} [options.ease] name or function from easing.js (see http://easings.net for examples) + * @emits to:done animation expires + * @emits to:wait each update during a wait + * @emits to:first first update when animation starts + * @emits to:each each update while animation is running + * @emits to:loop when animation is repeated + * @emits to:reverse when animation is reversed + */ + function to(object, goto, duration, options) { + _classCallCheck(this, to); - // This function returns a random double in [0, 1) that contains - // randomness in every bit of the mantissa of the IEEE 754 value. - var prng = function() { - var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48 - d = startdenom, // and denominator d = 2 ^ 48. - x = 0; // and no 'extra last byte'. - while (n < significance) { // Fill up all significant digits by - n = (n + x) * width; // shifting numerator and - d *= width; // denominator and generating a - x = arc4.g(1); // new least-significant-byte. - } - while (n >= overflow) { // To avoid rounding up, before adding - n /= 2; // last byte, shift everything - d /= 2; // right using integer math until - x >>>= 1; // we have exactly the desired bits. - } - return (n + x) / d; // Form the number within [0, 1). - }; - - prng.int32 = function() { return arc4.g(4) | 0; } - prng.quick = function() { return arc4.g(4) / 0x100000000; } - prng.double = prng; + options = options || {}; - // Mix the randomness into accumulated entropy. - mixkey(tostring(arc4.S), pool); + var _this = _possibleConstructorReturn(this, (to.__proto__ || Object.getPrototypeOf(to)).call(this, object, options)); - // Calling convention: what to return as a function of prng, seed, is_math. - return (options.pass || callback || - function(prng, seed, is_math_call, state) { - if (state) { - // Load the arc4 state from the given state if it has an S array. - if (state.S) { copy(state, arc4); } - // Only provide the .state method if requested via options.state. - prng.state = function() { return copy(arc4, {}); } + _this.type = 'To'; + if (Array.isArray(object)) { + _this.list = object; + _this.object = _this.list[0]; } + if (options.load) { + _this.load(options.load); + } else { + _this.goto = goto; + _this.fixScale(); + _this.duration = duration; + _this.restart(); + } + return _this; + } - // If called as a method of Math (Math.seedrandom()), mutate - // Math.random because that is how seedrandom.js has worked since v1.0. - if (is_math_call) { math[rngname] = prng; return seed; } - - // Otherwise, it is a newer calling convention, so return the - // prng directly. - else return prng; - })( - prng, - shortseed, - 'global' in options ? options.global : (this == math), - options.state); -} -math['seed' + rngname] = seedrandom; + /** + * converts scale from { scale: n } to { scale: { x: n, y: n }} + * @private + */ -// -// ARC4 -// -// An ARC4 implementation. The constructor takes a key in the form of -// an array of at most (width) integers that should be 0 <= x < (width). -// -// The g(count) method returns a pseudorandom integer that concatenates -// the next (count) outputs from ARC4. Its return value is a number x -// that is in the range 0 <= x < (width ^ count). -// -function ARC4(key) { - var t, keylen = key.length, - me = this, i = 0, j = me.i = me.j = 0, s = me.S = []; - // The empty key [] is treated as [0]. - if (!keylen) { key = [keylen++]; } + _createClass(to, [{ + key: 'fixScale', + value: function fixScale() { + if (typeof this.goto['scale'] !== 'undefined' && !Number.isNaN(this.goto['scale'])) { + this.goto['scale'] = { x: this.goto['scale'], y: this.goto['scale'] }; + } + } + }, { + key: 'save', + value: function save() { + var save = _get(to.prototype.__proto__ || Object.getPrototypeOf(to.prototype), 'save', this).call(this); + save.goto = this.goto; + save.start = this.start; + save.delta = this.delta; + save.keys = this.keys; + return save; + } + }, { + key: 'load', + value: function load(_load) { + _get(to.prototype.__proto__ || Object.getPrototypeOf(to.prototype), 'load', this).call(this, _load); + this.goto = _load.goto; + this.start = _load.start; + this.delta = _load.delta; + this.keys = _load.keys; + } + }, { + key: 'restart', + value: function restart() { + var i = 0; + var start = this.start = []; + var delta = this.delta = []; + var keys = this.keys = []; + var goto = this.goto; + var object = this.object; + + // loops through all keys in goto object + for (var key in goto) { + + // handles keys with one additional level e.g.: goto = {scale: {x: 5, y: 3}} + if (isNaN(goto[key])) { + keys[i] = { key: key, children: [] }; + start[i] = []; + delta[i] = []; + var j = 0; + for (var key2 in goto[key]) { + keys[i].children[j] = key2; + start[i][j] = parseFloat(object[key][key2]); + start[i][j] = this._correctDOM(key2, start[i][j]); + start[i][j] = isNaN(this.start[i][j]) ? 0 : start[i][j]; + delta[i][j] = goto[key][key2] - start[i][j]; + j++; + } + } else { + start[i] = parseFloat(object[key]); + start[i] = this._correctDOM(key, start[i]); + start[i] = isNaN(this.start[i]) ? 0 : start[i]; + delta[i] = goto[key] - start[i]; + keys[i] = key; + } + i++; + } + this.time = 0; + } + }, { + key: 'reverse', + value: function reverse() { + var object = this.object; + var keys = this.keys; + var goto = this.goto; + var delta = this.delta; + var start = this.start; + + for (var i = 0, _i = keys.length; i < _i; i++) { + var key = keys[i]; + if (isNaN(goto[key])) { + for (var j = 0, _j = key.children.length; j < _j; j++) { + delta[i][j] = -delta[i][j]; + start[i][j] = parseFloat(object[key.key][key.children[j]]); + start[i][j] = isNaN(start[i][j]) ? 0 : start[i][j]; + } + } else { + delta[i] = -delta[i]; + start[i] = parseFloat(object[key]); + start[i] = isNaN(start[i]) ? 0 : start[i]; + } + } + } + }, { + key: 'calculate', + value: function calculate() /*elapsed*/{ + var object = this.object; + var list = this.list; + var keys = this.keys; + var goto = this.goto; + var time = this.time; + var start = this.start; + var delta = this.delta; + var duration = this.duration; + var ease = this.options.ease; + for (var i = 0, _i = this.keys.length; i < _i; i++) { + var key = keys[i]; + if (isNaN(goto[key])) { + var key1 = key.key; + for (var j = 0, _j = key.children.length; j < _j; j++) { + var key2 = key.children[j]; + var others = object[key1][key2] = time >= duration ? start[i][j] + delta[i][j] : ease(time, start[i][j], delta[i][j], duration); + if (list) { + for (var k = 1, _k = list.length; k < _k; k++) { + list[k][key1][key2] = others; + } + } + } + } else { + var _key = keys[i]; + var _others = object[_key] = time >= duration ? start[i] + delta[i] : ease(time, start[i], delta[i], duration); + if (list) { + for (var _j2 = 1, _j3 = this.list.length; _j2 < _j3; _j2++) { + list[_j2][_key] = _others; + } + } + } + } + } + }]); - // Set up S using the standard key scheduling algorithm. - while (i < width) { - s[i] = i++; - } - for (i = 0; i < width; i++) { - s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))]; - s[j] = t; - } + return to; +}(wait); - // The "g" method returns the next (count) outputs as one number. - (me.g = function(count) { - // Using instance members instead of closure state nearly doubles speed. - var t, r = 0, - i = me.i, j = me.j, s = me.S; - while (count--) { - t = s[i = mask & (i + 1)]; - r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))]; - } - me.i = i; me.j = j; - return r; - // For robust unpredictability, the function call below automatically - // discards an initial batch of values. This is called RC4-drop[256]. - // See http://google.com/search?q=rsa+fluhrer+response&btnI - })(width); -} +module.exports = to; -// -// copy() -// Copies internal state of ARC4 to or from a plain object. -// -function copy(f, t) { - t.i = f.i; - t.j = f.j; - t.S = f.S.slice(); - return t; -}; +},{"./wait":11}],11:[function(require,module,exports){ +'use strict'; -// -// flatten() -// Converts an object tree to nested arrays of strings. -// -function flatten(obj, depth) { - var result = [], typ = (typeof obj), prop; - if (depth && typ == 'object') { - for (prop in obj) { - try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} - } - } - return (result.length ? result : typ == 'string' ? obj : obj + '\0'); -} +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); -// -// mixkey() -// Mixes a string seed into a key that is an array of integers, and -// returns a shortened string seed that is equivalent to the result key. -// -function mixkey(seed, key) { - var stringseed = seed + '', smear, j = 0; - while (j < stringseed.length) { - key[mask & j] = - mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++)); - } - return tostring(key); -} +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -// -// autoseed() -// Returns an object for autoseeding, using window.crypto and Node crypto -// module if available. -// -function autoseed() { - try { - var out; - if (nodecrypto && (out = nodecrypto.randomBytes)) { - // The use of 'out' to remember randomBytes makes tight minified code. - out = out(width); - } else { - out = new Uint8Array(width); - (global.crypto || global.msCrypto).getRandomValues(out); - } - return tostring(out); - } catch (e) { - var browser = global.navigator, - plugins = browser && browser.plugins; - return [+new Date, global, plugins, global.screen, tostring(pool)]; - } -} +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } -// -// tostring() -// Converts an array of charcodes to a string -// -function tostring(a) { - return String.fromCharCode.apply(0, a); -} +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -// -// When seedrandom.js is loaded, we immediately mix a few bits -// from the built-in RNG into the entropy pool. Because we do -// not want to interfere with deterministic PRNG state later, -// seedrandom will not call math.random on its own again after -// initialization. -// -mixkey(math.random(), pool); +var Easing = require('penner'); +var EventEmitter = require('eventemitter3'); -// -// Nodejs and AMD support: export the implementation as a module using -// either convention. -// -if ((typeof module) == 'object' && module.exports) { - module.exports = seedrandom; - // When in node.js, try using crypto package for autoseeding. - try { - nodecrypto = require('crypto'); - } catch (ex) {} -} else if ((typeof define) == 'function' && define.amd) { - define(function() { return seedrandom; }); -} +var wait = function (_EventEmitter) { + _inherits(wait, _EventEmitter); -// End anonymous scope, and pass initial values. -})( - [], // pool: entropy pool starts empty - Math // math: package containing random, pow, and seedrandom -); + /** + * @param {object|object[]} object or list of objects to animate + * @param {object} [options] + * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) + * @param {boolean} [options.pause] start the animation paused + * @param {(boolean|number)} [options.repeat] true: repeat animation forever n: repeat animation n times + * @param {(boolean|number)} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times + * + * @param {number} [options.id] user-generated id (e.g., I use it to properly load animations when an object has multiple animations running) + * @param {Function} [options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set + * @param {Function|string} [options.ease] function (or penner function name) from easing.js (see http://easings.net for examples)* + * + * @emits {done} animation expires + * @emits {wait} each update during a wait + * @emits {first} first update when animation starts + * @emits {each} each update while animation is running + * @emits {loop} when animation is repeated + * @emits {reverse} when animation is reversed + */ + function wait(object, options) { + _classCallCheck(this, wait); -},{"crypto":25}],11:[function(require,module,exports){ -// angle.js -// Released under MIT license -// Author: David Figatner -// Copyright (c) 2016-17 YOPEY YOPEY LLC + var _this = _possibleConstructorReturn(this, (wait.__proto__ || Object.getPrototypeOf(wait)).call(this)); -var _toDegreeConversion = 180 / Math.PI -var _toRadianConversion = Math.PI / 180 + _this.object = object; + _this.options = options || {}; + _this.type = 'Wait'; + if (_this.options.load) { + _this.load(_this.options.load); + } else { + _this.time = 0; + } + if (_this.options.ease && typeof _this.options.ease !== 'function') { + _this.options.easeName = _this.options.ease; + _this.options.ease = Easing[_this.options.ease]; + } + if (!_this.options.ease) { + _this.options.ease = Easing['linear']; + } + return _this; + } -/** @constant {number} */ -var UP = Math.PI / 2 -var DOWN = 3 * Math.PI / 2 -var LEFT = Math.PI -var RIGHT = 0 + _createClass(wait, [{ + key: 'save', + value: function save() { + var save = { type: this.type, time: this.time, duration: this.duration, ease: this.options.easeName }; + var options = this.options; + if (options.wait) { + save.wait = options.wait; + } + if (typeof options.id !== 'undefined') { + save.id = options.id; + } + if (options.pause) { + save.pause = options.pause; + } + if (options.repeat) { + save.repeat = options.repeat; + } + if (options.reverse) { + save.reverse = options.reverse; + } + return save; + } + }, { + key: 'load', + value: function load(_load) { + this.options.wait = _load.wait; + this.options.pause = _load.pause; + this.options.repeat = _load.repeat; + this.options.reverse = _load.reverse; + this.options.id = _load.id; + this.options.ease = _load.ease; + if (this.options.ease && typeof this.options.ease !== 'function') { + this.options.easeName = this.options.ease; + this.options.ease = Easing[this.options.ease]; + } + if (!this.options.ease) { + this.options.ease = Easing['linear']; + } + this.time = _load.time; + this.duration = _load.duration; + } -var NORTH = UP -var SOUTH = DOWN -var WEST = LEFT -var EAST = RIGHT + /** + * pause this entry + * @type {boolean} + */ -var PI_2 = Math.PI * 2 -var PI_QUARTER = Math.PI / 4 -var PI_HALF = Math.PI / 2 + }, { + key: 'end', + value: function end(leftOver) { + if (this.options.reverse) { + this.reverse(); + this.time = leftOver; + if (!this.options.repeat) { + if (this.options.reverse === true) { + this.options.reverse = false; + } else { + this.options.reverse--; + } + } else { + if (this.options.repeat !== true) { + this.options.repeat--; + } + } + this.emit('loop', this.list || this.object); + } else if (this.options.repeat) { + this.time = leftOver; + if (this.options.repeat !== true) { + this.options.repeat--; + } + this.emit('loop', this.list || this.object); + } else { + this.done(); + this.emit('done', this.list || this.object, leftOver); + // this.list = this.object = null + return true; + } + } + }, { + key: 'update', + value: function update(elapsed) { + var options = this.options; + if (options.pause) { + return; + } + if (options.wait) { + options.wait -= elapsed; + if (options.wait <= 0) { + elapsed = -options.wait; + options.wait = false; + } else { + this.emit('wait', elapsed, this.list || this.object); + return; + } + } + if (!this.first) { + this.first = true; + this.emit('first', this.list || this.object); + } + this.time += elapsed; + var leftOver = 0; + var duration = this.duration; + var time = this.time; + if (duration !== 0 && time > duration) { + leftOver = time - duration; + this.time = time = duration; + } + var force = this.calculate(elapsed); + this.emit('each', elapsed, this.list || this.object, this); + if (this.type === 'Wait' || duration !== 0 && time === duration) { + return this.end(leftOver); + } + return force || time === duration; + } + + // correct certain DOM values + + }, { + key: '_correctDOM', + value: function _correctDOM(key, value) { + switch (key) { + case 'opacity': + return isNaN(value) ? 1 : value; + } + return value; + } + }, { + key: 'reverse', + value: function reverse() {} + }, { + key: 'calculate', + value: function calculate() {} + }, { + key: 'done', + value: function done() {} + }, { + key: 'pause', + set: function set(value) { + this.options.pause = value; + }, + get: function get() { + return this.options.pause; + } + }]); + + return wait; +}(EventEmitter); + +module.exports = wait; + +},{"eventemitter3":12,"penner":13}],12:[function(require,module,exports){ +'use strict'; + +var has = Object.prototype.hasOwnProperty + , prefix = '~'; /** - * converts from radians to degrees (all other functions expect radians) - * @param {number} radians - * @return {number} degrees + * Constructor to create a storage for our `EE` objects. + * An `Events` instance is a plain object whose properties are event names. + * + * @constructor + * @private */ -function toDegrees(radians) -{ - return radians * _toDegreeConversion +function Events() {} + +// +// We try to not inherit from `Object.prototype`. In some engines creating an +// instance in this way is faster than calling `Object.create(null)` directly. +// If `Object.create(null)` is not supported we prefix the event names with a +// character to make sure that the built-in object properties are not +// overridden or used as an attack vector. +// +if (Object.create) { + Events.prototype = Object.create(null); + + // + // This hack is needed because the `__proto__` property is still inherited in + // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. + // + if (!new Events().__proto__) prefix = false; } /** - * converts from degrees to radians (all other functions expect radians) - * @param {number} degrees - * @return {number} radians + * Representation of a single event listener. + * + * @param {Function} fn The listener function. + * @param {*} context The context to invoke the listener with. + * @param {Boolean} [once=false] Specify if the listener is a one-time listener. + * @constructor + * @private */ -function toRadians(degrees) -{ - return degrees * _toRadianConversion +function EE(fn, context, once) { + this.fn = fn; + this.context = context; + this.once = once || false; } /** - * returns whether the target angle is between angle1 and angle2 (in radians) - * (based on: http://stackoverflow.com/questions/11406189/determine-if-angle-lies-between-2-other-angles) - * @param {number} target angle - * @param {number} angle1 - * @param {number} angle2 - * @return {boolean} + * Add a listener for a given event. + * + * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. + * @param {(String|Symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} context The context to invoke the listener with. + * @param {Boolean} once Specify if the listener is a one-time listener. + * @returns {EventEmitter} + * @private */ -function isAngleBetween(target, angle1, angle2) -{ - var rAngle = ((angle2 - angle1) % PI_2 + PI_2) % PI_2 - if (rAngle >= Math.PI) - { - var swap = angle1 - angle1 = angle2 - angle2 = swap - } +function addListener(emitter, event, fn, context, once) { + if (typeof fn !== 'function') { + throw new TypeError('The listener must be a function'); + } - if (angle1 <= angle2) - { - return target >= angle1 && target <= angle2 - } - else - { - return target >= angle1 || target <= angle2 - } -} + var listener = new EE(fn, context || emitter, once) + , evt = prefix ? prefix + event : event; -/** - * returns +1 or -1 based on whether the difference between two angles is positive or negative (in radians) - * @param {number} target angle - * @param {number} source angle - * @return {number} 1 or -1 - */ -function differenceAnglesSign(target, source) -{ - function mod(a, n) - { - return (a % n + n) % n - } + if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; + else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); + else emitter._events[evt] = [emitter._events[evt], listener]; - var a = target - source - return mod((a + Math.PI), PI_2) - Math.PI > 0 ? 1 : -1 + return emitter; } /** - * returns the normalized difference between two angles (in radians) - * @param {number} a - first angle - * @param {number} b - second angle - * @return {number} normalized difference between a and b + * Clear event by name. + * + * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. + * @param {(String|Symbol)} evt The Event name. + * @private */ -function differenceAngles(a, b) -{ - var c = Math.abs(a - b) % PI_2 - return c > Math.PI ? (PI_2 - c) : c +function clearEvent(emitter, evt) { + if (--emitter._eventsCount === 0) emitter._events = new Events(); + else delete emitter._events[evt]; } /** - * returns a target angle that is the shortest way to rotate an object between start and to--may choose a negative angle - * @param {number} start - * @param {number} to - * @return {number} shortest target angle + * Minimal `EventEmitter` interface that is molded against the Node.js + * `EventEmitter` interface. + * + * @constructor + * @public */ -function shortestAngle(start, to) -{ - var difference = differenceAngles(to, start) - var sign = differenceAnglesSign(to, start) - var delta = difference * sign - return delta + start +function EventEmitter() { + this._events = new Events(); + this._eventsCount = 0; } /** - * returns the normalized angle (0 - PI x 2) - * @param {number} radians - * @return {number} normalized angle in radians + * Return an array listing the events for which the emitter has registered + * listeners. + * + * @returns {Array} + * @public */ -function normalize(radians) -{ - return radians - PI_2 * Math.floor(radians / PI_2) -} +EventEmitter.prototype.eventNames = function eventNames() { + var names = [] + , events + , name; + + if (this._eventsCount === 0) return names; + + for (name in (events = this._events)) { + if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); + } + + if (Object.getOwnPropertySymbols) { + return names.concat(Object.getOwnPropertySymbols(events)); + } + + return names; +}; /** - * returns angle between two points (in radians) - * @param {Point} [point1] {x: x, y: y} - * @param {Point} [point2] {x: x, y: y} - * @param {number} [x1] - * @param {number} [y1] - * @param {number} [x2] - * @param {number} [y2] - * @return {number} angle + * Return the listeners registered for a given event. + * + * @param {(String|Symbol)} event The event name. + * @returns {Array} The registered listeners. + * @public */ -function angleTwoPoints(/* (point1, point2) OR (x1, y1, x2, y2) */) -{ - if (arguments.length === 4) - { - return Math.atan2(arguments[3] - arguments[1], arguments[2] - arguments[0]) - } - else - { - return Math.atan2(arguments[1].y - arguments[0].y, arguments[1].x - arguments[0].x) - } -} +EventEmitter.prototype.listeners = function listeners(event) { + var evt = prefix ? prefix + event : event + , handlers = this._events[evt]; + + if (!handlers) return []; + if (handlers.fn) return [handlers.fn]; + + for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { + ee[i] = handlers[i].fn; + } + + return ee; +}; /** - * returns distance between two points - * @param {Point} [point1] {x: x, y: y} - * @param {Point} [point2] {x: x, y: y} - * @param {number} [x1] - * @param {number} [y1] - * @param {number} [x2] - * @param {number} [y2] - * @return {number} distance - */ -function distanceTwoPoints(/* (point1, point2) OR (x1, y1, x2, y2) */) -{ - if (arguments.length === 2) - { - return Math.sqrt(Math.pow(arguments[1].x - arguments[0].x, 2) + Math.pow(arguments[1].y - arguments[0].y, 2)) - } - else - { - return Math.sqrt(Math.pow(arguments[2] - arguments[0], 2) + Math.pow(arguments[3] - arguments[1], 2)) - } -} - -/** - * returns the squared distance between two points - * @param {Point} [point1] {x: x, y: y} - * @param {Point} [point2] {x: x, y: y} - * @param {number} [x1] - * @param {number} [y1] - * @param {number} [x2] - * @param {number} [y2] - * @return {number} squared distance + * Return the number of listeners listening to a given event. + * + * @param {(String|Symbol)} event The event name. + * @returns {Number} The number of listeners. + * @public */ -function distanceTwoPointsSquared(/* (point1, point2) OR (x1, y1, x2, y2) */) -{ - if (arguments.length === 2) - { - return Math.pow(arguments[1].x - arguments[0].x, 2) + Math.pow(arguments[1].y - arguments[0].y, 2) - } - else - { - return Math.pow(arguments[2] - arguments[0], 2) + Math.pow(arguments[3] - arguments[1], 2) - } -} +EventEmitter.prototype.listenerCount = function listenerCount(event) { + var evt = prefix ? prefix + event : event + , listeners = this._events[evt]; -/** - * returns the closest cardinal (N, S, E, W) to the given angle (in radians) - * @param {number} angle - * @return {number} closest cardinal in radians - */ -function closestAngle(angle) -{ - var left = differenceAngles(angle, LEFT) - var right = differenceAngles(angle, RIGHT) - var up = differenceAngles(angle, UP) - var down = differenceAngles(angle, DOWN) - if (left <= right && left <= up && left <= down) - { - return LEFT - } - else if (right <= up && right <= down) - { - return RIGHT - } - else if (up <= down) - { - return UP - } - else - { - return DOWN - } -} + if (!listeners) return 0; + if (listeners.fn) return 1; + return listeners.length; +}; /** - * checks whether angles a1 and a2 are equal (after normalizing) - * @param {number} a1 - * @param {number} a2 - * @param {number} [wiggle] return true if the difference between the angles is <= wiggle - * @return {boolean} a1 === a2 + * Calls each of the listeners registered for a given event. + * + * @param {(String|Symbol)} event The event name. + * @returns {Boolean} `true` if the event had listeners, else `false`. + * @public */ -function equals(a1, a2, wiggle) -{ - if (wiggle) - { - return differenceAngles(a1, a2) < wiggle - } - else - { - return normalize(a1) === normalize(a2) +EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { + var evt = prefix ? prefix + event : event; + + if (!this._events[evt]) return false; + + var listeners = this._events[evt] + , len = arguments.length + , args + , i; + + if (listeners.fn) { + if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); + + switch (len) { + case 1: return listeners.fn.call(listeners.context), true; + case 2: return listeners.fn.call(listeners.context, a1), true; + case 3: return listeners.fn.call(listeners.context, a1, a2), true; + case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; + case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; + case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; } -} -/** - * return a text representation of the cardinal direction - * @param {number} angle - * @returns {string} UP, DOWN, LEFT, RIGHT, or NOT CARDINAL - */ -function explain(angle) -{ - switch (angle) - { - case UP: return 'UP' - case DOWN: return 'DOWN' - case LEFT: return 'LEFT' - case RIGHT: return 'RIGHT' - default: return 'NOT CARDINAL' + for (i = 1, args = new Array(len -1); i < len; i++) { + args[i - 1] = arguments[i]; } -} -module.exports = { - UP: UP, - DOWN: DOWN, - LEFT: LEFT, - RIGHT: RIGHT, - NORTH: NORTH, - SOUTH: SOUTH, - WEST: WEST, - EAST: EAST, - PI_2: PI_2, - PI_QUARTER: PI_QUARTER, - PI_HALF: PI_HALF, + listeners.fn.apply(listeners.context, args); + } else { + var length = listeners.length + , j; - toDegrees: toDegrees, - toRadians: toRadians, - isAngleBetween: isAngleBetween, - differenceAnglesSign: differenceAnglesSign, - differenceAngles: differenceAngles, - shortestAngle: shortestAngle, - normalize: normalize, - angleTwoPoints: angleTwoPoints, - distanceTwoPoints: distanceTwoPoints, - distanceTwoPointsSquared: distanceTwoPointsSquared, - closestAngle: closestAngle, - equals: equals, - explain: explain -} -},{}],12:[function(require,module,exports){ -// yy-color -// by David Figatner -// MIT License -// (c) YOPEY YOPEY LLC 2017 -// https://github.com/davidfig/color + for (i = 0; i < length; i++) { + if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); -var Random = require('yy-random') + switch (len) { + case 1: listeners[i].fn.call(listeners[i].context); break; + case 2: listeners[i].fn.call(listeners[i].context, a1); break; + case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; + case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; + default: + if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { + args[j - 1] = arguments[j]; + } -/** - * converts a #FFFFFF to 0x123456 - * @param {string} color - * @return {string} - */ -function poundToHex(color) -{ - return '0x' + parseInt(color.substr(1)).toString(16) -} + listeners[i].fn.apply(listeners[i].context, args); + } + } + } + + return true; +}; /** - * converts a 0x123456 to #FFFFFF - * @param {string} color - * @return {string} + * Add a listener for a given event. + * + * @param {(String|Symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} [context=this] The context to invoke the listener with. + * @returns {EventEmitter} `this`. + * @public */ -function hexToPound(color) -{ - return '#' + color.substr(2) -} +EventEmitter.prototype.on = function on(event, fn, context) { + return addListener(this, event, fn, context, false); +}; /** - * converts a number to #FFFFFF - * @param {number} color - * @return {string} + * Add a one-time listener for a given event. + * + * @param {(String|Symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} [context=this] The context to invoke the listener with. + * @returns {EventEmitter} `this`. + * @public */ -function valueToPound(color) -{ - return '#' + color.toString(16) -} +EventEmitter.prototype.once = function once(event, fn, context) { + return addListener(this, event, fn, context, true); +}; /** - * based on tinycolor - * https://github.com/bgrins/TinyColor - * BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE - * @param {string} color - * @returns {object} + * Remove the listeners of a given event. + * + * @param {(String|Symbol)} event The event name. + * @param {Function} fn Only remove the listeners that match this function. + * @param {*} context Only remove the listeners that have this context. + * @param {Boolean} once Only remove one-time listeners. + * @returns {EventEmitter} `this`. + * @public */ -function hexToHsl (color) -{ - var rgb = this.hexToRgb(color), - r = rgb.r, - g = rgb.g, - b = rgb.b - var max = Math.max(r, g, b), - min = Math.min(r, g, b) - var h, s, l = (max + min) / 2 +EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { + var evt = prefix ? prefix + event : event; - if (max === min) - { - h = s = 0 // achromatic - } - else - { - var d = max - min - s = l > 0.5 ? d / (2 - max - min) : d / (max + min) - switch (max) - { - case r: h = (g - b) / d + (g < b ? 6 : 0); break - case g: h = (b - r) / d + 2; break - case b: h = (r - g) / d + 4; break - } - - h /= 6 - } + if (!this._events[evt]) return this; + if (!fn) { + clearEvent(this, evt); + return this; + } - return { h: h, s: s, l: l } -} + var listeners = this._events[evt]; -/** based on tinycolor -* https://github.com/bgrins/TinyColor -* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE -* @param {object|number} color {h, s, b} or h -* @param {number} [s] -* @param {number} [l] -* @returns number -*/ -function hslToHex(color) -{ - var r, g, b, h, s, l - if (arguments.length === 1) - { - h = color.h, - s = color.s, - l = color.l + if (listeners.fn) { + if ( + listeners.fn === fn && + (!once || listeners.once) && + (!context || listeners.context === context) + ) { + clearEvent(this, evt); } - else - { - h = arguments[0] - s = arguments[1] - l = arguments[2] + } else { + for (var i = 0, events = [], length = listeners.length; i < length; i++) { + if ( + listeners[i].fn !== fn || + (once && !listeners[i].once) || + (context && listeners[i].context !== context) + ) { + events.push(listeners[i]); + } } - function hue2rgb(p, q, t) { - if (t < 0) t += 1 - if (t > 1) t -= 1 - if (t < 1/6) return p + (q - p) * 6 * t - if (t < 1/2) return q - if (t < 2/3) return p + (q - p) * (2/3 - t) * 6 - return p - } + // + // Reset the array, or remove it completely if we have no more listeners. + // + if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; + else clearEvent(this, evt); + } - if (s === 0) - { - r = g = b = l // achromatic - } - else - { - var q = l < 0.5 ? l * (1 + s) : l + s - l * s - var p = 2 * l - q - r = hue2rgb(p, q, h + 1/3) - g = hue2rgb(p, q, h) - b = hue2rgb(p, q, h - 1/3) - } + return this; +}; - return this.rgbToHex(r * 255, g * 255, b * 255) -} +/** + * Remove all listeners, or those of the specified event. + * + * @param {(String|Symbol)} [event] The event name. + * @returns {EventEmitter} `this`. + * @public + */ +EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { + var evt; -/* darkens a color by the percentage -* @param {object} color in hex (0xabcdef) -* @param {number} amount -* @return {number} -*/ -function darken(color, amount) -{ - return this.blend(amount, color, 0) -} + if (event) { + evt = prefix ? prefix + event : event; + if (this._events[evt]) clearEvent(this, evt); + } else { + this._events = new Events(); + this._eventsCount = 0; + } -/** based on tinycolor -* https://github.com/bgrins/TinyColor -* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE -* @param {object} color -* @param {number} amount -*/ -function saturate(color, amount) -{ - amount = (amount === 0) ? 0 : (amount || 10) - var hsl = this.hexToHsl(color) - hsl.s += amount / 100 - hsl.s = Math.min(1, Math.max(0, hsl.s)) - return this.hslToHex(hsl) -} + return this; +}; -/** based on tinycolor -* https://github.com/bgrins/TinyColor -* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE -* @param {object} color -* @param {number} amount -*/ -function desaturate(color, amount) -{ - amount = (amount === 0) ? 0 : (amount || 10) - var hsl = this.hexToHsl(color) - hsl.s -= amount / 100 - hsl.s = Math.min(1, Math.max(0, hsl.s)) - return this.hslToHex(hsl) -} +// +// Alias methods names because people roll like that. +// +EventEmitter.prototype.off = EventEmitter.prototype.removeListener; +EventEmitter.prototype.addListener = EventEmitter.prototype.on; -/** - * blends two colors together - * @param {number} percent [0.0 - 1.0] - * @param {string} color1 first color in 0x123456 format - * @param {string} color2 second color in 0x123456 format - * @return {number} - */ -function blend(percent, color1, color2) -{ - if (percent === 0) - { - return color1 - } - if (percent === 1) - { - return color2 - } - var r1 = color1 >> 16 - var g1 = color1 >> 8 & 0x0000ff - var b1 = color1 & 0x0000ff - var r2 = color2 >> 16 - var g2 = color2 >> 8 & 0x0000ff - var b2 = color2 & 0x0000ff - var percent1 = 1 - percent - var r = percent1 * r1 + percent * r2 - var g = percent1 * g1 + percent * g2 - var b = percent1 * b1 + percent * b2 - return r << 16 | g << 8 | b -} +// +// Expose the prefix. +// +EventEmitter.prefixed = prefix; -/** - * returns a hex color into an rgb value - * @param {number} hex - * @return {string} - */ -function hexToRgb(hex) -{ - if (hex === 0) - { - hex = '0x000000' - } - else if (typeof hex !== 'string') - { - var s = '000000' + hex.toString(16) - hex = '0x' + s.substr(s.length - 6) - } - var result = /^0x?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) - return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null -} +// +// Allow `EventEmitter` to be imported as module namespace. +// +EventEmitter.EventEmitter = EventEmitter; -/** - * rgb color to hex in the form of 0x123456 - * @param {(number|string)} r first number or 'rgb(...)' string - * @param {(number|null)} g - * @param {(number|null)} b - * @return {string} - */ -function rgbToHex(r, g, b) -{ - if (arguments.length === 1) { - if (Array.isArray(arguments[0])) { - var number = arguments[0] - r = number[0] - g = number[1] - b = number[2] - } else { - var parse = r.replace(/( *rgb *\( *)|( )|(\) *;?)/,'') - var numbers = parse.split(',') - r = numbers[0] - g = numbers[1] - b = numbers[2] - } - } - return '0x' + ((1 << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b)).toString(16).slice(1) +// +// Expose the module. +// +if ('undefined' !== typeof module) { + module.exports = EventEmitter; } -/** - * returns a random color with balanced r, g, b values (i.e., r, g, b either have the same value or are 0) - * @param {number} min value for random number - * @param {number} max value for random number - * @return {number} color - */ -function random(min, max) -{ - function random() - { - return Random.range(min, max) - } +},{}],13:[function(require,module,exports){ - var colors = [{r:1, g:1, b:1}, {r:1, g:1, b:0}, {r:1,g:0,b:1}, {r:0,g:1,b:1}, {r:1,g:0,b:0}, {r:0,g:1,b:0}, {r:0,g:0,b:1}] - var color = Random.pick(colors) - min = min || 0 - max = max || 255 - return this.rgbToHex(color.r ? random() : 0, color.g ? random() : 0, color.b ? random() : 0) -} +/* + Copyright © 2001 Robert Penner + All rights reserved. -// h: 0-360, s: 0-1, l: 0-1 -/** - * returns a random color based on hsl - * @param {number} hMin [0, 360] - * @param {number} hMax [hMin, 360] - * @param {number} sMin [0, 1] - * @param {number} sMax [sMin, 1] - * @param {number} lMin [0, 1] - * @param {number} lMax [lMin, 1] + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, this list + of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + + Neither the name of the author nor the names of contributors may be used to endorse + or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + OF THE POSSIBILITY OF SUCH DAMAGE. */ -function randomHSL(hMin, hMax, sMin, sMax, lMin, lMax) -{ - var color = { - h: Random.range(hMin, hMax), - s: Random.range(sMin, sMax, true), - l: Random.range(lMin, lMax, true) + +(function() { + var penner, umd; + + umd = function(factory) { + if (typeof exports === 'object') { + return module.exports = factory; + } else if (typeof define === 'function' && define.amd) { + return define([], factory); + } else { + return this.penner = factory; + } + }; + + penner = { + linear: function(t, b, c, d) { + return c * t / d + b; + }, + easeInQuad: function(t, b, c, d) { + return c * (t /= d) * t + b; + }, + easeOutQuad: function(t, b, c, d) { + return -c * (t /= d) * (t - 2) + b; + }, + easeInOutQuad: function(t, b, c, d) { + if ((t /= d / 2) < 1) { + return c / 2 * t * t + b; + } else { + return -c / 2 * ((--t) * (t - 2) - 1) + b; + } + }, + easeInCubic: function(t, b, c, d) { + return c * (t /= d) * t * t + b; + }, + easeOutCubic: function(t, b, c, d) { + return c * ((t = t / d - 1) * t * t + 1) + b; + }, + easeInOutCubic: function(t, b, c, d) { + if ((t /= d / 2) < 1) { + return c / 2 * t * t * t + b; + } else { + return c / 2 * ((t -= 2) * t * t + 2) + b; + } + }, + easeInQuart: function(t, b, c, d) { + return c * (t /= d) * t * t * t + b; + }, + easeOutQuart: function(t, b, c, d) { + return -c * ((t = t / d - 1) * t * t * t - 1) + b; + }, + easeInOutQuart: function(t, b, c, d) { + if ((t /= d / 2) < 1) { + return c / 2 * t * t * t * t + b; + } else { + return -c / 2 * ((t -= 2) * t * t * t - 2) + b; + } + }, + easeInQuint: function(t, b, c, d) { + return c * (t /= d) * t * t * t * t + b; + }, + easeOutQuint: function(t, b, c, d) { + return c * ((t = t / d - 1) * t * t * t * t + 1) + b; + }, + easeInOutQuint: function(t, b, c, d) { + if ((t /= d / 2) < 1) { + return c / 2 * t * t * t * t * t + b; + } else { + return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; + } + }, + easeInSine: function(t, b, c, d) { + return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; + }, + easeOutSine: function(t, b, c, d) { + return c * Math.sin(t / d * (Math.PI / 2)) + b; + }, + easeInOutSine: function(t, b, c, d) { + return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; + }, + easeInExpo: function(t, b, c, d) { + if (t === 0) { + return b; + } else { + return c * Math.pow(2, 10 * (t / d - 1)) + b; + } + }, + easeOutExpo: function(t, b, c, d) { + if (t === d) { + return b + c; + } else { + return c * (-Math.pow(2, -10 * t / d) + 1) + b; + } + }, + easeInOutExpo: function(t, b, c, d) { + if (t === 0) { + b; + } + if (t === d) { + b + c; + } + if ((t /= d / 2) < 1) { + return c / 2 * Math.pow(2, 10 * (t - 1)) + b; + } else { + return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; + } + }, + easeInCirc: function(t, b, c, d) { + return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b; + }, + easeOutCirc: function(t, b, c, d) { + return c * Math.sqrt(1 - (t = t / d - 1) * t) + b; + }, + easeInOutCirc: function(t, b, c, d) { + if ((t /= d / 2) < 1) { + return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; + } else { + return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b; + } + }, + easeInElastic: function(t, b, c, d) { + var a, p, s; + s = 1.70158; + p = 0; + a = c; + if (t === 0) { + b; + } else if ((t /= d) === 1) { + b + c; + } + if (!p) { + p = d * .3; + } + if (a < Math.abs(c)) { + a = c; + s = p / 4; + } else { + s = p / (2 * Math.PI) * Math.asin(c / a); + } + return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; + }, + easeOutElastic: function(t, b, c, d) { + var a, p, s; + s = 1.70158; + p = 0; + a = c; + if (t === 0) { + b; + } else if ((t /= d) === 1) { + b + c; + } + if (!p) { + p = d * .3; + } + if (a < Math.abs(c)) { + a = c; + s = p / 4; + } else { + s = p / (2 * Math.PI) * Math.asin(c / a); + } + return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b; + }, + easeInOutElastic: function(t, b, c, d) { + var a, p, s; + s = 1.70158; + p = 0; + a = c; + if (t === 0) { + b; + } else if ((t /= d / 2) === 2) { + b + c; + } + if (!p) { + p = d * (.3 * 1.5); + } + if (a < Math.abs(c)) { + a = c; + s = p / 4; + } else { + s = p / (2 * Math.PI) * Math.asin(c / a); + } + if (t < 1) { + return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; + } else { + return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b; + } + }, + easeInBack: function(t, b, c, d, s) { + if (s === void 0) { + s = 1.70158; + } + return c * (t /= d) * t * ((s + 1) * t - s) + b; + }, + easeOutBack: function(t, b, c, d, s) { + if (s === void 0) { + s = 1.70158; + } + return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; + }, + easeInOutBack: function(t, b, c, d, s) { + if (s === void 0) { + s = 1.70158; + } + if ((t /= d / 2) < 1) { + return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b; + } else { + return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b; + } + }, + easeInBounce: function(t, b, c, d) { + var v; + v = penner.easeOutBounce(d - t, 0, c, d); + return c - v + b; + }, + easeOutBounce: function(t, b, c, d) { + if ((t /= d) < 1 / 2.75) { + return c * (7.5625 * t * t) + b; + } else if (t < 2 / 2.75) { + return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b; + } else if (t < 2.5 / 2.75) { + return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b; + } else { + return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b; + } + }, + easeInOutBounce: function(t, b, c, d) { + var v; + if (t < d / 2) { + v = penner.easeInBounce(t * 2, 0, c, d); + return v * .5 + b; + } else { + v = penner.easeOutBounce(t * 2 - d, 0, c, d); + return v * .5 + c * .5 + b; + } + } + }; + + umd(penner); + +}).call(this); + +},{}],14:[function(require,module,exports){ +// A library of seedable RNGs implemented in Javascript. +// +// Usage: +// +// var seedrandom = require('seedrandom'); +// var random = seedrandom(1); // or any seed. +// var x = random(); // 0 <= x < 1. Every bit is random. +// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness. + +// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe. +// Period: ~2^116 +// Reported to pass all BigCrush tests. +var alea = require('./lib/alea'); + +// xor128, a pure xor-shift generator by George Marsaglia. +// Period: 2^128-1. +// Reported to fail: MatrixRank and LinearComp. +var xor128 = require('./lib/xor128'); + +// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl. +// Period: 2^192-2^32 +// Reported to fail: CollisionOver, SimpPoker, and LinearComp. +var xorwow = require('./lib/xorwow'); + +// xorshift7, by François Panneton and Pierre L'ecuyer, takes +// a different approach: it adds robustness by allowing more shifts +// than Marsaglia's original three. It is a 7-shift generator +// with 256 bits, that passes BigCrush with no systmatic failures. +// Period 2^256-1. +// No systematic BigCrush failures reported. +var xorshift7 = require('./lib/xorshift7'); + +// xor4096, by Richard Brent, is a 4096-bit xor-shift with a +// very long period that also adds a Weyl generator. It also passes +// BigCrush with no systematic failures. Its long period may +// be useful if you have many generators and need to avoid +// collisions. +// Period: 2^4128-2^32. +// No systematic BigCrush failures reported. +var xor4096 = require('./lib/xor4096'); + +// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random +// number generator derived from ChaCha, a modern stream cipher. +// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf +// Period: ~2^127 +// No systematic BigCrush failures reported. +var tychei = require('./lib/tychei'); + +// The original ARC4-based prng included in this library. +// Period: ~2^1600 +var sr = require('./seedrandom'); + +sr.alea = alea; +sr.xor128 = xor128; +sr.xorwow = xorwow; +sr.xorshift7 = xorshift7; +sr.xor4096 = xor4096; +sr.tychei = tychei; + +module.exports = sr; + +},{"./lib/alea":15,"./lib/tychei":16,"./lib/xor128":17,"./lib/xor4096":18,"./lib/xorshift7":19,"./lib/xorwow":20,"./seedrandom":21}],15:[function(require,module,exports){ +// A port of an algorithm by Johannes Baagøe , 2010 +// http://baagoe.com/en/RandomMusings/javascript/ +// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror +// Original work is under MIT license - + +// Copyright (C) 2010 by Johannes Baagøe +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + + + +(function(global, module, define) { + +function Alea(seed) { + var me = this, mash = Mash(); + + me.next = function() { + var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32 + me.s0 = me.s1; + me.s1 = me.s2; + return me.s2 = t - (me.c = t | 0); + }; + + // Apply the seeding algorithm from Baagoe. + me.c = 1; + me.s0 = mash(' '); + me.s1 = mash(' '); + me.s2 = mash(' '); + me.s0 -= mash(seed); + if (me.s0 < 0) { me.s0 += 1; } + me.s1 -= mash(seed); + if (me.s1 < 0) { me.s1 += 1; } + me.s2 -= mash(seed); + if (me.s2 < 0) { me.s2 += 1; } + mash = null; +} + +function copy(f, t) { + t.c = f.c; + t.s0 = f.s0; + t.s1 = f.s1; + t.s2 = f.s2; + return t; +} + +function impl(seed, opts) { + var xg = new Alea(seed), + state = opts && opts.state, + prng = xg.next; + prng.int32 = function() { return (xg.next() * 0x100000000) | 0; } + prng.double = function() { + return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 + }; + prng.quick = prng; + if (state) { + if (typeof(state) == 'object') copy(state, xg); + prng.state = function() { return copy(xg, {}); } + } + return prng; +} + +function Mash() { + var n = 0xefc8249d; + + var mash = function(data) { + data = data.toString(); + for (var i = 0; i < data.length; i++) { + n += data.charCodeAt(i); + var h = 0.02519603282416938 * n; + n = h >>> 0; + h -= n; + h *= n; + n = h >>> 0; + h -= n; + n += h * 0x100000000; // 2^32 + } + return (n >>> 0) * 2.3283064365386963e-10; // 2^-32 + }; + + return mash; +} + + +if (module && module.exports) { + module.exports = impl; +} else if (define && define.amd) { + define(function() { return impl; }); +} else { + this.alea = impl; +} + +})( + this, + (typeof module) == 'object' && module, // present in node.js + (typeof define) == 'function' && define // present with an AMD loader +); + + + +},{}],16:[function(require,module,exports){ +// A Javascript implementaion of the "Tyche-i" prng algorithm by +// Samuel Neves and Filipe Araujo. +// See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf + +(function(global, module, define) { + +function XorGen(seed) { + var me = this, strseed = ''; + + // Set up generator function. + me.next = function() { + var b = me.b, c = me.c, d = me.d, a = me.a; + b = (b << 25) ^ (b >>> 7) ^ c; + c = (c - d) | 0; + d = (d << 24) ^ (d >>> 8) ^ a; + a = (a - b) | 0; + me.b = b = (b << 20) ^ (b >>> 12) ^ c; + me.c = c = (c - d) | 0; + me.d = (d << 16) ^ (c >>> 16) ^ a; + return me.a = (a - b) | 0; + }; + + /* The following is non-inverted tyche, which has better internal + * bit diffusion, but which is about 25% slower than tyche-i in JS. + me.next = function() { + var a = me.a, b = me.b, c = me.c, d = me.d; + a = (me.a + me.b | 0) >>> 0; + d = me.d ^ a; d = d << 16 ^ d >>> 16; + c = me.c + d | 0; + b = me.b ^ c; b = b << 12 ^ d >>> 20; + me.a = a = a + b | 0; + d = d ^ a; me.d = d = d << 8 ^ d >>> 24; + me.c = c = c + d | 0; + b = b ^ c; + return me.b = (b << 7 ^ b >>> 25); + } + */ + + me.a = 0; + me.b = 0; + me.c = 2654435769 | 0; + me.d = 1367130551; + + if (seed === Math.floor(seed)) { + // Integer seed. + me.a = (seed / 0x100000000) | 0; + me.b = seed | 0; + } else { + // String seed. + strseed += seed; + } + + // Mix in string seed, then discard an initial batch of 64 values. + for (var k = 0; k < strseed.length + 20; k++) { + me.b ^= strseed.charCodeAt(k) | 0; + me.next(); + } +} + +function copy(f, t) { + t.a = f.a; + t.b = f.b; + t.c = f.c; + t.d = f.d; + return t; +}; + +function impl(seed, opts) { + var xg = new XorGen(seed), + state = opts && opts.state, + prng = function() { return (xg.next() >>> 0) / 0x100000000; }; + prng.double = function() { + do { + var top = xg.next() >>> 11, + bot = (xg.next() >>> 0) / 0x100000000, + result = (top + bot) / (1 << 21); + } while (result === 0); + return result; + }; + prng.int32 = xg.next; + prng.quick = prng; + if (state) { + if (typeof(state) == 'object') copy(state, xg); + prng.state = function() { return copy(xg, {}); } + } + return prng; +} + +if (module && module.exports) { + module.exports = impl; +} else if (define && define.amd) { + define(function() { return impl; }); +} else { + this.tychei = impl; +} + +})( + this, + (typeof module) == 'object' && module, // present in node.js + (typeof define) == 'function' && define // present with an AMD loader +); + + + +},{}],17:[function(require,module,exports){ +// A Javascript implementaion of the "xor128" prng algorithm by +// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper + +(function(global, module, define) { + +function XorGen(seed) { + var me = this, strseed = ''; + + me.x = 0; + me.y = 0; + me.z = 0; + me.w = 0; + + // Set up generator function. + me.next = function() { + var t = me.x ^ (me.x << 11); + me.x = me.y; + me.y = me.z; + me.z = me.w; + return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8); + }; + + if (seed === (seed | 0)) { + // Integer seed. + me.x = seed; + } else { + // String seed. + strseed += seed; + } + + // Mix in string seed, then discard an initial batch of 64 values. + for (var k = 0; k < strseed.length + 64; k++) { + me.x ^= strseed.charCodeAt(k) | 0; + me.next(); + } +} + +function copy(f, t) { + t.x = f.x; + t.y = f.y; + t.z = f.z; + t.w = f.w; + return t; +} + +function impl(seed, opts) { + var xg = new XorGen(seed), + state = opts && opts.state, + prng = function() { return (xg.next() >>> 0) / 0x100000000; }; + prng.double = function() { + do { + var top = xg.next() >>> 11, + bot = (xg.next() >>> 0) / 0x100000000, + result = (top + bot) / (1 << 21); + } while (result === 0); + return result; + }; + prng.int32 = xg.next; + prng.quick = prng; + if (state) { + if (typeof(state) == 'object') copy(state, xg); + prng.state = function() { return copy(xg, {}); } + } + return prng; +} + +if (module && module.exports) { + module.exports = impl; +} else if (define && define.amd) { + define(function() { return impl; }); +} else { + this.xor128 = impl; +} + +})( + this, + (typeof module) == 'object' && module, // present in node.js + (typeof define) == 'function' && define // present with an AMD loader +); + + + +},{}],18:[function(require,module,exports){ +// A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm. +// +// This fast non-cryptographic random number generator is designed for +// use in Monte-Carlo algorithms. It combines a long-period xorshift +// generator with a Weyl generator, and it passes all common batteries +// of stasticial tests for randomness while consuming only a few nanoseconds +// for each prng generated. For background on the generator, see Brent's +// paper: "Some long-period random number generators using shifts and xors." +// http://arxiv.org/pdf/1004.3115v1.pdf +// +// Usage: +// +// var xor4096 = require('xor4096'); +// random = xor4096(1); // Seed with int32 or string. +// assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits. +// assert.equal(random.int32(), 1806534897); // signed int32, 32 bits. +// +// For nonzero numeric keys, this impelementation provides a sequence +// identical to that by Brent's xorgens 3 implementaion in C. This +// implementation also provides for initalizing the generator with +// string seeds, or for saving and restoring the state of the generator. +// +// On Chrome, this prng benchmarks about 2.1 times slower than +// Javascript's built-in Math.random(). + +(function(global, module, define) { + +function XorGen(seed) { + var me = this; + + // Set up generator function. + me.next = function() { + var w = me.w, + X = me.X, i = me.i, t, v; + // Update Weyl generator. + me.w = w = (w + 0x61c88647) | 0; + // Update xor generator. + v = X[(i + 34) & 127]; + t = X[i = ((i + 1) & 127)]; + v ^= v << 13; + t ^= t << 17; + v ^= v >>> 15; + t ^= t >>> 12; + // Update Xor generator array state. + v = X[i] = v ^ t; + me.i = i; + // Result is the combination. + return (v + (w ^ (w >>> 16))) | 0; + }; + + function init(me, seed) { + var t, v, i, j, w, X = [], limit = 128; + if (seed === (seed | 0)) { + // Numeric seeds initialize v, which is used to generates X. + v = seed; + seed = null; + } else { + // String seeds are mixed into v and X one character at a time. + seed = seed + '\0'; + v = 0; + limit = Math.max(limit, seed.length); + } + // Initialize circular array and weyl value. + for (i = 0, j = -32; j < limit; ++j) { + // Put the unicode characters into the array, and shuffle them. + if (seed) v ^= seed.charCodeAt((j + 32) % seed.length); + // After 32 shuffles, take v as the starting w value. + if (j === 0) w = v; + v ^= v << 10; + v ^= v >>> 15; + v ^= v << 4; + v ^= v >>> 13; + if (j >= 0) { + w = (w + 0x61c88647) | 0; // Weyl. + t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array. + i = (0 == t) ? i + 1 : 0; // Count zeroes. + } + } + // We have detected all zeroes; make the key nonzero. + if (i >= 128) { + X[(seed && seed.length || 0) & 127] = -1; + } + // Run the generator 512 times to further mix the state before using it. + // Factoring this as a function slows the main generator, so it is just + // unrolled here. The weyl generator is not advanced while warming up. + i = 127; + for (j = 4 * 128; j > 0; --j) { + v = X[(i + 34) & 127]; + t = X[i = ((i + 1) & 127)]; + v ^= v << 13; + t ^= t << 17; + v ^= v >>> 15; + t ^= t >>> 12; + X[i] = v ^ t; + } + // Storing state as object members is faster than using closure variables. + me.w = w; + me.X = X; + me.i = i; + } + + init(me, seed); +} + +function copy(f, t) { + t.i = f.i; + t.w = f.w; + t.X = f.X.slice(); + return t; +}; + +function impl(seed, opts) { + if (seed == null) seed = +(new Date); + var xg = new XorGen(seed), + state = opts && opts.state, + prng = function() { return (xg.next() >>> 0) / 0x100000000; }; + prng.double = function() { + do { + var top = xg.next() >>> 11, + bot = (xg.next() >>> 0) / 0x100000000, + result = (top + bot) / (1 << 21); + } while (result === 0); + return result; + }; + prng.int32 = xg.next; + prng.quick = prng; + if (state) { + if (state.X) copy(state, xg); + prng.state = function() { return copy(xg, {}); } + } + return prng; +} + +if (module && module.exports) { + module.exports = impl; +} else if (define && define.amd) { + define(function() { return impl; }); +} else { + this.xor4096 = impl; +} + +})( + this, // window object or global + (typeof module) == 'object' && module, // present in node.js + (typeof define) == 'function' && define // present with an AMD loader +); + +},{}],19:[function(require,module,exports){ +// A Javascript implementaion of the "xorshift7" algorithm by +// François Panneton and Pierre L'ecuyer: +// "On the Xorgshift Random Number Generators" +// http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf + +(function(global, module, define) { + +function XorGen(seed) { + var me = this; + + // Set up generator function. + me.next = function() { + // Update xor generator. + var X = me.x, i = me.i, t, v, w; + t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24); + t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10); + t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3); + t = X[(i + 4) & 7]; v ^= t ^ (t << 7); + t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9); + X[i] = v; + me.i = (i + 1) & 7; + return v; + }; + + function init(me, seed) { + var j, w, X = []; + + if (seed === (seed | 0)) { + // Seed state array using a 32-bit integer. + w = X[0] = seed; + } else { + // Seed state using a string. + seed = '' + seed; + for (j = 0; j < seed.length; ++j) { + X[j & 7] = (X[j & 7] << 15) ^ + (seed.charCodeAt(j) + X[(j + 1) & 7] << 13); + } + } + // Enforce an array length of 8, not all zeroes. + while (X.length < 8) X.push(0); + for (j = 0; j < 8 && X[j] === 0; ++j); + if (j == 8) w = X[7] = -1; else w = X[j]; + + me.x = X; + me.i = 0; + + // Discard an initial 256 values. + for (j = 256; j > 0; --j) { + me.next(); } - return this.hslToHex(color) -} + } -/** - * returns random colors based on HSL with different hues - * based on http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ - * @returns {number[]} colors in hex format (0x123456) - */ -function randomGoldenRatioHSL(count, saturation, luminosity) -{ - var goldenRatio = 0.618033988749895 - var h = Random.get(1, true) - var colors = [] - for (var i = 0; i < count; i++) - { - colors.push(this.hslToHex(h, saturation, luminosity)) - h = (h + goldenRatio) % 1 - } - return colors + init(me, seed); } -module.exports = { - poundToHex: poundToHex, - hexToPound: hexToPound, - valueToPound: valueToPound, - hexToHsl: hexToHsl, - hslToHex: hslToHex, - hexToRgb: hexToRgb, - rgbToHex: rgbToHex, - darken: darken, - saturate: saturate, - desaturate: desaturate, - blend: blend, - random: random, - randomHSL: randomHSL, - randomGoldenRatioHSL: randomGoldenRatioHSL +function copy(f, t) { + t.x = f.x.slice(); + t.i = f.i; + return t; } -},{"yy-random":13}],13:[function(require,module,exports){ -'use strict'; -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -// yy-random -// by David Figatner -// MIT license -// copyright YOPEY YOPEY LLC 2016-17 -// https://github.com/davidfig/random +function impl(seed, opts) { + if (seed == null) seed = +(new Date); + var xg = new XorGen(seed), + state = opts && opts.state, + prng = function() { return (xg.next() >>> 0) / 0x100000000; }; + prng.double = function() { + do { + var top = xg.next() >>> 11, + bot = (xg.next() >>> 0) / 0x100000000, + result = (top + bot) / (1 << 21); + } while (result === 0); + return result; + }; + prng.int32 = xg.next; + prng.quick = prng; + if (state) { + if (state.x) copy(state, xg); + prng.state = function() { return copy(xg, {}); } + } + return prng; +} -var seedrandom = require('seedrandom'); +if (module && module.exports) { + module.exports = impl; +} else if (define && define.amd) { + define(function() { return impl; }); +} else { + this.xorshift7 = impl; +} -var Random = function () { - function Random() { - _classCallCheck(this, Random); +})( + this, + (typeof module) == 'object' && module, // present in node.js + (typeof define) == 'function' && define // present with an AMD loader +); - this.generator = Math.random; - } - /** - * generates a seeded number - * @param {number} seed - * @param {object} [options] - * @param {string} [PRNG="alea"] - name of algorithm, see https://github.com/davidbau/seedrandom - * @param {boolean} [save=true] - */ +},{}],20:[function(require,module,exports){ +// A Javascript implementaion of the "xorwow" prng algorithm by +// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper +(function(global, module, define) { - _createClass(Random, [{ - key: 'seed', - value: function seed(_seed, options) { - options = options || {}; - this.generator = seedrandom[options.PRNG || 'alea'](_seed, { state: options.state }); - this.options = options; - } +function XorGen(seed) { + var me = this, strseed = ''; - /** - * saves the state of the random generator - * can only be used after Random.seed() is called - * @returns {number} state - */ + // Set up generator function. + me.next = function() { + var t = (me.x ^ (me.x >>> 2)); + me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v; + return (me.d = (me.d + 362437 | 0)) + + (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0; + }; - }, { - key: 'save', - value: function save() { - if (this.generator !== Math.random) { - return this.generator.state(); - } - } + me.x = 0; + me.y = 0; + me.z = 0; + me.w = 0; + me.v = 0; - /** - * restores the state of the random generator - * @param {number} state - */ + if (seed === (seed | 0)) { + // Integer seed. + me.x = seed; + } else { + // String seed. + strseed += seed; + } - }, { - key: 'restore', - value: function restore(state) { - this.generator = seedrandom[this.options.PRNG || 'alea']('', { state: state }); - } + // Mix in string seed, then discard an initial batch of 64 values. + for (var k = 0; k < strseed.length + 64; k++) { + me.x ^= strseed.charCodeAt(k) | 0; + if (k == strseed.length) { + me.d = me.x << 10 ^ me.x >>> 4; + } + me.next(); + } +} - /** - * changes the generator to use the old Math.sin-based random function - * based on : http://stackoverflow.com/questions/521295/javascript-random-seeds - * (deprecated) Use only for compatibility purposes - * @param {number} seed - */ +function copy(f, t) { + t.x = f.x; + t.y = f.y; + t.z = f.z; + t.w = f.w; + t.v = f.v; + t.d = f.d; + return t; +} - }, { - key: 'seedOld', - value: function seedOld(seed) { - this.generator = function () { - var x = Math.sin(seed++) * 10000; - return x - Math.floor(x); - }; - } +function impl(seed, opts) { + var xg = new XorGen(seed), + state = opts && opts.state, + prng = function() { return (xg.next() >>> 0) / 0x100000000; }; + prng.double = function() { + do { + var top = xg.next() >>> 11, + bot = (xg.next() >>> 0) / 0x100000000, + result = (top + bot) / (1 << 21); + } while (result === 0); + return result; + }; + prng.int32 = xg.next; + prng.quick = prng; + if (state) { + if (typeof(state) == 'object') copy(state, xg); + prng.state = function() { return copy(xg, {}); } + } + return prng; +} - /** - * create a separate random generator using the seed - * @param {number} seed - * @return {object} - */ +if (module && module.exports) { + module.exports = impl; +} else if (define && define.amd) { + define(function() { return impl; }); +} else { + this.xorwow = impl; +} - }, { - key: 'separateSeed', - value: function separateSeed(seed) { - var random = new Random(); - random.seed(seed); - return random; - } +})( + this, + (typeof module) == 'object' && module, // present in node.js + (typeof define) == 'function' && define // present with an AMD loader +); - /** - * resets the random number this.generator to Math.random() - */ - }, { - key: 'reset', - value: function reset() { - this.generator = Math.random; - } - /** - * returns a random number using the this.generator between [0, ceiling - 1] - * @param {number} ceiling - * @param {boolean} [useFloat=false] - * @return {number} - */ +},{}],21:[function(require,module,exports){ +/* +Copyright 2014 David Bau. - }, { - key: 'get', - value: function get(ceiling, useFloat) { - var negative = ceiling < 0 ? -1 : 1; - ceiling *= negative; - var result = void 0; - if (useFloat) { - result = this.generator() * ceiling; - } else { - result = Math.floor(this.generator() * ceiling); - } - return result * negative; - } +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: - /** - * returns a random integer between 0 - Number.MAX_SAFE_INTEGER - * @return {number} - */ +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. - }, { - key: 'getHuge', - value: function getHuge() { - return this.get(Number.MAX_SAFE_INTEGER); - } +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - /** - * random number [middle - range, middle + range] - * @param {number} middle - * @param {number} delta - * @param {boolean} [useFloat=false] - * @return {number} - */ +*/ - }, { - key: 'middle', - value: function middle(_middle, delta, useFloat) { - var half = delta / 2; - return this.range(_middle - half, _middle + half, useFloat); - } +(function (pool, math) { +// +// The following constants are related to IEEE 754 limits. +// +var global = this, + width = 256, // each RC4 output is 0 <= x < 256 + chunks = 6, // at least six RC4 outputs for each double + digits = 52, // there are 52 significant digits in a double + rngname = 'random', // rngname: name for Math.random and Math.seedrandom + startdenom = math.pow(width, chunks), + significance = math.pow(2, digits), + overflow = significance * 2, + mask = width - 1, + nodecrypto; // node.js crypto module, initialized at the bottom. - /** - * random number [start, end] - * @param {number} start - * @param {number} end - * @param {boolean} [useFloat=false] if true, then range is (start, end)--i.e., not inclusive to start and end - * @return {number} - */ +// +// seedrandom() +// This is the seedrandom function described above. +// +function seedrandom(seed, options, callback) { + var key = []; + options = (options == true) ? { entropy: true } : (options || {}); - }, { - key: 'range', - value: function range(start, end, useFloat) { - // case where there is no range - if (end === start) { - return end; - } + // Flatten the seed string or build one from local entropy if needed. + var shortseed = mixkey(flatten( + options.entropy ? [seed, tostring(pool)] : + (seed == null) ? autoseed() : seed, 3), key); - if (useFloat) { - return this.get(end - start, true) + start; - } else { - var range = void 0; - if (start < 0 && end > 0) { - range = -start + end + 1; - } else if (start === 0 && end > 0) { - range = end + 1; - } else if (start < 0 && end === 0) { - range = start - 1; - start = 1; - } else if (start < 0 && end < 0) { - range = end - start - 1; - } else { - range = end - start + 1; - } - return Math.floor(this.generator() * range) + start; - } - } + // Use the seed to initialize an ARC4 generator. + var arc4 = new ARC4(key); - /** - * an array of random numbers between [start, end] - * @param {number} start - * @param {number} end - * @param {number} count - * @param {boolean} [useFloat=false] - * @return {number[]} - */ + // This function returns a random double in [0, 1) that contains + // randomness in every bit of the mantissa of the IEEE 754 value. + var prng = function() { + var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48 + d = startdenom, // and denominator d = 2 ^ 48. + x = 0; // and no 'extra last byte'. + while (n < significance) { // Fill up all significant digits by + n = (n + x) * width; // shifting numerator and + d *= width; // denominator and generating a + x = arc4.g(1); // new least-significant-byte. + } + while (n >= overflow) { // To avoid rounding up, before adding + n /= 2; // last byte, shift everything + d /= 2; // right using integer math until + x >>>= 1; // we have exactly the desired bits. + } + return (n + x) / d; // Form the number within [0, 1). + }; - }, { - key: 'rangeMultiple', - value: function rangeMultiple(start, end, count, useFloat) { - var array = []; - for (var i = 0; i < count; i++) { - array.push(this.range(start, end, useFloat)); - } - return array; - } + prng.int32 = function() { return arc4.g(4) | 0; } + prng.quick = function() { return arc4.g(4) / 0x100000000; } + prng.double = prng; - /** - * an array of random numbers between [middle - range, middle + range] - * @param {number} middle - * @param {number} range - * @param {number} count - * @param {boolean} [useFloat=false] - * @return {number[]} - */ + // Mix the randomness into accumulated entropy. + mixkey(tostring(arc4.S), pool); - }, { - key: 'middleMultiple', - value: function middleMultiple(middle, range, count, useFloat) { - var array = []; - for (var i = 0; i < count; i++) { - array.push(middle(middle, range, useFloat)); - } - return array; + // Calling convention: what to return as a function of prng, seed, is_math. + return (options.pass || callback || + function(prng, seed, is_math_call, state) { + if (state) { + // Load the arc4 state from the given state if it has an S array. + if (state.S) { copy(state, arc4); } + // Only provide the .state method if requested via options.state. + prng.state = function() { return copy(arc4, {}); } } - /** - * @param {number} [chance=0.5] - * returns random sign (either +1 or -1) - * @return {number} - */ + // If called as a method of Math (Math.seedrandom()), mutate + // Math.random because that is how seedrandom.js has worked since v1.0. + if (is_math_call) { math[rngname] = prng; return seed; } - }, { - key: 'sign', - value: function sign(chance) { - chance = chance || 0.5; - return this.generator() < chance ? 1 : -1; - } + // Otherwise, it is a newer calling convention, so return the + // prng directly. + else return prng; + })( + prng, + shortseed, + 'global' in options ? options.global : (this == math), + options.state); +} +math['seed' + rngname] = seedrandom; - /** - * tells you whether a random chance was achieved - * @param {number} [percent=0.5] - * @return {boolean} - */ +// +// ARC4 +// +// An ARC4 implementation. The constructor takes a key in the form of +// an array of at most (width) integers that should be 0 <= x < (width). +// +// The g(count) method returns a pseudorandom integer that concatenates +// the next (count) outputs from ARC4. Its return value is a number x +// that is in the range 0 <= x < (width ^ count). +// +function ARC4(key) { + var t, keylen = key.length, + me = this, i = 0, j = me.i = me.j = 0, s = me.S = []; - }, { - key: 'chance', - value: function chance(percent) { - return this.generator() < (percent || 0.5); - } + // The empty key [] is treated as [0]. + if (!keylen) { key = [keylen++]; } - /** - * returns a random angle in radians [0 - 2 * Math.PI) - */ + // Set up S using the standard key scheduling algorithm. + while (i < width) { + s[i] = i++; + } + for (i = 0; i < width; i++) { + s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))]; + s[j] = t; + } - }, { - key: 'angle', - value: function angle() { - return this.get(Math.PI * 2, true); - } + // The "g" method returns the next (count) outputs as one number. + (me.g = function(count) { + // Using instance members instead of closure state nearly doubles speed. + var t, r = 0, + i = me.i, j = me.j, s = me.S; + while (count--) { + t = s[i = mask & (i + 1)]; + r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))]; + } + me.i = i; me.j = j; + return r; + // For robust unpredictability, the function call below automatically + // discards an initial batch of values. This is called RC4-drop[256]. + // See http://google.com/search?q=rsa+fluhrer+response&btnI + })(width); +} - /** - * Shuffle array (either in place or copied) - * from http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array - * @param {Array} array - * @param {boolean} [copy=false] whether to shuffle in place (default) or return a new shuffled array - * @return {Array} a shuffled array - */ +// +// copy() +// Copies internal state of ARC4 to or from a plain object. +// +function copy(f, t) { + t.i = f.i; + t.j = f.j; + t.S = f.S.slice(); + return t; +}; - }, { - key: 'shuffle', - value: function shuffle(array, copy) { - if (copy) { - array = array.slice(); - } - if (array.length === 0) { - return array; - } +// +// flatten() +// Converts an object tree to nested arrays of strings. +// +function flatten(obj, depth) { + var result = [], typ = (typeof obj), prop; + if (depth && typ == 'object') { + for (prop in obj) { + try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} + } + } + return (result.length ? result : typ == 'string' ? obj : obj + '\0'); +} - var currentIndex = array.length, - temporaryValue = void 0, - randomIndex = void 0; +// +// mixkey() +// Mixes a string seed into a key that is an array of integers, and +// returns a shortened string seed that is equivalent to the result key. +// +function mixkey(seed, key) { + var stringseed = seed + '', smear, j = 0; + while (j < stringseed.length) { + key[mask & j] = + mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++)); + } + return tostring(key); +} - // While there remain elements to shuffle... - while (0 !== currentIndex) { - // Pick a remaining element... - randomIndex = this.get(currentIndex); - currentIndex -= 1; +// +// autoseed() +// Returns an object for autoseeding, using window.crypto and Node crypto +// module if available. +// +function autoseed() { + try { + var out; + if (nodecrypto && (out = nodecrypto.randomBytes)) { + // The use of 'out' to remember randomBytes makes tight minified code. + out = out(width); + } else { + out = new Uint8Array(width); + (global.crypto || global.msCrypto).getRandomValues(out); + } + return tostring(out); + } catch (e) { + var browser = global.navigator, + plugins = browser && browser.plugins; + return [+new Date, global, plugins, global.screen, tostring(pool)]; + } +} - // And swap it with the current element. - temporaryValue = array[currentIndex]; - array[currentIndex] = array[randomIndex]; - array[randomIndex] = temporaryValue; - } - return array; - } +// +// tostring() +// Converts an array of charcodes to a string +// +function tostring(a) { + return String.fromCharCode.apply(0, a); +} - /** - * picks a random element from an array - * @param {Array} array - * @return {*} - */ +// +// When seedrandom.js is loaded, we immediately mix a few bits +// from the built-in RNG into the entropy pool. Because we do +// not want to interfere with deterministic PRNG state later, +// seedrandom will not call math.random on its own again after +// initialization. +// +mixkey(math.random(), pool); - }, { - key: 'pick', - value: function pick(array, remove) { - if (!remove) { - return array[this.get(array.length)]; - } else { - var pick = this.get(array.length); - var temp = array[pick]; - array.splice(pick, 1); - return temp; - } - } +// +// Nodejs and AMD support: export the implementation as a module using +// either convention. +// +if ((typeof module) == 'object' && module.exports) { + module.exports = seedrandom; + // When in node.js, try using crypto package for autoseeding. + try { + nodecrypto = require('crypto'); + } catch (ex) {} +} else if ((typeof define) == 'function' && define.amd) { + define(function() { return seedrandom; }); +} - /** - * returns a random property from an object - * from http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object - * @param {object} obj - * @return {*} - */ +// End anonymous scope, and pass initial values. +})( + [], // pool: entropy pool starts empty + Math // math: package containing random, pow, and seedrandom +); - }, { - key: 'property', - value: function property(obj) { - var result; - var count = 0; - for (var prop in obj) { - if (this.chance(1 / ++count)) { - result = prop; - } - } - return result; - } +},{"crypto":25}],22:[function(require,module,exports){ +// angle.js +// Released under MIT license +// Author: David Figatner +// Copyright (c) 2016-17 YOPEY YOPEY LLC - /** - * creates a random set where each entry is a value between [min, max] - * @param {number} min - * @param {number} max - * @param {number} amount of numbers in set - * @param {number[]} - */ +var _toDegreeConversion = 180 / Math.PI +var _toRadianConversion = Math.PI / 180 - }, { - key: 'set', - value: function set(min, max, amount) { - var set = [], - all = [], - i; - for (i = min; i < max; i++) { - all.push(i); - } +/** @constant {number} */ +var UP = Math.PI / 2 +var DOWN = 3 * Math.PI / 2 +var LEFT = Math.PI +var RIGHT = 0 - for (i = 0; i < amount; i++) { - var found = this.get(all.length); - set.push(all[found]); - all.splice(found, 1); - } - return set; - } +var NORTH = UP +var SOUTH = DOWN +var WEST = LEFT +var EAST = RIGHT - /** - * returns a set of numbers with a randomly even distribution (i.e., no overlapping and filling the space) - * @param {number} start position - * @param {number} end position - * @param {number} count of non-start/end points - * @param {boolean} [includeStart=false] includes start point (count++) - * @param {boolean} [includeEnd=false] includes end point (count++) - * @param {boolean} [useFloat=false] - * @param {number[]} - */ +var PI_2 = Math.PI * 2 +var PI_QUARTER = Math.PI / 4 +var PI_HALF = Math.PI / 2 - }, { - key: 'distribution', - value: function distribution(start, end, count, includeStart, includeEnd, useFloat) { - var interval = Math.floor((end - start) / count); - var halfInterval = interval / 2; - var quarterInterval = interval / 4; - var set = []; - if (includeStart) { - set.push(start); - } - for (var i = 0; i < count; i++) { - set.push(start + i * interval + halfInterval + this.range(-quarterInterval, quarterInterval, useFloat)); - } - if (includeEnd) { - set.push(end); - } - return set; - } +/** + * converts from radians to degrees (all other functions expect radians) + * @param {number} radians + * @return {number} degrees + */ +function toDegrees(radians) +{ + return radians * _toDegreeConversion +} - /** - * returns a random number based on weighted probability between [min, max] - * from http://stackoverflow.com/questions/22656126/javascript-random-number-with-weighted-probability - * @param {number} min value - * @param {number} max value - * @param {number} target for average value - * @param {number} stddev - standard deviation - */ +/** + * converts from degrees to radians (all other functions expect radians) + * @param {number} degrees + * @return {number} radians + */ +function toRadians(degrees) +{ + return degrees * _toRadianConversion +} - }, { - key: 'weightedProbabilityInt', - value: function weightedProbabilityInt(min, max, target, stddev) { - function normRand() { - var x1 = void 0, - x2 = void 0, - rad = void 0; - do { - x1 = 2 * this.get(1, true) - 1; - x2 = 2 * this.get(1, true) - 1; - rad = x1 * x1 + x2 * x2; - } while (rad >= 1 || rad === 0); - var c = Math.sqrt(-2 * Math.log(rad) / rad); - return x1 * c; - } +/** + * returns whether the target angle is between angle1 and angle2 (in radians) + * (based on: http://stackoverflow.com/questions/11406189/determine-if-angle-lies-between-2-other-angles) + * @param {number} target angle + * @param {number} angle1 + * @param {number} angle2 + * @return {boolean} + */ +function isAngleBetween(target, angle1, angle2) +{ + var rAngle = ((angle2 - angle1) % PI_2 + PI_2) % PI_2 + if (rAngle >= Math.PI) + { + var swap = angle1 + angle1 = angle2 + angle2 = swap + } - stddev = stddev || 1; - if (Math.random() < 0.81546) { - while (true) { - var sample = normRand() * stddev + target; - if (sample >= min && sample <= max) { - return sample; - } - } - } else { - return this.range(min, max); - } - } + if (angle1 <= angle2) + { + return target >= angle1 && target <= angle2 + } + else + { + return target >= angle1 || target <= angle2 + } +} - /* - * returns a random hex color (0 - 0xffffff) - * @return {number} - */ +/** + * returns +1 or -1 based on whether the difference between two angles is positive or negative (in radians) + * @param {number} target angle + * @param {number} source angle + * @return {number} 1 or -1 + */ +function differenceAnglesSign(target, source) +{ + function mod(a, n) + { + return (a % n + n) % n + } - }, { - key: 'color', - value: function color() { - return this.get(0xffffff); - } - }]); + var a = target - source + return mod((a + Math.PI), PI_2) - Math.PI > 0 ? 1 : -1 +} - return Random; -}(); +/** + * returns the normalized difference between two angles (in radians) + * @param {number} a - first angle + * @param {number} b - second angle + * @return {number} normalized difference between a and b + */ +function differenceAngles(a, b) +{ + var c = Math.abs(a - b) % PI_2 + return c > Math.PI ? (PI_2 - c) : c +} -module.exports = new Random(); +/** + * returns a target angle that is the shortest way to rotate an object between start and to--may choose a negative angle + * @param {number} start + * @param {number} to + * @return {number} shortest target angle + */ +function shortestAngle(start, to) +{ + var difference = differenceAngles(to, start) + var sign = differenceAnglesSign(to, start) + var delta = difference * sign + return delta + start +} -},{"seedrandom":3}],14:[function(require,module,exports){ -const wait = require('./wait') +/** + * returns the normalized angle (0 - PI x 2) + * @param {number} radians + * @return {number} normalized angle in radians + */ +function normalize(radians) +{ + return radians - PI_2 * Math.floor(radians / PI_2) +} -class angle extends wait +/** + * returns angle between two points (in radians) + * @param {Point} [point1] {x: x, y: y} + * @param {Point} [point2] {x: x, y: y} + * @param {number} [x1] + * @param {number} [y1] + * @param {number} [x2] + * @param {number} [y2] + * @return {number} angle + */ +function angleTwoPoints(/* (point1, point2) OR (x1, y1, x2, y2) */) { - /** - * animate object's {x, y} using an angle - * @param {object} object to animate - * @param {number} angle in radians - * @param {number} speed in pixels/millisecond - * @param {number} [duration=0] in milliseconds; if 0, then continues forever - * @param {object} [options] @see {@link Wait} - * @private - */ - constructor(object, angle, speed, duration, options) + if (arguments.length === 4) { - options = options || {} - super(object, options) - this.type = 'Angle' - if (options.load) - { - this.load(options.load) - } - else - { - this.angle = angle - this.speed = speed - this.duration = duration || 0 - } + return Math.atan2(arguments[3] - arguments[1], arguments[2] - arguments[0]) + } + else + { + return Math.atan2(arguments[1].y - arguments[0].y, arguments[1].x - arguments[0].x) + } +} + +/** + * returns distance between two points + * @param {Point} [point1] {x: x, y: y} + * @param {Point} [point2] {x: x, y: y} + * @param {number} [x1] + * @param {number} [y1] + * @param {number} [x2] + * @param {number} [y2] + * @return {number} distance + */ +function distanceTwoPoints(/* (point1, point2) OR (x1, y1, x2, y2) */) +{ + if (arguments.length === 2) + { + return Math.sqrt(Math.pow(arguments[1].x - arguments[0].x, 2) + Math.pow(arguments[1].y - arguments[0].y, 2)) + } + else + { + return Math.sqrt(Math.pow(arguments[2] - arguments[0], 2) + Math.pow(arguments[3] - arguments[1], 2)) } +} - save() +/** + * returns the squared distance between two points + * @param {Point} [point1] {x: x, y: y} + * @param {Point} [point2] {x: x, y: y} + * @param {number} [x1] + * @param {number} [y1] + * @param {number} [x2] + * @param {number} [y2] + * @return {number} squared distance + */ +function distanceTwoPointsSquared(/* (point1, point2) OR (x1, y1, x2, y2) */) +{ + if (arguments.length === 2) { - const save = super.save() - save.angle = this.angle - save.speed = this.speed - return save + return Math.pow(arguments[1].x - arguments[0].x, 2) + Math.pow(arguments[1].y - arguments[0].y, 2) + } + else + { + return Math.pow(arguments[2] - arguments[0], 2) + Math.pow(arguments[3] - arguments[1], 2) } +} - load(load) +/** + * returns the closest cardinal (N, S, E, W) to the given angle (in radians) + * @param {number} angle + * @return {number} closest cardinal in radians + */ +function closestAngle(angle) +{ + var left = differenceAngles(angle, LEFT) + var right = differenceAngles(angle, RIGHT) + var up = differenceAngles(angle, UP) + var down = differenceAngles(angle, DOWN) + if (left <= right && left <= up && left <= down) + { + return LEFT + } + else if (right <= up && right <= down) + { + return RIGHT + } + else if (up <= down) + { + return UP + } + else { - super.load(load) - this.angle = load.angle - this.speed = load.speed + return DOWN } +} - get angle() +/** + * checks whether angles a1 and a2 are equal (after normalizing) + * @param {number} a1 + * @param {number} a2 + * @param {number} [wiggle] return true if the difference between the angles is <= wiggle + * @return {boolean} a1 === a2 + */ +function equals(a1, a2, wiggle) +{ + if (wiggle) + { + return differenceAngles(a1, a2) < wiggle + } + else { - return this._angle + return normalize(a1) === normalize(a2) } - set angle(value) +} + +/** + * return a text representation of the cardinal direction + * @param {number} angle + * @returns {string} UP, DOWN, LEFT, RIGHT, or NOT CARDINAL + */ +function explain(angle) +{ + switch (angle) { - this._angle = value - this.sin = Math.sin(this._angle) - this.cos = Math.cos(this._angle) + case UP: return 'UP' + case DOWN: return 'DOWN' + case LEFT: return 'LEFT' + case RIGHT: return 'RIGHT' + default: return 'NOT CARDINAL' } +} + +module.exports = { + UP: UP, + DOWN: DOWN, + LEFT: LEFT, + RIGHT: RIGHT, + NORTH: NORTH, + SOUTH: SOUTH, + WEST: WEST, + EAST: EAST, + PI_2: PI_2, + PI_QUARTER: PI_QUARTER, + PI_HALF: PI_HALF, + + toDegrees: toDegrees, + toRadians: toRadians, + isAngleBetween: isAngleBetween, + differenceAnglesSign: differenceAnglesSign, + differenceAngles: differenceAngles, + shortestAngle: shortestAngle, + normalize: normalize, + angleTwoPoints: angleTwoPoints, + distanceTwoPoints: distanceTwoPoints, + distanceTwoPointsSquared: distanceTwoPointsSquared, + closestAngle: closestAngle, + equals: equals, + explain: explain +} +},{}],23:[function(require,module,exports){ +// yy-color +// by David Figatner +// MIT License +// (c) YOPEY YOPEY LLC 2017 +// https://github.com/davidfig/color - calculate(elapsed) - { - this.object.x += this.cos * elapsed * this.speed - this.object.y += this.sin * elapsed * this.speed - } +var Random = require('yy-random') - reverse() - { - this.angle += Math.PI - } +/** + * converts a #FFFFFF to 0x123456 + * @param {string} color + * @return {string} + */ +function poundToHex(color) +{ + return '0x' + parseInt(color.substr(1)).toString(16) } -module.exports = angle -},{"./wait":24}],15:[function(require,module,exports){ -const Angle = require('yy-angle') -const wait = require('./wait') +/** + * converts a 0x123456 to #FFFFFF + * @param {string} color + * @return {string} + */ +function hexToPound(color) +{ + return '#' + color.substr(2) +} -/** Rotates an object to face the target */ -class face extends wait +/** + * converts a number to #FFFFFF + * @param {number} color + * @return {string} + */ +function valueToPound(color) { - /** - * @param {object} object - * @param {Point} target - * @param {number} speed in radians/millisecond - * @param {object} [options] @see {@link Wait} - * @param {boolean} [options.keepAlive] don't stop animation when complete - */ - constructor(object, target, speed, options) - { - options = options || {} - super(object, options) - this.type = 'Face' - this.target = target - if (options.load) - { - this.load(options.load) - } - else - { - this.speed = speed - } - } + return '#' + color.toString(16) +} - save() - { - if (this.options.cancel) - { - return null - } - const save = super.save() - save.speed = this.speed - save.keepAlive = this.options.keepAlive - return save - } +/** + * based on tinycolor + * https://github.com/bgrins/TinyColor + * BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE + * @param {string} color + * @returns {object} + */ +function hexToHsl (color) +{ + var rgb = this.hexToRgb(color), + r = rgb.r, + g = rgb.g, + b = rgb.b + var max = Math.max(r, g, b), + min = Math.min(r, g, b) + var h, s, l = (max + min) / 2 - load(load) + if (max === min) { - super.load(load) - this.speed = load.speed - this.options.keepAlive = load.keepAlive + h = s = 0 // achromatic } - - calculate(elapsed) + else { - var angle = Angle.angleTwoPoints(this.object.position, this.target) - var difference = Angle.differenceAngles(angle, this.object.rotation) - if (difference === 0) - { - this.emit('done', this.object) - if (!this.options.keepAlive) - { - return true - } - } - else + var d = max - min + s = l > 0.5 ? d / (2 - max - min) : d / (max + min) + switch (max) { - var sign = Angle.differenceAnglesSign(angle, this.object.rotation) - var change = this.speed * elapsed - var delta = (change > difference) ? difference : change - this.object.rotation += delta * sign + case r: h = (g - b) / d + (g < b ? 6 : 0); break + case g: h = (b - r) / d + 2; break + case b: h = (r - g) / d + 4; break } + + h /= 6 } -} -module.exports = face -},{"./wait":24,"yy-angle":11}],16:[function(require,module,exports){ -const Ease = { - list: require('./list'), - wait: require('./wait'), - to: require('./to'), - shake: require('./shake'), - tint: require('./tint'), - face: require('./face'), - angle: require('./angle'), - target: require('./target'), - movie: require('./movie'), - load: require('./load') + return { h: h, s: s, l: l } } -PIXI.extras.Ease = Ease - -module.exports = Ease -},{"./angle":14,"./face":15,"./list":17,"./load":18,"./movie":19,"./shake":20,"./target":21,"./tint":22,"./to":23,"./wait":24}],17:[function(require,module,exports){ -const Events = require('eventemitter3') - -const Angle = require('./angle') -const Face = require('./face') -const Load = require('./load') -const Movie = require('./movie') -const Shake = require('./shake') -const Target = require('./target') -const Tint = require('./tint') -const To = require('./to') -const Wait = require('./wait') - -class Ease extends Events +/** based on tinycolor +* https://github.com/bgrins/TinyColor +* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE +* @param {object|number} color {h, s, b} or h +* @param {number} [s] +* @param {number} [l] +* @returns number +*/ +function hslToHex(color) { - /** - * Main class for creating eases - * @param {object} [options] - * @param {boolean} [options.noTicker] don't add the update function to PIXI.ticker - * @param {PIXI.ticker} [options.ticker=PIXI.ticker.shared] use this PIXI.ticker for the list - * @extends eventemitter - * @fire done - * @fire each - */ - constructor(options) - { - options = options || {} - super() - if (!options.noTicker) - { - const ticker = options.ticker || PIXI.ticker.shared - ticker.add(() => this.update(ticker.elapsedMS)) - } - this.list = [] - this.empty = true - this.removeWaiting = [] - this.removeAllWaiting = false - } - - /** - * Add animation(s) to animation list - * @param {(object|object[])} any animation class - * @return {object} first animation - */ - add() - { - let first - for (let arg of arguments) - { - if (Array.isArray(arg)) - { - for (let entry of arg) - { - if (!first) - { - first = entry - } - this.list.push(entry) - } - } - else - { - first = arg - this.list.push(arg) - } - } - this.empty = false - return first - } - - /** - * remove animation(s) - * @param {object|array} animate - the animation (or array of animations) to remove; can be null - */ - remove(animate) + var r, g, b, h, s, l + if (arguments.length === 1) { - if (this.inUpdate) - { - this.removeWaiting.push(animate) - } - else - { - const index = this.list.indexOf(animate) - if (index !== -1) - { - this.list.splice(index, 1) - } - } + h = color.h, + s = color.s, + l = color.l } - - /** - * remove all animations from list - * @inherited from yy-loop - */ - removeAll() + else { - if (this.inUpdate) - { - this.removeAllWaiting = true - } - else - { - this.list = [] - } + h = arguments[0] + s = arguments[1] + l = arguments[2] } - /** - * update frame - * this is automatically added to PIXI.ticker unless options.noTicker is set - * if using options.noTicker, this should be called manually - * @param {number} elasped time in MS since last update - */ - update(elapsed) - { - this.inUpdate = true - for (let i = 0, _i = this.list.length; i < _i; i++) - { - if (this.list[i] && this.list[i].update(elapsed)) - { - this.list.splice(i, 1) - i-- - _i-- - } - } - this.emit('each', this) - if (this.list.length === 0 && !this.empty) - { - this.emit('done', this) - this.empty = true - } - this.inUpdate = false - if (this.removeAllWaiting) - { - this.removeAll() - this.removeAllWaiting = false - } - while (this.removeWaiting.length) - { - this.remove(this.removeWaiting.pop()) - } + function hue2rgb(p, q, t) { + if (t < 0) t += 1 + if (t > 1) t -= 1 + if (t < 1/6) return p + (q - p) * 6 * t + if (t < 1/2) return q + if (t < 2/3) return p + (q - p) * (2/3 - t) * 6 + return p } - /** - * number of animations - * @type {number} - */ - get count() + if (s === 0) { - return this.list.length + r = g = b = l // achromatic } - - /** - * number of active animations - * @type {number} - */ - get countRunning() + else { - let count = 0 - for (let entry of this.list) - { - if (!entry.pause) - { - count++ - } - } - return count + var q = l < 0.5 ? l * (1 + s) : l + s - l * s + var p = 2 * l - q + r = hue2rgb(p, q, h + 1/3) + g = hue2rgb(p, q, h) + b = hue2rgb(p, q, h - 1/3) } - /** - * default options for all eases - * @typedef {object} EaseOptions - * @param {object} [EaseOptions.options] - * @param {number} [EaseOptions.options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [EaseOptions.options.pause] start the animation paused - * @param {boolean|number} [EaseOptions.options.repeat] true: repeat animation forever n: repeat animation n times - * @param {boolean|number} [EaseOptions.options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * @param {Function} [EaseOptions.options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set - * @param {string|Function} [EaseOptions.options.ease] name or function from easing.js (see http://easings.net for examples) - */ - - /** - * ease parameters of object - * @param {PIXI.DisplayObject} object to animate - * @param {object} goto - parameters to animate, e.g.: {alpha: 5, scale: {3, 5}, scale: 5, rotation: Math.PI} - * @param {number} duration - time to run - * @fires done - * @fires wait - * @fires first - * @fires each - * @fires loop - * @fires reverse - */ - to() { return this.add(new To(...arguments)) } - - /** - * animate object's {x, y} using an angle - * @param {object} object to animate - * @param {number} angle in radians - * @param {number} speed in pixels/millisecond - * @param {number} [duration=0] in milliseconds; if 0, then continues forever - * @param {object} [options] @see {@link Wait} - */ - angle() { return this.add(new Angle(...arguments)) } - - /** helper to add to the list a new Ease.face class; see Ease.to class below for parameters */ - face() { return this.add(new Face(...arguments)) } - - /** helper to add to the list a new Ease.load class; see Ease.to class below for parameters */ - load() { return this.add(new Load(...arguments)) } - - /** helper to add to the list a new Ease.movie class; see Ease.to class below for parameters */ - movie() { return this.add(new Movie(...arguments)) } + return this.rgbToHex(r * 255, g * 255, b * 255) +} - /** helper to add to the list a new Ease.shake class; see Ease.to class below for parameters */ - shake() { return this.add(new Shake(...arguments)) } +/* darkens a color by the percentage +* @param {object} color in hex (0xabcdef) +* @param {number} amount +* @return {number} +*/ +function darken(color, amount) +{ + return this.blend(amount, color, 0) +} - /** helper to add to the list a new Ease.target class; see Ease.to class below for parameters */ - target() { return this.add(new Target(...arguments)) } +/** based on tinycolor +* https://github.com/bgrins/TinyColor +* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE +* @param {object} color +* @param {number} amount +*/ +function saturate(color, amount) +{ + amount = (amount === 0) ? 0 : (amount || 10) + var hsl = this.hexToHsl(color) + hsl.s += amount / 100 + hsl.s = Math.min(1, Math.max(0, hsl.s)) + return this.hslToHex(hsl) +} - /** helper to add to the list a new Ease.angle tint; see Ease.to class below for parameters */ - tint() { return this.add(new Tint(...arguments)) } +/** based on tinycolor +* https://github.com/bgrins/TinyColor +* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE +* @param {object} color +* @param {number} amount +*/ +function desaturate(color, amount) +{ + amount = (amount === 0) ? 0 : (amount || 10) + var hsl = this.hexToHsl(color) + hsl.s -= amount / 100 + hsl.s = Math.min(1, Math.max(0, hsl.s)) + return this.hslToHex(hsl) +} - /** helper to add to the list a new Ease.wait class; see Ease.to class below for parameters */ - wait() { return this.add(new Wait(...arguments)) } +/** + * blends two colors together + * @param {number} percent [0.0 - 1.0] + * @param {string} color1 first color in 0x123456 format + * @param {string} color2 second color in 0x123456 format + * @return {number} + */ +function blend(percent, color1, color2) +{ + if (percent === 0) + { + return color1 + } + if (percent === 1) + { + return color2 + } + var r1 = color1 >> 16 + var g1 = color1 >> 8 & 0x0000ff + var b1 = color1 & 0x0000ff + var r2 = color2 >> 16 + var g2 = color2 >> 8 & 0x0000ff + var b2 = color2 & 0x0000ff + var percent1 = 1 - percent + var r = percent1 * r1 + percent * r2 + var g = percent1 * g1 + percent * g2 + var b = percent1 * b1 + percent * b2 + return r << 16 | g << 8 | b } -module.exports = Ease -},{"./angle":14,"./face":15,"./load":18,"./movie":19,"./shake":20,"./target":21,"./tint":22,"./to":23,"./wait":24,"eventemitter3":1}],18:[function(require,module,exports){ -const wait = require('./wait') -const to = require('./to') -const tint = require('./tint') -const shake = require('./shake') -const angle = require('./angle') -const face = require('./face') -const target = require('./target') -const movie = require('./movie') - /** - * restart an animation = requires a saved state - * @param {object} object(s) to animate + * returns a hex color into an rgb value + * @param {number} hex + * @return {string} */ -function load(object, load) +function hexToRgb(hex) { - if (!load) + if (hex === 0) { - return null + hex = '0x000000' } - const options = { load } - switch (load.type) + else if (typeof hex !== 'string') { - case 'Wait': - return new wait(object, options) - case 'To': - return new to(object, null, null, options) - case 'Tint': - return new tint(object, null, null, options) - case 'Shake': - return new shake(object, null, null, options) - case 'Angle': - return new angle(object, null, null, null, options) - case 'Face': - return new face(object[0], object[1], null, options) - case 'Target': - return new target(object[0], object[1], null, options) - case 'Movie': - return new movie(object, object[1], null, options) + var s = '000000' + hex.toString(16) + hex = '0x' + s.substr(s.length - 6) } + var result = /^0x?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) + return result ? { + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null } -module.exports = load -},{"./angle":14,"./face":15,"./movie":19,"./shake":20,"./target":21,"./tint":22,"./to":23,"./wait":24}],19:[function(require,module,exports){ -const wait = require('./wait') - /** - * animate a movie of textures + * rgb color to hex in the form of 0x123456 + * @param {(number|string)} r first number or 'rgb(...)' string + * @param {(number|null)} g + * @param {(number|null)} b + * @return {string} */ -class movie extends wait +function rgbToHex(r, g, b) { - /** - * @param {object} object to animate - * @param {PIXI.Texture[]} textures - * @param {number} [duration=0] time to run (use 0 for infinite duration--should only be used with customized easing functions) - * @param {object} [options] - * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [options.pause] start the animation paused - * @param {(boolean|number)} [options.repeat] true: repeat animation forever n: repeat animation n times - * @param {(boolean|number)} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * @param {(boolean|number)} [options.continue] true: continue animation with new starting values n: continue animation n times - * @param {Function} [options.load] loads an animation using a .save() object note the * parameters below cannot be loaded and must be re-set - * @param {Function} [options.ease] function from easing.js (see http://easings.net for examples) - * @emits {done} animation expires - * @emits {wait} each update during a wait - * @emits {first} first update when animation starts - * @emits {each} each update while animation is running - * @emits {loop} when animation is repeated - * @emits {reverse} when animation is reversed - */ - constructor(object, textures, duration, options) - { - options = options || {} - super(object, options) - this.type = 'Movie' - if (Array.isArray(object)) - { - this.list = object - this.object = this.list[0] - } - if (options.load) - { - this.load(options.load) - } - else - { - this.textures = textures - this.duration = duration - this.current = 0 - this.length = textures.length - this.interval = duration / this.length - this.isReverse = false - this.restart() + if (arguments.length === 1) { + if (Array.isArray(arguments[0])) { + var number = arguments[0] + r = number[0] + g = number[1] + b = number[2] + } else { + var parse = r.replace(/( *rgb *\( *)|( )|(\) *;?)/,'') + var numbers = parse.split(',') + r = numbers[0] + g = numbers[1] + b = numbers[2] } } + return '0x' + ((1 << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b)).toString(16).slice(1) +} - save() +/** + * returns a random color with balanced r, g, b values (i.e., r, g, b either have the same value or are 0) + * @param {number} min value for random number + * @param {number} max value for random number + * @return {number} color + */ +function random(min, max) +{ + function random() { - const save = super.save() - save.goto = this.goto - save.current = this.current - save.length = this.length - save.interval = this.interval - return save + return Random.range(min, max) } - load(load) - { - super.load(load) - this.goto = load.goto - this.current = load.current - this.interval = load.current - } + var colors = [{r:1, g:1, b:1}, {r:1, g:1, b:0}, {r:1,g:0,b:1}, {r:0,g:1,b:1}, {r:1,g:0,b:0}, {r:0,g:1,b:0}, {r:0,g:0,b:1}] + var color = Random.pick(colors) + min = min || 0 + max = max || 255 + return this.rgbToHex(color.r ? random() : 0, color.g ? random() : 0, color.b ? random() : 0) +} - restart() - { - this.current = 0 - this.time = 0 - this.isReverse = false +// h: 0-360, s: 0-1, l: 0-1 +/** + * returns a random color based on hsl + * @param {number} hMin [0, 360] + * @param {number} hMax [hMin, 360] + * @param {number} sMin [0, 1] + * @param {number} sMax [sMin, 1] + * @param {number} lMin [0, 1] + * @param {number} lMax [lMin, 1] + */ +function randomHSL(hMin, hMax, sMin, sMax, lMin, lMax) +{ + var color = { + h: Random.range(hMin, hMax), + s: Random.range(sMin, sMax, true), + l: Random.range(lMin, lMax, true) } + return this.hslToHex(color) +} - reverse() +/** + * returns random colors based on HSL with different hues + * based on http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ + * @returns {number[]} colors in hex format (0x123456) + */ +function randomGoldenRatioHSL(count, saturation, luminosity) +{ + var goldenRatio = 0.618033988749895 + var h = Random.get(1, true) + var colors = [] + for (var i = 0; i < count; i++) { - this.isReverse = !this.isReverse + colors.push(this.hslToHex(h, saturation, luminosity)) + h = (h + goldenRatio) % 1 } + return colors +} - calculate() - { - let index = Math.round(this.options.ease(this.time, 0, this.length - 1, this.duration)) - if (this.isReverse) - { - index = this.length - 1 - index - } - if (this.list) - { - for (let i = 0; i < this.list.length; i++) - { - this.list[i].texture = this.textures[index] - } - } - else - { - this.object.texture = this.textures[index] - } - } +module.exports = { + poundToHex: poundToHex, + hexToPound: hexToPound, + valueToPound: valueToPound, + hexToHsl: hexToHsl, + hslToHex: hslToHex, + hexToRgb: hexToRgb, + rgbToHex: rgbToHex, + darken: darken, + saturate: saturate, + desaturate: desaturate, + blend: blend, + random: random, + randomHSL: randomHSL, + randomGoldenRatioHSL: randomGoldenRatioHSL } +},{"yy-random":24}],24:[function(require,module,exports){ +'use strict'; -module.exports = movie -},{"./wait":24}],20:[function(require,module,exports){ -const wait = require('./wait') +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +// yy-random +// by David Figatner +// MIT license +// copyright YOPEY YOPEY LLC 2016-17 +// https://github.com/davidfig/random + +var seedrandom = require('seedrandom'); + +var Random = function () { + function Random() { + _classCallCheck(this, Random); + + this.generator = Math.random; + } -/** - * shakes an object or list of objects - */ -class shake extends wait -{ /** - * @param {object|array} object or list of objects to shake - * @param {number} amount to shake - * @param {number} duration (in milliseconds) to shake - * @param {object} options (see Animate.wait) + * generates a seeded number + * @param {number} seed + * @param {object} [options] + * @param {string} [PRNG="alea"] - name of algorithm, see https://github.com/davidbau/seedrandom + * @param {boolean} [save=true] */ - constructor(object, amount, duration, options) - { - options = options || {} - super(object, options) - this.type = 'Shake' - if (Array.isArray(object)) - { - this.array = true - this.list = object - } - if (options.load) - { - this.load(options.load) + + + _createClass(Random, [{ + key: 'seed', + value: function seed(_seed, options) { + options = options || {}; + this.generator = seedrandom[options.PRNG || 'alea'](_seed, { state: options.state }); + this.options = options; } - else - { - if (this.list) - { - this.start = [] - for (let i = 0; i < object.length; i++) - { - const target = object[i] - this.start[i] = {x: target.x, y: target.y} - } - } - else - { - this.start = {x: object.x, y: object.y} + + /** + * saves the state of the random generator + * can only be used after Random.seed() is called + * @returns {number} state + */ + + }, { + key: 'save', + value: function save() { + if (this.generator !== Math.random) { + return this.generator.state(); } - this.amount = amount - this.duration = duration } - } - save() - { - const save = super.save() - save.start = this.start - save.amount = this.amount - return save - } + /** + * restores the state of the random generator + * @param {number} state + */ - load(load) - { - super.load(load) - this.start = load.start - this.amount = load.amount - } + }, { + key: 'restore', + value: function restore(state) { + this.generator = seedrandom[this.options.PRNG || 'alea']('', { state: state }); + } - calculate(/*elapsed*/) - { - const object = this.object - const start = this.start - const amount = this.amount - if (this.array) - { - const list = this.list - for (let i = 0; i < list.length; i++) - { - const object = list[i] - const actual = start[i] - object.x = actual.x + Math.floor(Math.random() * amount * 2) - amount - object.y = actual.y + Math.floor(Math.random() * amount * 2) - amount - } + /** + * changes the generator to use the old Math.sin-based random function + * based on : http://stackoverflow.com/questions/521295/javascript-random-seeds + * (deprecated) Use only for compatibility purposes + * @param {number} seed + */ + + }, { + key: 'seedOld', + value: function seedOld(seed) { + this.generator = function () { + var x = Math.sin(seed++) * 10000; + return x - Math.floor(x); + }; } - object.x = start.x + Math.floor(Math.random() * amount * 2) - amount - object.y = start.y + Math.floor(Math.random() * amount * 2) - amount - } - done() - { - const object = this.object - const start = this.start - if (this.array) - { - const list = this.list - for (let i = 0; i < list.length; i++) - { - const object = list[i] - const actual = start[i] - object.x = actual.x - object.y = actual.y - } - } - else - { - object.x = start.x - object.y = start.y + /** + * create a separate random generator using the seed + * @param {number} seed + * @return {object} + */ + + }, { + key: 'separateSeed', + value: function separateSeed(seed) { + var random = new Random(); + random.seed(seed); + return random; } - } -} -module.exports = shake -},{"./wait":24}],21:[function(require,module,exports){ -const wait = require('./wait') + /** + * resets the random number this.generator to Math.random() + */ -/** move an object to a target's location */ -class target extends wait -{ - /** - * move to a target - * @param {object} object - object to animate - * @param {object} target - object needs to contain {x: x, y: y} - * @param {number} speed - number of pixels to move per millisecond - * @param {object} [options] @see {@link Wait} - * @param {boolean} [options.keepAlive] don't cancel the animation when target is reached - */ - constructor(object, target, speed, options) - { - options = options || {} - super(object, options) - this.type = 'Target' - this.target = target - if (options.load) - { - this.load(options.load) - } - else - { - this.speed = speed + }, { + key: 'reset', + value: function reset() { + this.generator = Math.random; } - } - save() - { - const save = super.save() - save.speed = this.speed - save.keepAlive = this.options.keepAlive - return save - } - - load(load) - { - super.load(load) - this.speed = load.speed - this.options.keepAlive = load.keepAlive - } + /** + * returns a random number using the this.generator between [0, ceiling - 1] + * @param {number} ceiling + * @param {boolean} [useFloat=false] + * @return {number} + */ - calculate(elapsed) - { - const deltaX = this.target.x - this.object.x - const deltaY = this.target.y - this.object.y - if (deltaX === 0 && deltaY === 0) - { - this.emit('done', this.object) - if (!this.options.keepAlive) - { - return true - } - } - else - { - const angle = Math.atan2(deltaY, deltaX) - this.object.x += Math.cos(angle) * elapsed * this.speed - this.object.y += Math.sin(angle) * elapsed * this.speed - if ((deltaX >= 0) !== ((this.target.x - this.object.x) >= 0)) - { - this.object.x = this.target.x - } - if ((deltaY >= 0) !== ((this.target.y - this.object.y) >= 0)) - { - this.object.y = this.target.y + }, { + key: 'get', + value: function get(ceiling, useFloat) { + var negative = ceiling < 0 ? -1 : 1; + ceiling *= negative; + var result = void 0; + if (useFloat) { + result = this.generator() * ceiling; + } else { + result = Math.floor(this.generator() * ceiling); } + return result * negative; } - } -} -module.exports = target -},{"./wait":24}],22:[function(require,module,exports){ -const Color = require('yy-color') -const wait = require('./wait') + /** + * returns a random integer between 0 - Number.MAX_SAFE_INTEGER + * @return {number} + */ -class tint extends wait -{ - /** - * @param {PIXI.DisplayObject|PIXI.DisplayObject[]} object - * @param {number|number[]} tint - * @param {number} [duration] in milliseconds - * @param {object} [options] @see {@link Wait} - */ - constructor(object, tint, duration, options) - { - options = options || {} - super(object, options) - this.type = 'Tint' - if (Array.isArray(object)) - { - this.list = object - this.object = this.list[0] - } - this.duration = duration - if (options.load) - { - this.load(options.load) - } - else if (Array.isArray(tint)) - { - this.tints = [this.object.tint, ...tint] + }, { + key: 'getHuge', + value: function getHuge() { + return this.get(Number.MAX_SAFE_INTEGER); } - else - { - this.start = this.object.tint - this.to = tint + + /** + * random number [middle - range, middle + range] + * @param {number} middle + * @param {number} delta + * @param {boolean} [useFloat=false] + * @return {number} + */ + + }, { + key: 'middle', + value: function middle(_middle, delta, useFloat) { + var half = delta / 2; + return this.range(_middle - half, _middle + half, useFloat); } - } - save() - { - const save = super.save() - save.start = this.start - save.to = this.to - return save - } + /** + * random number [start, end] + * @param {number} start + * @param {number} end + * @param {boolean} [useFloat=false] if true, then range is (start, end)--i.e., not inclusive to start and end + * @return {number} + */ - load(load) - { - super.load(load) - this.start = load.start - this.to = load.to - } + }, { + key: 'range', + value: function range(start, end, useFloat) { + // case where there is no range + if (end === start) { + return end; + } - calculate() - { - const percent = this.options.ease(this.time, 0, 1, this.duration) - if (this.tints) - { - const each = 1 / (this.tints.length - 1) - let per = each - for (let i = 1; i < this.tints.length; i++) - { - if (percent <= per) - { - const color = Color.blend(1 - (per - percent) / each, this.tints[i - 1], this.tints[i]) - if (this.list) - { - for (let object of this.list) - { - object.tint = color - } - } - else - { - this.object.tint = color - } - break; + if (useFloat) { + return this.get(end - start, true) + start; + } else { + var range = void 0; + if (start < 0 && end > 0) { + range = -start + end + 1; + } else if (start === 0 && end > 0) { + range = end + 1; + } else if (start < 0 && end === 0) { + range = start - 1; + start = 1; + } else if (start < 0 && end < 0) { + range = end - start - 1; + } else { + range = end - start + 1; } - per += each + return Math.floor(this.generator() * range) + start; } } - else - { - const color = Color.blend(percent, this.start, this.to) - if (this.list) - { - for (let object of this.list) - { - object.tint = color - } - } - else - { - this.object.tint = color + + /** + * an array of random numbers between [start, end] + * @param {number} start + * @param {number} end + * @param {number} count + * @param {boolean} [useFloat=false] + * @return {number[]} + */ + + }, { + key: 'rangeMultiple', + value: function rangeMultiple(start, end, count, useFloat) { + var array = []; + for (var i = 0; i < count; i++) { + array.push(this.range(start, end, useFloat)); } + return array; } - } - reverse() - { - if (this.tints) - { - const tints = [] - for (let i = this.tints.length - 1; i >= 0; i--) - { - tints.push(this.tints[i]) + /** + * an array of random numbers between [middle - range, middle + range] + * @param {number} middle + * @param {number} range + * @param {number} count + * @param {boolean} [useFloat=false] + * @return {number[]} + */ + + }, { + key: 'middleMultiple', + value: function middleMultiple(middle, range, count, useFloat) { + var array = []; + for (var i = 0; i < count; i++) { + array.push(middle(middle, range, useFloat)); } - this.tints = tints - } - else - { - const swap = this.to - this.to = this.start - this.start = swap + return array; } - } -} -module.exports = tint -},{"./wait":24,"yy-color":12}],23:[function(require,module,exports){ -const wait = require('./wait') + /** + * @param {number} [chance=0.5] + * returns random sign (either +1 or -1) + * @return {number} + */ -/** animate any numeric parameter of an object or array of objects */ -class to extends wait -{ - /** - * @private - * @param {object} object to animate - * @param {object} goto - parameters to animate, e.g.: {alpha: 5, scale: {3, 5}, scale: 5, rotation: Math.PI} - * @param {number} duration - time to run - * @param {object} [options] - * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [options.pause] start the animation paused - * @param {boolean|number} [options.repeat] true: repeat animation forever n: repeat animation n times - * @param {boolean|number} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * @param {Function} [options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set - * @param {string|Function} [options.ease] name or function from easing.js (see http://easings.net for examples) - * @emits to:done animation expires - * @emits to:wait each update during a wait - * @emits to:first first update when animation starts - * @emits to:each each update while animation is running - * @emits to:loop when animation is repeated - * @emits to:reverse when animation is reversed - */ - constructor(object, goto, duration, options) - { - options = options || {} - super(object, options) - this.type = 'To' - if (Array.isArray(object)) - { - this.list = object - this.object = this.list[0] - } - if (options.load) - { - this.load(options.load) + }, { + key: 'sign', + value: function sign(chance) { + chance = chance || 0.5; + return this.generator() < chance ? 1 : -1; } - else - { - this.goto = goto - this.fixScale() - this.duration = duration - this.restart() + + /** + * tells you whether a random chance was achieved + * @param {number} [percent=0.5] + * @return {boolean} + */ + + }, { + key: 'chance', + value: function chance(percent) { + return this.generator() < (percent || 0.5); } - } - /** - * converts scale from { scale: n } to { scale: { x: n, y: n }} - * @private - */ - fixScale() - { - if (typeof this.goto['scale'] !== 'undefined' && !Number.isNaN(this.goto['scale'])) - { - this.goto['scale'] = {x: this.goto['scale'], y: this.goto['scale']} + /** + * returns a random angle in radians [0 - 2 * Math.PI) + */ + + }, { + key: 'angle', + value: function angle() { + return this.get(Math.PI * 2, true); } - } - save() - { - const save = super.save() - save.goto = this.goto - save.start = this.start - save.delta = this.delta - save.keys = this.keys - return save - } + /** + * Shuffle array (either in place or copied) + * from http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array + * @param {Array} array + * @param {boolean} [copy=false] whether to shuffle in place (default) or return a new shuffled array + * @return {Array} a shuffled array + */ - load(load) - { - super.load(load) - this.goto = load.goto - this.start = load.start - this.delta = load.delta - this.keys = load.keys - } + }, { + key: 'shuffle', + value: function shuffle(array, copy) { + if (copy) { + array = array.slice(); + } + if (array.length === 0) { + return array; + } - restart() - { - let i = 0 - const start = this.start = [] - const delta = this.delta = [] - const keys = this.keys = [] - const goto = this.goto - const object = this.object - - // loops through all keys in goto object - for (let key in goto) - { + var currentIndex = array.length, + temporaryValue = void 0, + randomIndex = void 0; - // handles keys with one additional level e.g.: goto = {scale: {x: 5, y: 3}} - if (isNaN(goto[key])) - { - keys[i] = { key: key, children: [] } - start[i] = [] - delta[i] = [] - let j = 0 - for (let key2 in goto[key]) - { - keys[i].children[j] = key2 - start[i][j] = parseFloat(object[key][key2]) - start[i][j] = this._correctDOM(key2, start[i][j]) - start[i][j] = isNaN(this.start[i][j]) ? 0 : start[i][j] - delta[i][j] = goto[key][key2] - start[i][j] - j++ - } - } - else - { - start[i] = parseFloat(object[key]) - start[i] = this._correctDOM(key, start[i]) - start[i] = isNaN(this.start[i]) ? 0 : start[i] - delta[i] = goto[key] - start[i] - keys[i] = key + // While there remain elements to shuffle... + while (0 !== currentIndex) { + // Pick a remaining element... + randomIndex = this.get(currentIndex); + currentIndex -= 1; + + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; } - i++ + return array; } - this.time = 0 - } - reverse() - { - const object = this.object - const keys = this.keys - const goto = this.goto - const delta = this.delta - const start = this.start + /** + * picks a random element from an array + * @param {Array} array + * @return {*} + */ - for (let i = 0, _i = keys.length; i < _i; i++) - { - const key = keys[i] - if (isNaN(goto[key])) - { - for (let j = 0, _j = key.children.length; j < _j; j++) - { - delta[i][j] = -delta[i][j] - start[i][j] = parseFloat(object[key.key][key.children[j]]) - start[i][j] = isNaN(start[i][j]) ? 0 : start[i][j] - } - } - else - { - delta[i] = -delta[i] - start[i] = parseFloat(object[key]) - start[i] = isNaN(start[i]) ? 0 : start[i] + }, { + key: 'pick', + value: function pick(array, remove) { + if (!remove) { + return array[this.get(array.length)]; + } else { + var pick = this.get(array.length); + var temp = array[pick]; + array.splice(pick, 1); + return temp; } } - } - calculate(/*elapsed*/) - { - const object = this.object - const list = this.list - const keys = this.keys - const goto = this.goto - const time = this.time - const start = this.start - const delta = this.delta - const duration = this.duration - const ease = this.options.ease - for (let i = 0, _i = this.keys.length; i < _i; i++) - { - const key = keys[i] - if (isNaN(goto[key])) - { - const key1 = key.key - for (let j = 0, _j = key.children.length; j < _j; j++) - { - const key2 = key.children[j] - const others = object[key1][key2] = (time >= duration) ? start[i][j] + delta[i][j] : ease(time, start[i][j], delta[i][j], duration) - if (list) - { - for (let k = 1, _k = list.length; k < _k; k++) - { - list[k][key1][key2] = others - } - } - } - } - else - { - const key = keys[i] - const others = object[key] = (time >= duration) ? start[i] + delta[i] : ease(time, start[i], delta[i], duration) - if (list) - { - for (let j = 1, _j = this.list.length; j < _j; j++) - { - list[j][key] = others - } + /** + * returns a random property from an object + * from http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object + * @param {object} obj + * @return {*} + */ + + }, { + key: 'property', + value: function property(obj) { + var result; + var count = 0; + for (var prop in obj) { + if (this.chance(1 / ++count)) { + result = prop; } } + return result; } - } -} -module.exports = to -},{"./wait":24}],24:[function(require,module,exports){ -const Easing = require('penner') -const EventEmitter = require('eventemitter3') - -class wait extends EventEmitter -{ - /** - * @param {object|object[]} object or list of objects to animate - * @param {object} [options] - * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [options.pause] start the animation paused - * @param {(boolean|number)} [options.repeat] true: repeat animation forever n: repeat animation n times - * @param {(boolean|number)} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * - * @param {number} [options.id] user-generated id (e.g., I use it to properly load animations when an object has multiple animations running) - * @param {Function} [options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set - * @param {Function|string} [options.ease] function (or penner function name) from easing.js (see http://easings.net for examples)* - * - * @emits {done} animation expires - * @emits {wait} each update during a wait - * @emits {first} first update when animation starts - * @emits {each} each update while animation is running - * @emits {loop} when animation is repeated - * @emits {reverse} when animation is reversed - */ - constructor(object, options) - { - super() - this.object = object - this.options = options || {} - this.type = 'Wait' - if (this.options.load) - { - this.load(this.options.load) - } - else - { - this.time = 0 - } - if (this.options.ease && typeof this.options.ease !== 'function') - { - this.options.easeName = this.options.ease - this.options.ease = Easing[this.options.ease] - } - if (!this.options.ease) - { - this.options.ease = Easing['linear'] - } - } + /** + * creates a random set where each entry is a value between [min, max] + * @param {number} min + * @param {number} max + * @param {number} amount of numbers in set + * @param {number[]} + */ - save() - { - const save = { type: this.type, time: this.time, duration: this.duration, ease: this.options.easeName } - const options = this.options - if (options.wait) - { - save.wait = options.wait - } - if (typeof options.id !== 'undefined') - { - save.id = options.id - } - if (options.pause) - { - save.pause = options.pause - } - if (options.repeat) - { - save.repeat = options.repeat - } - if (options.reverse) - { - save.reverse = options.reverse - } - return save - } + }, { + key: 'set', + value: function set(min, max, amount) { + var set = [], + all = [], + i; + for (i = min; i < max; i++) { + all.push(i); + } - load(load) - { - this.options.wait = load.wait - this.options.pause = load.pause - this.options.repeat = load.repeat - this.options.reverse = load.reverse - this.options.id = load.id - this.options.ease = load.ease - if (this.options.ease && typeof this.options.ease !== 'function') - { - this.options.easeName = this.options.ease - this.options.ease = Easing[this.options.ease] - } - if (!this.options.ease) - { - this.options.ease = Easing['linear'] + for (i = 0; i < amount; i++) { + var found = this.get(all.length); + set.push(all[found]); + all.splice(found, 1); + } + return set; } - this.time = load.time - this.duration = load.duration - } - /** - * pause this entry - * @type {boolean} - */ - set pause(value) - { - this.options.pause = value - } - get pause() - { - return this.options.pause - } + /** + * returns a set of numbers with a randomly even distribution (i.e., no overlapping and filling the space) + * @param {number} start position + * @param {number} end position + * @param {number} count of non-start/end points + * @param {boolean} [includeStart=false] includes start point (count++) + * @param {boolean} [includeEnd=false] includes end point (count++) + * @param {boolean} [useFloat=false] + * @param {number[]} + */ - end(leftOver) - { - if (this.options.reverse) - { - this.reverse() - this.time = leftOver - if (!this.options.repeat) - { - if (this.options.reverse === true) - { - this.options.reverse = false - } - else - { - this.options.reverse-- - } + }, { + key: 'distribution', + value: function distribution(start, end, count, includeStart, includeEnd, useFloat) { + var interval = Math.floor((end - start) / count); + var halfInterval = interval / 2; + var quarterInterval = interval / 4; + var set = []; + if (includeStart) { + set.push(start); } - else - { - if (this.options.repeat !== true) - { - this.options.repeat-- - } + for (var i = 0; i < count; i++) { + set.push(start + i * interval + halfInterval + this.range(-quarterInterval, quarterInterval, useFloat)); } - this.emit('loop', this.list || this.object) - } - else if (this.options.repeat) - { - this.time = leftOver - if (this.options.repeat !== true) - { - this.options.repeat-- + if (includeEnd) { + set.push(end); } - this.emit('loop', this.list || this.object) - } - else - { - this.done() - this.emit('done', this.list || this.object, leftOver) - // this.list = this.object = null - return true + return set; } - } - update(elapsed) - { - const options = this.options - if (options.pause) - { - return - } - if (options.wait) - { - options.wait -= elapsed - if (options.wait <= 0) - { - elapsed = -options.wait - options.wait = false + /** + * returns a random number based on weighted probability between [min, max] + * from http://stackoverflow.com/questions/22656126/javascript-random-number-with-weighted-probability + * @param {number} min value + * @param {number} max value + * @param {number} target for average value + * @param {number} stddev - standard deviation + */ + + }, { + key: 'weightedProbabilityInt', + value: function weightedProbabilityInt(min, max, target, stddev) { + function normRand() { + var x1 = void 0, + x2 = void 0, + rad = void 0; + do { + x1 = 2 * this.get(1, true) - 1; + x2 = 2 * this.get(1, true) - 1; + rad = x1 * x1 + x2 * x2; + } while (rad >= 1 || rad === 0); + var c = Math.sqrt(-2 * Math.log(rad) / rad); + return x1 * c; } - else - { - this.emit('wait', elapsed, this.list || this.object) - return + + stddev = stddev || 1; + if (Math.random() < 0.81546) { + while (true) { + var sample = normRand() * stddev + target; + if (sample >= min && sample <= max) { + return sample; + } + } + } else { + return this.range(min, max); } } - if (!this.first) - { - this.first = true - this.emit('first', this.list || this.object) - } - this.time += elapsed - let leftOver = 0 - const duration = this.duration - let time = this.time - if (duration !== 0 && time > duration) - { - leftOver = time - duration - this.time = time = duration - } - const force = this.calculate(elapsed) - this.emit('each', elapsed, this.list || this.object, this) - if (this.type === 'Wait' || (duration !== 0 && time === duration)) - { - return this.end(leftOver) - } - return force || time === duration - } - // correct certain DOM values - _correctDOM(key, value) - { - switch (key) - { - case 'opacity': - return (isNaN(value)) ? 1 : value + /* + * returns a random hex color (0 - 0xffffff) + * @return {number} + */ + + }, { + key: 'color', + value: function color() { + return this.get(0xffffff); } - return value - } + }]); - reverse() {} - calculate() { } - done() { } -} + return Random; +}(); + +module.exports = new Random(); -module.exports = wait -},{"eventemitter3":1,"penner":2}],25:[function(require,module,exports){ +},{"seedrandom":14}],25:[function(require,module,exports){ -},{}]},{},[16]); +},{}]},{},[3]); diff --git a/bundle/pixi-ease.min.js b/bundle/pixi-ease.min.js new file mode 100644 index 0000000..ff46e0a --- /dev/null +++ b/bundle/pixi-ease.min.js @@ -0,0 +1 @@ +!function i(a,s,u){function c(n,t){if(!s[n]){if(!a[n]){var e="function"==typeof require&&require;if(!t&&e)return e(n,!0);if(l)return l(n,!0);var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}var o=s[n]={exports:{}};a[n][0].call(o.exports,function(t){var e=a[n][1][t];return c(e||t)},o,o.exports,i,a,s,u)}return s[n].exports}for(var l="function"==typeof require&&require,t=0;t>>0,r=(n*=r)>>>0,r+=4294967296*(n-=r)}return 2.3283064365386963e-10*(r>>>0)});e.next=function(){var t=2091639*e.s0+2.3283064365386963e-10*e.c;return e.s0=e.s1,e.s1=e.s2,e.s2=t-(e.c=0|t)},e.c=1,e.s0=n(" "),e.s1=n(" "),e.s2=n(" "),e.s0-=n(t),e.s0<0&&(e.s0+=1),e.s1-=n(t),e.s1<0&&(e.s1+=1),e.s2-=n(t),e.s2<0&&(e.s2+=1),n=null}function a(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function r(t,e){var n=new i(t),r=e&&e.state,o=n.next;return o.int32=function(){return 4294967296*n.next()|0},o.double=function(){return o()+11102230246251565e-32*(2097152*o()|0)},o.quick=o,r&&("object"==typeof r&&a(r,n),o.state=function(){return a(n,{})}),o}e&&e.exports?e.exports=r:n&&n.amd?n(function(){return r}):this.alea=r}(0,"object"==typeof e&&e,"function"==typeof define&&define)},{}],16:[function(t,e,n){!function(t,e,n){function i(t){var o=this,e="";o.next=function(){var t=o.b,e=o.c,n=o.d,r=o.a;return t=t<<25^t>>>7^e,e=e-n|0,n=n<<24^n>>>8^r,r=r-t|0,o.b=t=t<<20^t>>>12^e,o.c=e=e-n|0,o.d=n<<16^e>>>16^r,o.a=r-t|0},o.a=0,o.b=0,o.c=-1640531527,o.d=1367130551,t===Math.floor(t)?(o.a=t/4294967296|0,o.b=0|t):e+=t;for(var n=0;n>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&("object"==typeof r&&a(r,n),o.state=function(){return a(n,{})}),o}e&&e.exports?e.exports=r:n&&n.amd?n(function(){return r}):this.tychei=r}(0,"object"==typeof e&&e,"function"==typeof define&&define)},{}],17:[function(t,e,n){!function(t,e,n){function i(t){var e=this,n="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:n+=t;for(var r=0;r>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&("object"==typeof r&&a(r,n),o.state=function(){return a(n,{})}),o}e&&e.exports?e.exports=r:n&&n.amd?n(function(){return r}):this.xor128=r}(0,"object"==typeof e&&e,"function"==typeof define&&define)},{}],18:[function(t,e,n){!function(t,e,n){function i(t){var i=this;i.next=function(){var t,e,n=i.w,r=i.X,o=i.i;return i.w=n=n+1640531527|0,e=r[o+34&127],t=r[o=o+1&127],e^=e<<13,t^=t<<17,e^=e>>>15,t^=t>>>12,e=r[o]=e^t,i.i=o,e+(n^n>>>16)|0},function(t,e){var n,r,o,i,a,s=[],u=128;for(e===(0|e)?(r=e,e=null):(e+="\0",r=0,u=Math.max(u,e.length)),o=0,i=-32;i>>15,r^=r<<4,r^=r>>>13,0<=i&&(a=a+1640531527|0,o=0==(n=s[127&i]^=r+a)?o+1:0);for(128<=o&&(s[127&(e&&e.length||0)]=-1),o=127,i=512;0>>15,n^=n>>>12,s[o]=r^n;t.w=a,t.X=s,t.i=o}(i,t)}function a(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function r(t,e){null==t&&(t=+new Date);var n=new i(t),r=e&&e.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&(r.X&&a(r,n),o.state=function(){return a(n,{})}),o}e&&e.exports?e.exports=r:n&&n.amd?n(function(){return r}):this.xor4096=r}(0,"object"==typeof e&&e,"function"==typeof define&&define)},{}],19:[function(t,e,n){!function(t,e,n){function i(t){var o=this;o.next=function(){var t,e,n=o.x,r=o.i;return t=n[r],e=(t^=t>>>7)^t<<24,e^=(t=n[r+1&7])^t>>>10,e^=(t=n[r+3&7])^t>>>3,e^=(t=n[r+4&7])^t<<7,t=n[r+7&7],e^=(t^=t<<13)^t<<9,n[r]=e,o.i=r+1&7,e},function(t,e){var n,r=[];if(e===(0|e))r[0]=e;else for(e=""+e,n=0;n>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&(r.x&&a(r,n),o.state=function(){return a(n,{})}),o}e&&e.exports?e.exports=r:n&&n.amd?n(function(){return r}):this.xorshift7=r}(0,"object"==typeof e&&e,"function"==typeof define&&define)},{}],20:[function(t,e,n){!function(t,e,n){function i(t){var e=this,n="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,t===((e.v=0)|t)?e.x=t:n+=t;for(var r=0;r>>4),e.next()}function a(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function r(t,e){var n=new i(t),r=e&&e.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&("object"==typeof r&&a(r,n),o.state=function(){return a(n,{})}),o}e&&e.exports?e.exports=r:n&&n.amd?n(function(){return r}):this.xorwow=r}(0,"object"==typeof e&&e,"function"==typeof define&&define)},{}],21:[function(e,n,t){!function(s,u){var c,l=this,f=256,h=6,p="random",v=u.pow(f,h),y=u.pow(2,52),d=2*y,b=f-1;function t(t,e,n){var r=[],o=x(function t(e,n){var r,o=[],i=typeof e;if(n&&"object"==i)for(r in e)try{o.push(t(e[r],n-1))}catch(t){}return o.length?o:"string"==i?e:e+"\0"}((e=1==e?{entropy:!0}:e||{}).entropy?[t,O(s)]:null==t?function(){try{var t;return c&&(t=c.randomBytes)?t=t(f):(t=new Uint8Array(f),(l.crypto||l.msCrypto).getRandomValues(t)),O(t)}catch(t){var e=l.navigator,n=e&&e.plugins;return[+new Date,l,n,l.screen,O(s)]}}():t,3),r),i=new g(r),a=function(){for(var t=i.g(h),e=v,n=0;t>>=1;return(t+n)/e};return a.int32=function(){return 0|i.g(4)},a.quick=function(){return i.g(4)/4294967296},a.double=a,x(O(i.S),s),(e.pass||n||function(t,e,n,r){return r&&(r.S&&w(r,i),t.state=function(){return w(i,{})}),n?(u[p]=t,e):t})(a,o,"global"in e?e.global:this==u,e.state)}function g(t){var e,n=t.length,a=this,r=0,o=a.i=a.j=0,i=a.S=[];for(n||(t=[n++]);rMath.PI?f-n:n}function d(t){return t-f*Math.floor(t/f)}e.exports={UP:i,DOWN:a,LEFT:s,RIGHT:0,NORTH:u,SOUTH:c,WEST:l,EAST:0,PI_2:f,PI_QUARTER:h,PI_HALF:p,toDegrees:function(t){return t*r},toRadians:function(t){return t*o},isAngleBetween:function(t,e,n){if(((n-e)%f+f)%f>=Math.PI){var r=e;e=n,n=r}return e<=n?e<=t&&t<=n:e<=t||t<=n},differenceAnglesSign:v,differenceAngles:y,shortestAngle:function(t,e){return y(e,t)*v(e,t)+t},normalize:d,angleTwoPoints:function(){return 4===arguments.length?Math.atan2(arguments[3]-arguments[1],arguments[2]-arguments[0]):Math.atan2(arguments[1].y-arguments[0].y,arguments[1].x-arguments[0].x)},distanceTwoPoints:function(){return 2===arguments.length?Math.sqrt(Math.pow(arguments[1].x-arguments[0].x,2)+Math.pow(arguments[1].y-arguments[0].y,2)):Math.sqrt(Math.pow(arguments[2]-arguments[0],2)+Math.pow(arguments[3]-arguments[1],2))},distanceTwoPointsSquared:function(){return 2===arguments.length?Math.pow(arguments[1].x-arguments[0].x,2)+Math.pow(arguments[1].y-arguments[0].y,2):Math.pow(arguments[2]-arguments[0],2)+Math.pow(arguments[3]-arguments[1],2)},closestAngle:function(t){var e=y(t,s),n=y(t,0),r=y(t,i),o=y(t,a);return e<=n&&e<=r&&e<=o?s:n<=r&&n<=o?0:r<=o?i:a},equals:function(t,e,n){return n?y(t,e)>16)+t*(n>>16)<<16|r*(e>>8&255)+t*(n>>8&255)<<8|r*(255&e)+t*(255&n)},random:function(t,e){function n(){return s.range(t,e)}var r=s.pick([{r:1,g:1,b:1},{r:1,g:1,b:0},{r:1,g:0,b:1},{r:0,g:1,b:1},{r:1,g:0,b:0},{r:0,g:1,b:0},{r:0,g:0,b:1}]);return t=t||0,e=e||255,this.rgbToHex(r.r?n():0,r.g?n():0,r.b?n():0)},randomHSL:function(t,e,n,r,o,i){var a={h:s.range(t,e),s:s.range(n,r,!0),l:s.range(o,i,!0)};return this.hslToHex(a)},randomGoldenRatioHSL:function(t,e,n){for(var r=s.get(1,!0),o=[],i=0;i, 2010 - // http://baagoe.com/en/RandomMusings/javascript/ - // https://github.com/nquinlan/better-random-numbers-for-javascript-mirror - // Original work is under MIT license - - - // Copyright (C) 2010 by Johannes Baagøe - // - // Permission is hereby granted, free of charge, to any person obtaining a copy - // of this software and associated documentation files (the "Software"), to deal - // in the Software without restriction, including without limitation the rights - // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - // copies of the Software, and to permit persons to whom the Software is - // furnished to do so, subject to the following conditions: - // - // The above copyright notice and this permission notice shall be included in - // all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - // THE SOFTWARE. - - - (function (global, module, define) { - - function Alea(seed) { - var me = this, - mash = Mash(); - - me.next = function () { - var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32 - me.s0 = me.s1; - me.s1 = me.s2; - return me.s2 = t - (me.c = t | 0); - }; - - // Apply the seeding algorithm from Baagoe. - me.c = 1; - me.s0 = mash(' '); - me.s1 = mash(' '); - me.s2 = mash(' '); - me.s0 -= mash(seed); - if (me.s0 < 0) { - me.s0 += 1; - } - me.s1 -= mash(seed); - if (me.s1 < 0) { - me.s1 += 1; - } - me.s2 -= mash(seed); - if (me.s2 < 0) { - me.s2 += 1; - } - mash = null; - } - - function copy(f, t) { - t.c = f.c; - t.s0 = f.s0; - t.s1 = f.s1; - t.s2 = f.s2; - return t; - } - - function impl(seed, opts) { - var xg = new Alea(seed), - state = opts && opts.state, - prng = xg.next; - prng.int32 = function () { - return xg.next() * 0x100000000 | 0; - }; - prng.double = function () { - return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 - }; - prng.quick = prng; - if (state) { - if ((typeof state === "undefined" ? "undefined" : _typeof(state)) == 'object') copy(state, xg); - prng.state = function () { - return copy(xg, {}); - }; - } - return prng; - } - - function Mash() { - var n = 0xefc8249d; - - var mash = function mash(data) { - data = data.toString(); - for (var i = 0; i < data.length; i++) { - n += data.charCodeAt(i); - var h = 0.02519603282416938 * n; - n = h >>> 0; - h -= n; - h *= n; - n = h >>> 0; - h -= n; - n += h * 0x100000000; // 2^32 - } - return (n >>> 0) * 2.3283064365386963e-10; // 2^-32 - }; - - return mash; - } - - if (module && module.exports) { - module.exports = impl; - } else if (define && define.amd) { - define(function () { - return impl; - }); - } else { - this.alea = impl; - } - })(this, (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module, // present in node.js - typeof define == 'function' && define // present with an AMD loader - ); - }, {}], 5: [function (require, module, exports) { - // A Javascript implementaion of the "Tyche-i" prng algorithm by - // Samuel Neves and Filipe Araujo. - // See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf - - (function (global, module, define) { - - function XorGen(seed) { - var me = this, - strseed = ''; - - // Set up generator function. - me.next = function () { - var b = me.b, - c = me.c, - d = me.d, - a = me.a; - b = b << 25 ^ b >>> 7 ^ c; - c = c - d | 0; - d = d << 24 ^ d >>> 8 ^ a; - a = a - b | 0; - me.b = b = b << 20 ^ b >>> 12 ^ c; - me.c = c = c - d | 0; - me.d = d << 16 ^ c >>> 16 ^ a; - return me.a = a - b | 0; - }; - - /* The following is non-inverted tyche, which has better internal - * bit diffusion, but which is about 25% slower than tyche-i in JS. - me.next = function() { - var a = me.a, b = me.b, c = me.c, d = me.d; - a = (me.a + me.b | 0) >>> 0; - d = me.d ^ a; d = d << 16 ^ d >>> 16; - c = me.c + d | 0; - b = me.b ^ c; b = b << 12 ^ d >>> 20; - me.a = a = a + b | 0; - d = d ^ a; me.d = d = d << 8 ^ d >>> 24; - me.c = c = c + d | 0; - b = b ^ c; - return me.b = (b << 7 ^ b >>> 25); - } - */ - - me.a = 0; - me.b = 0; - me.c = 2654435769 | 0; - me.d = 1367130551; - - if (seed === Math.floor(seed)) { - // Integer seed. - me.a = seed / 0x100000000 | 0; - me.b = seed | 0; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 20; k++) { - me.b ^= strseed.charCodeAt(k) | 0; - me.next(); - } - } - - function copy(f, t) { - t.a = f.a; - t.b = f.b; - t.c = f.c; - t.d = f.d; - return t; - }; - - function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function prng() { - return (xg.next() >>> 0) / 0x100000000; - }; - prng.double = function () { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if ((typeof state === "undefined" ? "undefined" : _typeof(state)) == 'object') copy(state, xg); - prng.state = function () { - return copy(xg, {}); - }; - } - return prng; - } - - if (module && module.exports) { - module.exports = impl; - } else if (define && define.amd) { - define(function () { - return impl; - }); - } else { - this.tychei = impl; - } - })(this, (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module, // present in node.js - typeof define == 'function' && define // present with an AMD loader - ); - }, {}], 6: [function (require, module, exports) { - // A Javascript implementaion of the "xor128" prng algorithm by - // George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - - (function (global, module, define) { - - function XorGen(seed) { - var me = this, - strseed = ''; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - - // Set up generator function. - me.next = function () { - var t = me.x ^ me.x << 11; - me.x = me.y; - me.y = me.z; - me.z = me.w; - return me.w ^= me.w >>> 19 ^ t ^ t >>> 8; - }; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - me.next(); - } - } - - function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - return t; - } - - function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function prng() { - return (xg.next() >>> 0) / 0x100000000; - }; - prng.double = function () { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if ((typeof state === "undefined" ? "undefined" : _typeof(state)) == 'object') copy(state, xg); - prng.state = function () { - return copy(xg, {}); - }; - } - return prng; - } - - if (module && module.exports) { - module.exports = impl; - } else if (define && define.amd) { - define(function () { - return impl; - }); - } else { - this.xor128 = impl; - } - })(this, (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module, // present in node.js - typeof define == 'function' && define // present with an AMD loader - ); - }, {}], 7: [function (require, module, exports) { - // A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm. - // - // This fast non-cryptographic random number generator is designed for - // use in Monte-Carlo algorithms. It combines a long-period xorshift - // generator with a Weyl generator, and it passes all common batteries - // of stasticial tests for randomness while consuming only a few nanoseconds - // for each prng generated. For background on the generator, see Brent's - // paper: "Some long-period random number generators using shifts and xors." - // http://arxiv.org/pdf/1004.3115v1.pdf - // - // Usage: - // - // var xor4096 = require('xor4096'); - // random = xor4096(1); // Seed with int32 or string. - // assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits. - // assert.equal(random.int32(), 1806534897); // signed int32, 32 bits. - // - // For nonzero numeric keys, this impelementation provides a sequence - // identical to that by Brent's xorgens 3 implementaion in C. This - // implementation also provides for initalizing the generator with - // string seeds, or for saving and restoring the state of the generator. - // - // On Chrome, this prng benchmarks about 2.1 times slower than - // Javascript's built-in Math.random(). - - (function (global, module, define) { - - function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function () { - var w = me.w, - X = me.X, - i = me.i, - t, - v; - // Update Weyl generator. - me.w = w = w + 0x61c88647 | 0; - // Update xor generator. - v = X[i + 34 & 127]; - t = X[i = i + 1 & 127]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - // Update Xor generator array state. - v = X[i] = v ^ t; - me.i = i; - // Result is the combination. - return v + (w ^ w >>> 16) | 0; - }; - - function init(me, seed) { - var t, - v, - i, - j, - w, - X = [], - limit = 128; - if (seed === (seed | 0)) { - // Numeric seeds initialize v, which is used to generates X. - v = seed; - seed = null; - } else { - // String seeds are mixed into v and X one character at a time. - seed = seed + '\0'; - v = 0; - limit = Math.max(limit, seed.length); - } - // Initialize circular array and weyl value. - for (i = 0, j = -32; j < limit; ++j) { - // Put the unicode characters into the array, and shuffle them. - if (seed) v ^= seed.charCodeAt((j + 32) % seed.length); - // After 32 shuffles, take v as the starting w value. - if (j === 0) w = v; - v ^= v << 10; - v ^= v >>> 15; - v ^= v << 4; - v ^= v >>> 13; - if (j >= 0) { - w = w + 0x61c88647 | 0; // Weyl. - t = X[j & 127] ^= v + w; // Combine xor and weyl to init array. - i = 0 == t ? i + 1 : 0; // Count zeroes. - } - } - // We have detected all zeroes; make the key nonzero. - if (i >= 128) { - X[(seed && seed.length || 0) & 127] = -1; - } - // Run the generator 512 times to further mix the state before using it. - // Factoring this as a function slows the main generator, so it is just - // unrolled here. The weyl generator is not advanced while warming up. - i = 127; - for (j = 4 * 128; j > 0; --j) { - v = X[i + 34 & 127]; - t = X[i = i + 1 & 127]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - X[i] = v ^ t; - } - // Storing state as object members is faster than using closure variables. - me.w = w; - me.X = X; - me.i = i; - } - - init(me, seed); - } - - function copy(f, t) { - t.i = f.i; - t.w = f.w; - t.X = f.X.slice(); - return t; - }; - - function impl(seed, opts) { - if (seed == null) seed = +new Date(); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function prng() { - return (xg.next() >>> 0) / 0x100000000; - }; - prng.double = function () { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.X) copy(state, xg); - prng.state = function () { - return copy(xg, {}); - }; - } - return prng; - } - - if (module && module.exports) { - module.exports = impl; - } else if (define && define.amd) { - define(function () { - return impl; - }); - } else { - this.xor4096 = impl; - } - })(this, // window object or global - (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module, // present in node.js - typeof define == 'function' && define // present with an AMD loader - ); - }, {}], 8: [function (require, module, exports) { - // A Javascript implementaion of the "xorshift7" algorithm by - // François Panneton and Pierre L'ecuyer: - // "On the Xorgshift Random Number Generators" - // http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf - - (function (global, module, define) { - - function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function () { - // Update xor generator. - var X = me.x, - i = me.i, - t, - v, - w; - t = X[i];t ^= t >>> 7;v = t ^ t << 24; - t = X[i + 1 & 7];v ^= t ^ t >>> 10; - t = X[i + 3 & 7];v ^= t ^ t >>> 3; - t = X[i + 4 & 7];v ^= t ^ t << 7; - t = X[i + 7 & 7];t = t ^ t << 13;v ^= t ^ t << 9; - X[i] = v; - me.i = i + 1 & 7; - return v; - }; - - function init(me, seed) { - var j, - w, - X = []; - - if (seed === (seed | 0)) { - // Seed state array using a 32-bit integer. - w = X[0] = seed; - } else { - // Seed state using a string. - seed = '' + seed; - for (j = 0; j < seed.length; ++j) { - X[j & 7] = X[j & 7] << 15 ^ seed.charCodeAt(j) + X[j + 1 & 7] << 13; - } - } - // Enforce an array length of 8, not all zeroes. - while (X.length < 8) { - X.push(0); - }for (j = 0; j < 8 && X[j] === 0; ++j) {} - if (j == 8) w = X[7] = -1;else w = X[j]; - - me.x = X; - me.i = 0; - - // Discard an initial 256 values. - for (j = 256; j > 0; --j) { - me.next(); - } - } - - init(me, seed); - } - - function copy(f, t) { - t.x = f.x.slice(); - t.i = f.i; - return t; - } - - function impl(seed, opts) { - if (seed == null) seed = +new Date(); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function prng() { - return (xg.next() >>> 0) / 0x100000000; - }; - prng.double = function () { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.x) copy(state, xg); - prng.state = function () { - return copy(xg, {}); - }; - } - return prng; - } - - if (module && module.exports) { - module.exports = impl; - } else if (define && define.amd) { - define(function () { - return impl; - }); - } else { - this.xorshift7 = impl; - } - })(this, (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module, // present in node.js - typeof define == 'function' && define // present with an AMD loader - ); - }, {}], 9: [function (require, module, exports) { - // A Javascript implementaion of the "xorwow" prng algorithm by - // George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - - (function (global, module, define) { - - function XorGen(seed) { - var me = this, - strseed = ''; - - // Set up generator function. - me.next = function () { - var t = me.x ^ me.x >>> 2; - me.x = me.y;me.y = me.z;me.z = me.w;me.w = me.v; - return (me.d = me.d + 362437 | 0) + (me.v = me.v ^ me.v << 4 ^ (t ^ t << 1)) | 0; - }; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - me.v = 0; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - if (k == strseed.length) { - me.d = me.x << 10 ^ me.x >>> 4; - } - me.next(); - } - } - - function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - t.v = f.v; - t.d = f.d; - return t; - } - - function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function prng() { - return (xg.next() >>> 0) / 0x100000000; - }; - prng.double = function () { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if ((typeof state === "undefined" ? "undefined" : _typeof(state)) == 'object') copy(state, xg); - prng.state = function () { - return copy(xg, {}); - }; - } - return prng; - } - - if (module && module.exports) { - module.exports = impl; - } else if (define && define.amd) { - define(function () { - return impl; - }); - } else { - this.xorwow = impl; - } - })(this, (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module, // present in node.js - typeof define == 'function' && define // present with an AMD loader - ); - }, {}], 10: [function (require, module, exports) { - /* - Copyright 2014 David Bau. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - */ - - (function (pool, math) { - // - // The following constants are related to IEEE 754 limits. - // - var global = this, - width = 256, - // each RC4 output is 0 <= x < 256 - chunks = 6, - // at least six RC4 outputs for each double - digits = 52, - // there are 52 significant digits in a double - rngname = 'random', - // rngname: name for Math.random and Math.seedrandom - startdenom = math.pow(width, chunks), - significance = math.pow(2, digits), - overflow = significance * 2, - mask = width - 1, - nodecrypto; // node.js crypto module, initialized at the bottom. - - // - // seedrandom() - // This is the seedrandom function described above. - // - function seedrandom(seed, options, callback) { - var key = []; - options = options == true ? { entropy: true } : options || {}; - - // Flatten the seed string or build one from local entropy if needed. - var shortseed = mixkey(flatten(options.entropy ? [seed, tostring(pool)] : seed == null ? autoseed() : seed, 3), key); - - // Use the seed to initialize an ARC4 generator. - var arc4 = new ARC4(key); - - // This function returns a random double in [0, 1) that contains - // randomness in every bit of the mantissa of the IEEE 754 value. - var prng = function prng() { - var n = arc4.g(chunks), - // Start with a numerator n < 2 ^ 48 - d = startdenom, - // and denominator d = 2 ^ 48. - x = 0; // and no 'extra last byte'. - while (n < significance) { - // Fill up all significant digits by - n = (n + x) * width; // shifting numerator and - d *= width; // denominator and generating a - x = arc4.g(1); // new least-significant-byte. - } - while (n >= overflow) { - // To avoid rounding up, before adding - n /= 2; // last byte, shift everything - d /= 2; // right using integer math until - x >>>= 1; // we have exactly the desired bits. - } - return (n + x) / d; // Form the number within [0, 1). - }; - - prng.int32 = function () { - return arc4.g(4) | 0; - }; - prng.quick = function () { - return arc4.g(4) / 0x100000000; - }; - prng.double = prng; - - // Mix the randomness into accumulated entropy. - mixkey(tostring(arc4.S), pool); - - // Calling convention: what to return as a function of prng, seed, is_math. - return (options.pass || callback || function (prng, seed, is_math_call, state) { - if (state) { - // Load the arc4 state from the given state if it has an S array. - if (state.S) { - copy(state, arc4); - } - // Only provide the .state method if requested via options.state. - prng.state = function () { - return copy(arc4, {}); - }; - } - - // If called as a method of Math (Math.seedrandom()), mutate - // Math.random because that is how seedrandom.js has worked since v1.0. - if (is_math_call) { - math[rngname] = prng;return seed; - } - - // Otherwise, it is a newer calling convention, so return the - // prng directly. - else return prng; - })(prng, shortseed, 'global' in options ? options.global : this == math, options.state); - } - math['seed' + rngname] = seedrandom; - - // - // ARC4 - // - // An ARC4 implementation. The constructor takes a key in the form of - // an array of at most (width) integers that should be 0 <= x < (width). - // - // The g(count) method returns a pseudorandom integer that concatenates - // the next (count) outputs from ARC4. Its return value is a number x - // that is in the range 0 <= x < (width ^ count). - // - function ARC4(key) { - var t, - keylen = key.length, - me = this, - i = 0, - j = me.i = me.j = 0, - s = me.S = []; - - // The empty key [] is treated as [0]. - if (!keylen) { - key = [keylen++]; - } - - // Set up S using the standard key scheduling algorithm. - while (i < width) { - s[i] = i++; - } - for (i = 0; i < width; i++) { - s[i] = s[j = mask & j + key[i % keylen] + (t = s[i])]; - s[j] = t; - } - - // The "g" method returns the next (count) outputs as one number. - (me.g = function (count) { - // Using instance members instead of closure state nearly doubles speed. - var t, - r = 0, - i = me.i, - j = me.j, - s = me.S; - while (count--) { - t = s[i = mask & i + 1]; - r = r * width + s[mask & (s[i] = s[j = mask & j + t]) + (s[j] = t)]; - } - me.i = i;me.j = j; - return r; - // For robust unpredictability, the function call below automatically - // discards an initial batch of values. This is called RC4-drop[256]. - // See http://google.com/search?q=rsa+fluhrer+response&btnI - })(width); - } - - // - // copy() - // Copies internal state of ARC4 to or from a plain object. - // - function copy(f, t) { - t.i = f.i; - t.j = f.j; - t.S = f.S.slice(); - return t; - }; - - // - // flatten() - // Converts an object tree to nested arrays of strings. - // - function flatten(obj, depth) { - var result = [], - typ = typeof obj === "undefined" ? "undefined" : _typeof(obj), - prop; - if (depth && typ == 'object') { - for (prop in obj) { - try { - result.push(flatten(obj[prop], depth - 1)); - } catch (e) {} - } - } - return result.length ? result : typ == 'string' ? obj : obj + '\0'; - } - - // - // mixkey() - // Mixes a string seed into a key that is an array of integers, and - // returns a shortened string seed that is equivalent to the result key. - // - function mixkey(seed, key) { - var stringseed = seed + '', - smear, - j = 0; - while (j < stringseed.length) { - key[mask & j] = mask & (smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++); - } - return tostring(key); - } - - // - // autoseed() - // Returns an object for autoseeding, using window.crypto and Node crypto - // module if available. - // - function autoseed() { - try { - var out; - if (nodecrypto && (out = nodecrypto.randomBytes)) { - // The use of 'out' to remember randomBytes makes tight minified code. - out = out(width); - } else { - out = new Uint8Array(width); - (global.crypto || global.msCrypto).getRandomValues(out); - } - return tostring(out); - } catch (e) { - var browser = global.navigator, - plugins = browser && browser.plugins; - return [+new Date(), global, plugins, global.screen, tostring(pool)]; - } - } - - // - // tostring() - // Converts an array of charcodes to a string - // - function tostring(a) { - return String.fromCharCode.apply(0, a); - } - - // - // When seedrandom.js is loaded, we immediately mix a few bits - // from the built-in RNG into the entropy pool. Because we do - // not want to interfere with deterministic PRNG state later, - // seedrandom will not call math.random on its own again after - // initialization. - // - mixkey(math.random(), pool); - - // - // Nodejs and AMD support: export the implementation as a module using - // either convention. - // - if ((typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module.exports) { - module.exports = seedrandom; - // When in node.js, try using crypto package for autoseeding. - try { - nodecrypto = require('crypto'); - } catch (ex) {} - } else if (typeof define == 'function' && define.amd) { - define(function () { - return seedrandom; - }); - } - - // End anonymous scope, and pass initial values. - })([], // pool: entropy pool starts empty - Math // math: package containing random, pow, and seedrandom - ); - }, { "crypto": 25 }], 11: [function (require, module, exports) { - // angle.js - // Released under MIT license - // Author: David Figatner - // Copyright (c) 2016-17 YOPEY YOPEY LLC - - var _toDegreeConversion = 180 / Math.PI; - var _toRadianConversion = Math.PI / 180; - - /** @constant {number} */ - var UP = Math.PI / 2; - var DOWN = 3 * Math.PI / 2; - var LEFT = Math.PI; - var RIGHT = 0; - - var NORTH = UP; - var SOUTH = DOWN; - var WEST = LEFT; - var EAST = RIGHT; - - var PI_2 = Math.PI * 2; - var PI_QUARTER = Math.PI / 4; - var PI_HALF = Math.PI / 2; - - /** - * converts from radians to degrees (all other functions expect radians) - * @param {number} radians - * @return {number} degrees - */ - function toDegrees(radians) { - return radians * _toDegreeConversion; - } - - /** - * converts from degrees to radians (all other functions expect radians) - * @param {number} degrees - * @return {number} radians - */ - function toRadians(degrees) { - return degrees * _toRadianConversion; - } - - /** - * returns whether the target angle is between angle1 and angle2 (in radians) - * (based on: http://stackoverflow.com/questions/11406189/determine-if-angle-lies-between-2-other-angles) - * @param {number} target angle - * @param {number} angle1 - * @param {number} angle2 - * @return {boolean} - */ - function isAngleBetween(target, angle1, angle2) { - var rAngle = ((angle2 - angle1) % PI_2 + PI_2) % PI_2; - if (rAngle >= Math.PI) { - var swap = angle1; - angle1 = angle2; - angle2 = swap; - } - - if (angle1 <= angle2) { - return target >= angle1 && target <= angle2; - } else { - return target >= angle1 || target <= angle2; - } - } - - /** - * returns +1 or -1 based on whether the difference between two angles is positive or negative (in radians) - * @param {number} target angle - * @param {number} source angle - * @return {number} 1 or -1 - */ - function differenceAnglesSign(target, source) { - function mod(a, n) { - return (a % n + n) % n; - } - - var a = target - source; - return mod(a + Math.PI, PI_2) - Math.PI > 0 ? 1 : -1; - } - - /** - * returns the normalized difference between two angles (in radians) - * @param {number} a - first angle - * @param {number} b - second angle - * @return {number} normalized difference between a and b - */ - function differenceAngles(a, b) { - var c = Math.abs(a - b) % PI_2; - return c > Math.PI ? PI_2 - c : c; - } - - /** - * returns a target angle that is the shortest way to rotate an object between start and to--may choose a negative angle - * @param {number} start - * @param {number} to - * @return {number} shortest target angle - */ - function shortestAngle(start, to) { - var difference = differenceAngles(to, start); - var sign = differenceAnglesSign(to, start); - var delta = difference * sign; - return delta + start; - } - - /** - * returns the normalized angle (0 - PI x 2) - * @param {number} radians - * @return {number} normalized angle in radians - */ - function normalize(radians) { - return radians - PI_2 * Math.floor(radians / PI_2); - } - - /** - * returns angle between two points (in radians) - * @param {Point} [point1] {x: x, y: y} - * @param {Point} [point2] {x: x, y: y} - * @param {number} [x1] - * @param {number} [y1] - * @param {number} [x2] - * @param {number} [y2] - * @return {number} angle - */ - function angleTwoPoints() /* (point1, point2) OR (x1, y1, x2, y2) */{ - if (arguments.length === 4) { - return Math.atan2(arguments[3] - arguments[1], arguments[2] - arguments[0]); - } else { - return Math.atan2(arguments[1].y - arguments[0].y, arguments[1].x - arguments[0].x); - } - } - - /** - * returns distance between two points - * @param {Point} [point1] {x: x, y: y} - * @param {Point} [point2] {x: x, y: y} - * @param {number} [x1] - * @param {number} [y1] - * @param {number} [x2] - * @param {number} [y2] - * @return {number} distance - */ - function distanceTwoPoints() /* (point1, point2) OR (x1, y1, x2, y2) */{ - if (arguments.length === 2) { - return Math.sqrt(Math.pow(arguments[1].x - arguments[0].x, 2) + Math.pow(arguments[1].y - arguments[0].y, 2)); - } else { - return Math.sqrt(Math.pow(arguments[2] - arguments[0], 2) + Math.pow(arguments[3] - arguments[1], 2)); - } - } - - /** - * returns the squared distance between two points - * @param {Point} [point1] {x: x, y: y} - * @param {Point} [point2] {x: x, y: y} - * @param {number} [x1] - * @param {number} [y1] - * @param {number} [x2] - * @param {number} [y2] - * @return {number} squared distance - */ - function distanceTwoPointsSquared() /* (point1, point2) OR (x1, y1, x2, y2) */{ - if (arguments.length === 2) { - return Math.pow(arguments[1].x - arguments[0].x, 2) + Math.pow(arguments[1].y - arguments[0].y, 2); - } else { - return Math.pow(arguments[2] - arguments[0], 2) + Math.pow(arguments[3] - arguments[1], 2); - } - } - - /** - * returns the closest cardinal (N, S, E, W) to the given angle (in radians) - * @param {number} angle - * @return {number} closest cardinal in radians - */ - function closestAngle(angle) { - var left = differenceAngles(angle, LEFT); - var right = differenceAngles(angle, RIGHT); - var up = differenceAngles(angle, UP); - var down = differenceAngles(angle, DOWN); - if (left <= right && left <= up && left <= down) { - return LEFT; - } else if (right <= up && right <= down) { - return RIGHT; - } else if (up <= down) { - return UP; - } else { - return DOWN; - } - } - - /** - * checks whether angles a1 and a2 are equal (after normalizing) - * @param {number} a1 - * @param {number} a2 - * @param {number} [wiggle] return true if the difference between the angles is <= wiggle - * @return {boolean} a1 === a2 - */ - function equals(a1, a2, wiggle) { - if (wiggle) { - return differenceAngles(a1, a2) < wiggle; - } else { - return normalize(a1) === normalize(a2); - } - } - - /** - * return a text representation of the cardinal direction - * @param {number} angle - * @returns {string} UP, DOWN, LEFT, RIGHT, or NOT CARDINAL - */ - function explain(angle) { - switch (angle) { - case UP: - return 'UP'; - case DOWN: - return 'DOWN'; - case LEFT: - return 'LEFT'; - case RIGHT: - return 'RIGHT'; - default: - return 'NOT CARDINAL'; - } - } - - module.exports = { - UP: UP, - DOWN: DOWN, - LEFT: LEFT, - RIGHT: RIGHT, - NORTH: NORTH, - SOUTH: SOUTH, - WEST: WEST, - EAST: EAST, - PI_2: PI_2, - PI_QUARTER: PI_QUARTER, - PI_HALF: PI_HALF, - - toDegrees: toDegrees, - toRadians: toRadians, - isAngleBetween: isAngleBetween, - differenceAnglesSign: differenceAnglesSign, - differenceAngles: differenceAngles, - shortestAngle: shortestAngle, - normalize: normalize, - angleTwoPoints: angleTwoPoints, - distanceTwoPoints: distanceTwoPoints, - distanceTwoPointsSquared: distanceTwoPointsSquared, - closestAngle: closestAngle, - equals: equals, - explain: explain - }; - }, {}], 12: [function (require, module, exports) { - // yy-color - // by David Figatner - // MIT License - // (c) YOPEY YOPEY LLC 2017 - // https://github.com/davidfig/color - - var Random = require('yy-random'); - - /** - * converts a #FFFFFF to 0x123456 - * @param {string} color - * @return {string} - */ - function poundToHex(color) { - return '0x' + parseInt(color.substr(1)).toString(16); - } - - /** - * converts a 0x123456 to #FFFFFF - * @param {string} color - * @return {string} - */ - function hexToPound(color) { - return '#' + color.substr(2); - } - - /** - * converts a number to #FFFFFF - * @param {number} color - * @return {string} - */ - function valueToPound(color) { - return '#' + color.toString(16); - } - - /** - * based on tinycolor - * https://github.com/bgrins/TinyColor - * BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE - * @param {string} color - * @returns {object} - */ - function hexToHsl(color) { - var rgb = this.hexToRgb(color), - r = rgb.r, - g = rgb.g, - b = rgb.b; - var max = Math.max(r, g, b), - min = Math.min(r, g, b); - var h, - s, - l = (max + min) / 2; - - if (max === min) { - h = s = 0; // achromatic - } else { - var d = max - min; - s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - switch (max) { - case r: - h = (g - b) / d + (g < b ? 6 : 0);break; - case g: - h = (b - r) / d + 2;break; - case b: - h = (r - g) / d + 4;break; - } - - h /= 6; - } - - return { h: h, s: s, l: l }; - } - - /** based on tinycolor - * https://github.com/bgrins/TinyColor - * BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE - * @param {object|number} color {h, s, b} or h - * @param {number} [s] - * @param {number} [l] - * @returns number - */ - function hslToHex(color) { - var r, g, b, h, s, l; - if (arguments.length === 1) { - h = color.h, s = color.s, l = color.l; - } else { - h = arguments[0]; - s = arguments[1]; - l = arguments[2]; - } - - function hue2rgb(p, q, t) { - if (t < 0) t += 1; - if (t > 1) t -= 1; - if (t < 1 / 6) return p + (q - p) * 6 * t; - if (t < 1 / 2) return q; - if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; - return p; - } - - if (s === 0) { - r = g = b = l; // achromatic - } else { - var q = l < 0.5 ? l * (1 + s) : l + s - l * s; - var p = 2 * l - q; - r = hue2rgb(p, q, h + 1 / 3); - g = hue2rgb(p, q, h); - b = hue2rgb(p, q, h - 1 / 3); - } - - return this.rgbToHex(r * 255, g * 255, b * 255); - } - - /* darkens a color by the percentage - * @param {object} color in hex (0xabcdef) - * @param {number} amount - * @return {number} - */ - function darken(color, amount) { - return this.blend(amount, color, 0); - } - - /** based on tinycolor - * https://github.com/bgrins/TinyColor - * BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE - * @param {object} color - * @param {number} amount - */ - function saturate(color, amount) { - amount = amount === 0 ? 0 : amount || 10; - var hsl = this.hexToHsl(color); - hsl.s += amount / 100; - hsl.s = Math.min(1, Math.max(0, hsl.s)); - return this.hslToHex(hsl); - } - - /** based on tinycolor - * https://github.com/bgrins/TinyColor - * BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE - * @param {object} color - * @param {number} amount - */ - function desaturate(color, amount) { - amount = amount === 0 ? 0 : amount || 10; - var hsl = this.hexToHsl(color); - hsl.s -= amount / 100; - hsl.s = Math.min(1, Math.max(0, hsl.s)); - return this.hslToHex(hsl); - } - - /** - * blends two colors together - * @param {number} percent [0.0 - 1.0] - * @param {string} color1 first color in 0x123456 format - * @param {string} color2 second color in 0x123456 format - * @return {number} - */ - function blend(percent, color1, color2) { - if (percent === 0) { - return color1; - } - if (percent === 1) { - return color2; - } - var r1 = color1 >> 16; - var g1 = color1 >> 8 & 0x0000ff; - var b1 = color1 & 0x0000ff; - var r2 = color2 >> 16; - var g2 = color2 >> 8 & 0x0000ff; - var b2 = color2 & 0x0000ff; - var percent1 = 1 - percent; - var r = percent1 * r1 + percent * r2; - var g = percent1 * g1 + percent * g2; - var b = percent1 * b1 + percent * b2; - return r << 16 | g << 8 | b; - } - - /** - * returns a hex color into an rgb value - * @param {number} hex - * @return {string} - */ - function hexToRgb(hex) { - if (hex === 0) { - hex = '0x000000'; - } else if (typeof hex !== 'string') { - var s = '000000' + hex.toString(16); - hex = '0x' + s.substr(s.length - 6); - } - var result = /^0x?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); - return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; - } - - /** - * rgb color to hex in the form of 0x123456 - * @param {(number|string)} r first number or 'rgb(...)' string - * @param {(number|null)} g - * @param {(number|null)} b - * @return {string} - */ - function rgbToHex(r, g, b) { - if (arguments.length === 1) { - if (Array.isArray(arguments[0])) { - var number = arguments[0]; - r = number[0]; - g = number[1]; - b = number[2]; - } else { - var parse = r.replace(/( *rgb *\( *)|( )|(\) *;?)/, ''); - var numbers = parse.split(','); - r = numbers[0]; - g = numbers[1]; - b = numbers[2]; - } - } - return '0x' + ((1 << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b)).toString(16).slice(1); - } - - /** - * returns a random color with balanced r, g, b values (i.e., r, g, b either have the same value or are 0) - * @param {number} min value for random number - * @param {number} max value for random number - * @return {number} color - */ - function random(min, max) { - function random() { - return Random.range(min, max); - } - - var colors = [{ r: 1, g: 1, b: 1 }, { r: 1, g: 1, b: 0 }, { r: 1, g: 0, b: 1 }, { r: 0, g: 1, b: 1 }, { r: 1, g: 0, b: 0 }, { r: 0, g: 1, b: 0 }, { r: 0, g: 0, b: 1 }]; - var color = Random.pick(colors); - min = min || 0; - max = max || 255; - return this.rgbToHex(color.r ? random() : 0, color.g ? random() : 0, color.b ? random() : 0); - } - - // h: 0-360, s: 0-1, l: 0-1 - /** - * returns a random color based on hsl - * @param {number} hMin [0, 360] - * @param {number} hMax [hMin, 360] - * @param {number} sMin [0, 1] - * @param {number} sMax [sMin, 1] - * @param {number} lMin [0, 1] - * @param {number} lMax [lMin, 1] - */ - function randomHSL(hMin, hMax, sMin, sMax, lMin, lMax) { - var color = { - h: Random.range(hMin, hMax), - s: Random.range(sMin, sMax, true), - l: Random.range(lMin, lMax, true) - }; - return this.hslToHex(color); - } - - /** - * returns random colors based on HSL with different hues - * based on http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ - * @returns {number[]} colors in hex format (0x123456) - */ - function randomGoldenRatioHSL(count, saturation, luminosity) { - var goldenRatio = 0.618033988749895; - var h = Random.get(1, true); - var colors = []; - for (var i = 0; i < count; i++) { - colors.push(this.hslToHex(h, saturation, luminosity)); - h = (h + goldenRatio) % 1; - } - return colors; - } - - module.exports = { - poundToHex: poundToHex, - hexToPound: hexToPound, - valueToPound: valueToPound, - hexToHsl: hexToHsl, - hslToHex: hslToHex, - hexToRgb: hexToRgb, - rgbToHex: rgbToHex, - darken: darken, - saturate: saturate, - desaturate: desaturate, - blend: blend, - random: random, - randomHSL: randomHSL, - randomGoldenRatioHSL: randomGoldenRatioHSL - }; - }, { "yy-random": 13 }], 13: [function (require, module, exports) { - 'use strict'; - - var _createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); - } - }return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; - }; - }(); - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - // yy-random - // by David Figatner - // MIT license - // copyright YOPEY YOPEY LLC 2016-17 - // https://github.com/davidfig/random - - var seedrandom = require('seedrandom'); - - var Random = function () { - function Random() { - _classCallCheck(this, Random); - - this.generator = Math.random; - } - - /** - * generates a seeded number - * @param {number} seed - * @param {object} [options] - * @param {string} [PRNG="alea"] - name of algorithm, see https://github.com/davidbau/seedrandom - * @param {boolean} [save=true] - */ - - _createClass(Random, [{ - key: 'seed', - value: function seed(_seed, options) { - options = options || {}; - this.generator = seedrandom[options.PRNG || 'alea'](_seed, { state: options.state }); - this.options = options; - } - - /** - * saves the state of the random generator - * can only be used after Random.seed() is called - * @returns {number} state - */ - - }, { - key: 'save', - value: function save() { - if (this.generator !== Math.random) { - return this.generator.state(); - } - } - - /** - * restores the state of the random generator - * @param {number} state - */ - - }, { - key: 'restore', - value: function restore(state) { - this.generator = seedrandom[this.options.PRNG || 'alea']('', { state: state }); - } - - /** - * changes the generator to use the old Math.sin-based random function - * based on : http://stackoverflow.com/questions/521295/javascript-random-seeds - * (deprecated) Use only for compatibility purposes - * @param {number} seed - */ - - }, { - key: 'seedOld', - value: function seedOld(seed) { - this.generator = function () { - var x = Math.sin(seed++) * 10000; - return x - Math.floor(x); - }; - } - - /** - * create a separate random generator using the seed - * @param {number} seed - * @return {object} - */ - - }, { - key: 'separateSeed', - value: function separateSeed(seed) { - var random = new Random(); - random.seed(seed); - return random; - } - - /** - * resets the random number this.generator to Math.random() - */ - - }, { - key: 'reset', - value: function reset() { - this.generator = Math.random; - } - - /** - * returns a random number using the this.generator between [0, ceiling - 1] - * @param {number} ceiling - * @param {boolean} [useFloat=false] - * @return {number} - */ - - }, { - key: 'get', - value: function get(ceiling, useFloat) { - var negative = ceiling < 0 ? -1 : 1; - ceiling *= negative; - var result = void 0; - if (useFloat) { - result = this.generator() * ceiling; - } else { - result = Math.floor(this.generator() * ceiling); - } - return result * negative; - } - - /** - * returns a random integer between 0 - Number.MAX_SAFE_INTEGER - * @return {number} - */ - - }, { - key: 'getHuge', - value: function getHuge() { - return this.get(Number.MAX_SAFE_INTEGER); - } - - /** - * random number [middle - range, middle + range] - * @param {number} middle - * @param {number} delta - * @param {boolean} [useFloat=false] - * @return {number} - */ - - }, { - key: 'middle', - value: function middle(_middle, delta, useFloat) { - var half = delta / 2; - return this.range(_middle - half, _middle + half, useFloat); - } - - /** - * random number [start, end] - * @param {number} start - * @param {number} end - * @param {boolean} [useFloat=false] if true, then range is (start, end)--i.e., not inclusive to start and end - * @return {number} - */ - - }, { - key: 'range', - value: function range(start, end, useFloat) { - // case where there is no range - if (end === start) { - return end; - } - - if (useFloat) { - return this.get(end - start, true) + start; - } else { - var range = void 0; - if (start < 0 && end > 0) { - range = -start + end + 1; - } else if (start === 0 && end > 0) { - range = end + 1; - } else if (start < 0 && end === 0) { - range = start - 1; - start = 1; - } else if (start < 0 && end < 0) { - range = end - start - 1; - } else { - range = end - start + 1; - } - return Math.floor(this.generator() * range) + start; - } - } - - /** - * an array of random numbers between [start, end] - * @param {number} start - * @param {number} end - * @param {number} count - * @param {boolean} [useFloat=false] - * @return {number[]} - */ - - }, { - key: 'rangeMultiple', - value: function rangeMultiple(start, end, count, useFloat) { - var array = []; - for (var i = 0; i < count; i++) { - array.push(this.range(start, end, useFloat)); - } - return array; - } - - /** - * an array of random numbers between [middle - range, middle + range] - * @param {number} middle - * @param {number} range - * @param {number} count - * @param {boolean} [useFloat=false] - * @return {number[]} - */ - - }, { - key: 'middleMultiple', - value: function middleMultiple(middle, range, count, useFloat) { - var array = []; - for (var i = 0; i < count; i++) { - array.push(middle(middle, range, useFloat)); - } - return array; - } - - /** - * @param {number} [chance=0.5] - * returns random sign (either +1 or -1) - * @return {number} - */ - - }, { - key: 'sign', - value: function sign(chance) { - chance = chance || 0.5; - return this.generator() < chance ? 1 : -1; - } - - /** - * tells you whether a random chance was achieved - * @param {number} [percent=0.5] - * @return {boolean} - */ - - }, { - key: 'chance', - value: function chance(percent) { - return this.generator() < (percent || 0.5); - } - - /** - * returns a random angle in radians [0 - 2 * Math.PI) - */ - - }, { - key: 'angle', - value: function angle() { - return this.get(Math.PI * 2, true); - } - - /** - * Shuffle array (either in place or copied) - * from http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array - * @param {Array} array - * @param {boolean} [copy=false] whether to shuffle in place (default) or return a new shuffled array - * @return {Array} a shuffled array - */ - - }, { - key: 'shuffle', - value: function shuffle(array, copy) { - if (copy) { - array = array.slice(); - } - if (array.length === 0) { - return array; - } - - var currentIndex = array.length, - temporaryValue = void 0, - randomIndex = void 0; - - // While there remain elements to shuffle... - while (0 !== currentIndex) { - // Pick a remaining element... - randomIndex = this.get(currentIndex); - currentIndex -= 1; - - // And swap it with the current element. - temporaryValue = array[currentIndex]; - array[currentIndex] = array[randomIndex]; - array[randomIndex] = temporaryValue; - } - return array; - } - - /** - * picks a random element from an array - * @param {Array} array - * @return {*} - */ - - }, { - key: 'pick', - value: function pick(array, remove) { - if (!remove) { - return array[this.get(array.length)]; - } else { - var pick = this.get(array.length); - var temp = array[pick]; - array.splice(pick, 1); - return temp; - } - } - - /** - * returns a random property from an object - * from http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object - * @param {object} obj - * @return {*} - */ - - }, { - key: 'property', - value: function property(obj) { - var result; - var count = 0; - for (var prop in obj) { - if (this.chance(1 / ++count)) { - result = prop; - } - } - return result; - } - - /** - * creates a random set where each entry is a value between [min, max] - * @param {number} min - * @param {number} max - * @param {number} amount of numbers in set - * @param {number[]} - */ - - }, { - key: 'set', - value: function set(min, max, amount) { - var set = [], - all = [], - i; - for (i = min; i < max; i++) { - all.push(i); - } - - for (i = 0; i < amount; i++) { - var found = this.get(all.length); - set.push(all[found]); - all.splice(found, 1); - } - return set; - } - - /** - * returns a set of numbers with a randomly even distribution (i.e., no overlapping and filling the space) - * @param {number} start position - * @param {number} end position - * @param {number} count of non-start/end points - * @param {boolean} [includeStart=false] includes start point (count++) - * @param {boolean} [includeEnd=false] includes end point (count++) - * @param {boolean} [useFloat=false] - * @param {number[]} - */ - - }, { - key: 'distribution', - value: function distribution(start, end, count, includeStart, includeEnd, useFloat) { - var interval = Math.floor((end - start) / count); - var halfInterval = interval / 2; - var quarterInterval = interval / 4; - var set = []; - if (includeStart) { - set.push(start); - } - for (var i = 0; i < count; i++) { - set.push(start + i * interval + halfInterval + this.range(-quarterInterval, quarterInterval, useFloat)); - } - if (includeEnd) { - set.push(end); - } - return set; - } - - /** - * returns a random number based on weighted probability between [min, max] - * from http://stackoverflow.com/questions/22656126/javascript-random-number-with-weighted-probability - * @param {number} min value - * @param {number} max value - * @param {number} target for average value - * @param {number} stddev - standard deviation - */ - - }, { - key: 'weightedProbabilityInt', - value: function weightedProbabilityInt(min, max, target, stddev) { - function normRand() { - var x1 = void 0, - x2 = void 0, - rad = void 0; - do { - x1 = 2 * this.get(1, true) - 1; - x2 = 2 * this.get(1, true) - 1; - rad = x1 * x1 + x2 * x2; - } while (rad >= 1 || rad === 0); - var c = Math.sqrt(-2 * Math.log(rad) / rad); - return x1 * c; - } - - stddev = stddev || 1; - if (Math.random() < 0.81546) { - while (true) { - var sample = normRand() * stddev + target; - if (sample >= min && sample <= max) { - return sample; - } - } - } else { - return this.range(min, max); - } - } - - /* - * returns a random hex color (0 - 0xffffff) - * @return {number} - */ - - }, { - key: 'color', - value: function color() { - return this.get(0xffffff); - } - }]); - - return Random; - }(); - - module.exports = new Random(); - }, { "seedrandom": 3 }], 14: [function (require, module, exports) { - var wait = require('./wait'); - - var angle = function (_wait) { - _inherits(angle, _wait); - - /** - * animate object's {x, y} using an angle - * @param {object} object to animate - * @param {number} angle in radians - * @param {number} speed in pixels/millisecond - * @param {number} [duration=0] in milliseconds; if 0, then continues forever - * @param {object} [options] @see {@link Wait} - * @private - */ - function angle(object, _angle, speed, duration, options) { - _classCallCheck2(this, angle); - - options = options || {}; - - var _this = _possibleConstructorReturn(this, (angle.__proto__ || Object.getPrototypeOf(angle)).call(this, object, options)); - - _this.type = 'Angle'; - if (options.load) { - _this.load(options.load); - } else { - _this.angle = _angle; - _this.speed = speed; - _this.duration = duration || 0; - } - return _this; - } - - _createClass2(angle, [{ - key: "save", - value: function save() { - var save = _get(angle.prototype.__proto__ || Object.getPrototypeOf(angle.prototype), "save", this).call(this); - save.angle = this.angle; - save.speed = this.speed; - return save; - } - }, { - key: "load", - value: function load(_load) { - _get(angle.prototype.__proto__ || Object.getPrototypeOf(angle.prototype), "load", this).call(this, _load); - this.angle = _load.angle; - this.speed = _load.speed; - } - }, { - key: "calculate", - value: function calculate(elapsed) { - this.object.x += this.cos * elapsed * this.speed; - this.object.y += this.sin * elapsed * this.speed; - } - }, { - key: "reverse", - value: function reverse() { - this.angle += Math.PI; - } - }, { - key: "angle", - get: function get() { - return this._angle; - }, - set: function set(value) { - this._angle = value; - this.sin = Math.sin(this._angle); - this.cos = Math.cos(this._angle); - } - }]); - - return angle; - }(wait); - - module.exports = angle; - }, { "./wait": 24 }], 15: [function (require, module, exports) { - var Angle = require('yy-angle'); - var wait = require('./wait'); - - /** Rotates an object to face the target */ - - var face = function (_wait2) { - _inherits(face, _wait2); - - /** - * @param {object} object - * @param {Point} target - * @param {number} speed in radians/millisecond - * @param {object} [options] @see {@link Wait} - * @param {boolean} [options.keepAlive] don't stop animation when complete - */ - function face(object, target, speed, options) { - _classCallCheck2(this, face); - - options = options || {}; - - var _this2 = _possibleConstructorReturn(this, (face.__proto__ || Object.getPrototypeOf(face)).call(this, object, options)); - - _this2.type = 'Face'; - _this2.target = target; - if (options.load) { - _this2.load(options.load); - } else { - _this2.speed = speed; - } - return _this2; - } - - _createClass2(face, [{ - key: "save", - value: function save() { - if (this.options.cancel) { - return null; - } - var save = _get(face.prototype.__proto__ || Object.getPrototypeOf(face.prototype), "save", this).call(this); - save.speed = this.speed; - save.keepAlive = this.options.keepAlive; - return save; - } - }, { - key: "load", - value: function load(_load2) { - _get(face.prototype.__proto__ || Object.getPrototypeOf(face.prototype), "load", this).call(this, _load2); - this.speed = _load2.speed; - this.options.keepAlive = _load2.keepAlive; - } - }, { - key: "calculate", - value: function calculate(elapsed) { - var angle = Angle.angleTwoPoints(this.object.position, this.target); - var difference = Angle.differenceAngles(angle, this.object.rotation); - if (difference === 0) { - this.emit('done', this.object); - if (!this.options.keepAlive) { - return true; - } - } else { - var sign = Angle.differenceAnglesSign(angle, this.object.rotation); - var change = this.speed * elapsed; - var delta = change > difference ? difference : change; - this.object.rotation += delta * sign; - } - } - }]); - - return face; - }(wait); - - module.exports = face; - }, { "./wait": 24, "yy-angle": 11 }], 16: [function (require, module, exports) { - var Ease = { - list: require('./list'), - wait: require('./wait'), - to: require('./to'), - shake: require('./shake'), - tint: require('./tint'), - face: require('./face'), - angle: require('./angle'), - target: require('./target'), - movie: require('./movie'), - load: require('./load') - }; - - PIXI.extras.Ease = Ease; - - module.exports = Ease; - }, { "./angle": 14, "./face": 15, "./list": 17, "./load": 18, "./movie": 19, "./shake": 20, "./target": 21, "./tint": 22, "./to": 23, "./wait": 24 }], 17: [function (require, module, exports) { - var Events = require('eventemitter3'); - - var Angle = require('./angle'); - var Face = require('./face'); - var Load = require('./load'); - var Movie = require('./movie'); - var Shake = require('./shake'); - var Target = require('./target'); - var Tint = require('./tint'); - var To = require('./to'); - var Wait = require('./wait'); - - var Ease = function (_Events) { - _inherits(Ease, _Events); - - /** - * Main class for creating eases - * @param {object} [options] - * @param {boolean} [options.noTicker] don't add the update function to PIXI.ticker - * @param {PIXI.ticker} [options.ticker=PIXI.ticker.shared] use this PIXI.ticker for the list - * @extends eventemitter - * @fire done - * @fire each - */ - function Ease(options) { - _classCallCheck2(this, Ease); - - options = options || {}; - - var _this3 = _possibleConstructorReturn(this, (Ease.__proto__ || Object.getPrototypeOf(Ease)).call(this)); - - if (!options.noTicker) { - var ticker = options.ticker || PIXI.ticker.shared; - ticker.add(function () { - return _this3.update(ticker.elapsedMS); - }); - } - _this3.list = []; - _this3.empty = true; - _this3.removeWaiting = []; - _this3.removeAllWaiting = false; - return _this3; - } - - /** - * Add animation(s) to animation list - * @param {(object|object[])} any animation class - * @return {object} first animation - */ - - - _createClass2(Ease, [{ - key: "add", - value: function add() { - var first = void 0; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = arguments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var arg = _step.value; - - if (Array.isArray(arg)) { - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = arg[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var entry = _step2.value; - - if (!first) { - first = entry; - } - this.list.push(entry); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - } else { - first = arg; - this.list.push(arg); - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - this.empty = false; - return first; - } - - /** - * remove animation(s) - * @param {object|array} animate - the animation (or array of animations) to remove; can be null - */ - - }, { - key: "remove", - value: function remove(animate) { - if (this.inUpdate) { - this.removeWaiting.push(animate); - } else { - var index = this.list.indexOf(animate); - if (index !== -1) { - this.list.splice(index, 1); - } - } - } - - /** - * remove all animations from list - * @inherited from yy-loop - */ - - }, { - key: "removeAll", - value: function removeAll() { - if (this.inUpdate) { - this.removeAllWaiting = true; - } else { - this.list = []; - } - } - - /** - * update frame - * this is automatically added to PIXI.ticker unless options.noTicker is set - * if using options.noTicker, this should be called manually - * @param {number} elasped time in MS since last update - */ - - }, { - key: "update", - value: function update(elapsed) { - this.inUpdate = true; - for (var i = 0, _i = this.list.length; i < _i; i++) { - if (this.list[i] && this.list[i].update(elapsed)) { - this.list.splice(i, 1); - i--; - _i--; - } - } - this.emit('each', this); - if (this.list.length === 0 && !this.empty) { - this.emit('done', this); - this.empty = true; - } - this.inUpdate = false; - if (this.removeAllWaiting) { - this.removeAll(); - this.removeAllWaiting = false; - } - while (this.removeWaiting.length) { - this.remove(this.removeWaiting.pop()); - } - } - - /** - * number of animations - * @type {number} - */ - - }, { - key: "to", - - - /** - * default options for all eases - * @typedef {object} EaseOptions - * @param {object} [EaseOptions.options] - * @param {number} [EaseOptions.options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [EaseOptions.options.pause] start the animation paused - * @param {boolean|number} [EaseOptions.options.repeat] true: repeat animation forever n: repeat animation n times - * @param {boolean|number} [EaseOptions.options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * @param {Function} [EaseOptions.options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set - * @param {string|Function} [EaseOptions.options.ease] name or function from easing.js (see http://easings.net for examples) - */ - - /** - * ease parameters of object - * @param {PIXI.DisplayObject} object to animate - * @param {object} goto - parameters to animate, e.g.: {alpha: 5, scale: {3, 5}, scale: 5, rotation: Math.PI} - * @param {number} duration - time to run - * @fires done - * @fires wait - * @fires first - * @fires each - * @fires loop - * @fires reverse - */ - value: function to() { - return this.add(new (Function.prototype.bind.apply(To, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** - * animate object's {x, y} using an angle - * @param {object} object to animate - * @param {number} angle in radians - * @param {number} speed in pixels/millisecond - * @param {number} [duration=0] in milliseconds; if 0, then continues forever - * @param {object} [options] @see {@link Wait} - */ - - }, { - key: "angle", - value: function angle() { - return this.add(new (Function.prototype.bind.apply(Angle, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** helper to add to the list a new Ease.face class; see Ease.to class below for parameters */ - - }, { - key: "face", - value: function face() { - return this.add(new (Function.prototype.bind.apply(Face, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** helper to add to the list a new Ease.load class; see Ease.to class below for parameters */ - - }, { - key: "load", - value: function load() { - return this.add(new (Function.prototype.bind.apply(Load, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** helper to add to the list a new Ease.movie class; see Ease.to class below for parameters */ - - }, { - key: "movie", - value: function movie() { - return this.add(new (Function.prototype.bind.apply(Movie, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** helper to add to the list a new Ease.shake class; see Ease.to class below for parameters */ - - }, { - key: "shake", - value: function shake() { - return this.add(new (Function.prototype.bind.apply(Shake, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** helper to add to the list a new Ease.target class; see Ease.to class below for parameters */ - - }, { - key: "target", - value: function target() { - return this.add(new (Function.prototype.bind.apply(Target, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** helper to add to the list a new Ease.angle tint; see Ease.to class below for parameters */ - - }, { - key: "tint", - value: function tint() { - return this.add(new (Function.prototype.bind.apply(Tint, [null].concat(Array.prototype.slice.call(arguments))))()); - } - - /** helper to add to the list a new Ease.wait class; see Ease.to class below for parameters */ - - }, { - key: "wait", - value: function wait() { - return this.add(new (Function.prototype.bind.apply(Wait, [null].concat(Array.prototype.slice.call(arguments))))()); - } - }, { - key: "count", - get: function get() { - return this.list.length; - } - - /** - * number of active animations - * @type {number} - */ - - }, { - key: "countRunning", - get: function get() { - var count = 0; - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = this.list[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var entry = _step3.value; - - if (!entry.pause) { - count++; - } - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - return count; - } - }]); - - return Ease; - }(Events); - - module.exports = Ease; - }, { "./angle": 14, "./face": 15, "./load": 18, "./movie": 19, "./shake": 20, "./target": 21, "./tint": 22, "./to": 23, "./wait": 24, "eventemitter3": 1 }], 18: [function (require, module, exports) { - var wait = require('./wait'); - var to = require('./to'); - var tint = require('./tint'); - var shake = require('./shake'); - var angle = require('./angle'); - var face = require('./face'); - var target = require('./target'); - var movie = require('./movie'); - - /** - * restart an animation = requires a saved state - * @param {object} object(s) to animate - */ - function load(object, load) { - if (!load) { - return null; - } - var options = { load: load }; - switch (load.type) { - case 'Wait': - return new wait(object, options); - case 'To': - return new to(object, null, null, options); - case 'Tint': - return new tint(object, null, null, options); - case 'Shake': - return new shake(object, null, null, options); - case 'Angle': - return new angle(object, null, null, null, options); - case 'Face': - return new face(object[0], object[1], null, options); - case 'Target': - return new target(object[0], object[1], null, options); - case 'Movie': - return new movie(object, object[1], null, options); - } - } - - module.exports = load; - }, { "./angle": 14, "./face": 15, "./movie": 19, "./shake": 20, "./target": 21, "./tint": 22, "./to": 23, "./wait": 24 }], 19: [function (require, module, exports) { - var wait = require('./wait'); - - /** - * animate a movie of textures - */ - - var movie = function (_wait3) { - _inherits(movie, _wait3); - - /** - * @param {object} object to animate - * @param {PIXI.Texture[]} textures - * @param {number} [duration=0] time to run (use 0 for infinite duration--should only be used with customized easing functions) - * @param {object} [options] - * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [options.pause] start the animation paused - * @param {(boolean|number)} [options.repeat] true: repeat animation forever n: repeat animation n times - * @param {(boolean|number)} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * @param {(boolean|number)} [options.continue] true: continue animation with new starting values n: continue animation n times - * @param {Function} [options.load] loads an animation using a .save() object note the * parameters below cannot be loaded and must be re-set - * @param {Function} [options.ease] function from easing.js (see http://easings.net for examples) - * @emits {done} animation expires - * @emits {wait} each update during a wait - * @emits {first} first update when animation starts - * @emits {each} each update while animation is running - * @emits {loop} when animation is repeated - * @emits {reverse} when animation is reversed - */ - function movie(object, textures, duration, options) { - _classCallCheck2(this, movie); - - options = options || {}; - - var _this4 = _possibleConstructorReturn(this, (movie.__proto__ || Object.getPrototypeOf(movie)).call(this, object, options)); - - _this4.type = 'Movie'; - if (Array.isArray(object)) { - _this4.list = object; - _this4.object = _this4.list[0]; - } - if (options.load) { - _this4.load(options.load); - } else { - _this4.textures = textures; - _this4.duration = duration; - _this4.current = 0; - _this4.length = textures.length; - _this4.interval = duration / _this4.length; - _this4.isReverse = false; - _this4.restart(); - } - return _this4; - } - - _createClass2(movie, [{ - key: "save", - value: function save() { - var save = _get(movie.prototype.__proto__ || Object.getPrototypeOf(movie.prototype), "save", this).call(this); - save.goto = this.goto; - save.current = this.current; - save.length = this.length; - save.interval = this.interval; - return save; - } - }, { - key: "load", - value: function load(_load3) { - _get(movie.prototype.__proto__ || Object.getPrototypeOf(movie.prototype), "load", this).call(this, _load3); - this.goto = _load3.goto; - this.current = _load3.current; - this.interval = _load3.current; - } - }, { - key: "restart", - value: function restart() { - this.current = 0; - this.time = 0; - this.isReverse = false; - } - }, { - key: "reverse", - value: function reverse() { - this.isReverse = !this.isReverse; - } - }, { - key: "calculate", - value: function calculate() { - var index = Math.round(this.options.ease(this.time, 0, this.length - 1, this.duration)); - if (this.isReverse) { - index = this.length - 1 - index; - } - if (this.list) { - for (var i = 0; i < this.list.length; i++) { - this.list[i].texture = this.textures[index]; - } - } else { - this.object.texture = this.textures[index]; - } - } - }]); - - return movie; - }(wait); - - module.exports = movie; - }, { "./wait": 24 }], 20: [function (require, module, exports) { - var wait = require('./wait'); - - /** - * shakes an object or list of objects - */ - - var shake = function (_wait4) { - _inherits(shake, _wait4); - - /** - * @param {object|array} object or list of objects to shake - * @param {number} amount to shake - * @param {number} duration (in milliseconds) to shake - * @param {object} options (see Animate.wait) - */ - function shake(object, amount, duration, options) { - _classCallCheck2(this, shake); - - options = options || {}; - - var _this5 = _possibleConstructorReturn(this, (shake.__proto__ || Object.getPrototypeOf(shake)).call(this, object, options)); - - _this5.type = 'Shake'; - if (Array.isArray(object)) { - _this5.array = true; - _this5.list = object; - } - if (options.load) { - _this5.load(options.load); - } else { - if (_this5.list) { - _this5.start = []; - for (var i = 0; i < object.length; i++) { - var target = object[i]; - _this5.start[i] = { x: target.x, y: target.y }; - } - } else { - _this5.start = { x: object.x, y: object.y }; - } - _this5.amount = amount; - _this5.duration = duration; - } - return _this5; - } - - _createClass2(shake, [{ - key: "save", - value: function save() { - var save = _get(shake.prototype.__proto__ || Object.getPrototypeOf(shake.prototype), "save", this).call(this); - save.start = this.start; - save.amount = this.amount; - return save; - } - }, { - key: "load", - value: function load(_load4) { - _get(shake.prototype.__proto__ || Object.getPrototypeOf(shake.prototype), "load", this).call(this, _load4); - this.start = _load4.start; - this.amount = _load4.amount; - } - }, { - key: "calculate", - value: function calculate() /*elapsed*/{ - var object = this.object; - var start = this.start; - var amount = this.amount; - if (this.array) { - var list = this.list; - for (var i = 0; i < list.length; i++) { - var _object = list[i]; - var actual = start[i]; - _object.x = actual.x + Math.floor(Math.random() * amount * 2) - amount; - _object.y = actual.y + Math.floor(Math.random() * amount * 2) - amount; - } - } - object.x = start.x + Math.floor(Math.random() * amount * 2) - amount; - object.y = start.y + Math.floor(Math.random() * amount * 2) - amount; - } - }, { - key: "done", - value: function done() { - var object = this.object; - var start = this.start; - if (this.array) { - var list = this.list; - for (var i = 0; i < list.length; i++) { - var _object2 = list[i]; - var actual = start[i]; - _object2.x = actual.x; - _object2.y = actual.y; - } - } else { - object.x = start.x; - object.y = start.y; - } - } - }]); - - return shake; - }(wait); - - module.exports = shake; - }, { "./wait": 24 }], 21: [function (require, module, exports) { - var wait = require('./wait'); - - /** move an object to a target's location */ - - var target = function (_wait5) { - _inherits(target, _wait5); - - /** - * move to a target - * @param {object} object - object to animate - * @param {object} target - object needs to contain {x: x, y: y} - * @param {number} speed - number of pixels to move per millisecond - * @param {object} [options] @see {@link Wait} - * @param {boolean} [options.keepAlive] don't cancel the animation when target is reached - */ - function target(object, _target, speed, options) { - _classCallCheck2(this, target); - - options = options || {}; - - var _this6 = _possibleConstructorReturn(this, (target.__proto__ || Object.getPrototypeOf(target)).call(this, object, options)); - - _this6.type = 'Target'; - _this6.target = _target; - if (options.load) { - _this6.load(options.load); - } else { - _this6.speed = speed; - } - return _this6; - } - - _createClass2(target, [{ - key: "save", - value: function save() { - var save = _get(target.prototype.__proto__ || Object.getPrototypeOf(target.prototype), "save", this).call(this); - save.speed = this.speed; - save.keepAlive = this.options.keepAlive; - return save; - } - }, { - key: "load", - value: function load(_load5) { - _get(target.prototype.__proto__ || Object.getPrototypeOf(target.prototype), "load", this).call(this, _load5); - this.speed = _load5.speed; - this.options.keepAlive = _load5.keepAlive; - } - }, { - key: "calculate", - value: function calculate(elapsed) { - var deltaX = this.target.x - this.object.x; - var deltaY = this.target.y - this.object.y; - if (deltaX === 0 && deltaY === 0) { - this.emit('done', this.object); - if (!this.options.keepAlive) { - return true; - } - } else { - var angle = Math.atan2(deltaY, deltaX); - this.object.x += Math.cos(angle) * elapsed * this.speed; - this.object.y += Math.sin(angle) * elapsed * this.speed; - if (deltaX >= 0 !== this.target.x - this.object.x >= 0) { - this.object.x = this.target.x; - } - if (deltaY >= 0 !== this.target.y - this.object.y >= 0) { - this.object.y = this.target.y; - } - } - } - }]); - - return target; - }(wait); - - module.exports = target; - }, { "./wait": 24 }], 22: [function (require, module, exports) { - var Color = require('yy-color'); - var wait = require('./wait'); - - var tint = function (_wait6) { - _inherits(tint, _wait6); - - /** - * @param {PIXI.DisplayObject|PIXI.DisplayObject[]} object - * @param {number|number[]} tint - * @param {number} [duration] in milliseconds - * @param {object} [options] @see {@link Wait} - */ - function tint(object, _tint, duration, options) { - _classCallCheck2(this, tint); - - options = options || {}; - - var _this7 = _possibleConstructorReturn(this, (tint.__proto__ || Object.getPrototypeOf(tint)).call(this, object, options)); - - _this7.type = 'Tint'; - if (Array.isArray(object)) { - _this7.list = object; - _this7.object = _this7.list[0]; - } - _this7.duration = duration; - if (options.load) { - _this7.load(options.load); - } else if (Array.isArray(_tint)) { - _this7.tints = [_this7.object.tint].concat(_toConsumableArray(_tint)); - } else { - _this7.start = _this7.object.tint; - _this7.to = _tint; - } - return _this7; - } - - _createClass2(tint, [{ - key: "save", - value: function save() { - var save = _get(tint.prototype.__proto__ || Object.getPrototypeOf(tint.prototype), "save", this).call(this); - save.start = this.start; - save.to = this.to; - return save; - } - }, { - key: "load", - value: function load(_load6) { - _get(tint.prototype.__proto__ || Object.getPrototypeOf(tint.prototype), "load", this).call(this, _load6); - this.start = _load6.start; - this.to = _load6.to; - } - }, { - key: "calculate", - value: function calculate() { - var percent = this.options.ease(this.time, 0, 1, this.duration); - if (this.tints) { - var each = 1 / (this.tints.length - 1); - var per = each; - for (var i = 1; i < this.tints.length; i++) { - if (percent <= per) { - var color = Color.blend(1 - (per - percent) / each, this.tints[i - 1], this.tints[i]); - if (this.list) { - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = this.list[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var object = _step4.value; - - object.tint = color; - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4.return) { - _iterator4.return(); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - } else { - this.object.tint = color; - } - break; - } - per += each; - } - } else { - var _color = Color.blend(percent, this.start, this.to); - if (this.list) { - var _iteratorNormalCompletion5 = true; - var _didIteratorError5 = false; - var _iteratorError5 = undefined; - - try { - for (var _iterator5 = this.list[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var _object3 = _step5.value; - - _object3.tint = _color; - } - } catch (err) { - _didIteratorError5 = true; - _iteratorError5 = err; - } finally { - try { - if (!_iteratorNormalCompletion5 && _iterator5.return) { - _iterator5.return(); - } - } finally { - if (_didIteratorError5) { - throw _iteratorError5; - } - } - } - } else { - this.object.tint = _color; - } - } - } - }, { - key: "reverse", - value: function reverse() { - if (this.tints) { - var tints = []; - for (var i = this.tints.length - 1; i >= 0; i--) { - tints.push(this.tints[i]); - } - this.tints = tints; - } else { - var swap = this.to; - this.to = this.start; - this.start = swap; - } - } - }]); - - return tint; - }(wait); - - module.exports = tint; - }, { "./wait": 24, "yy-color": 12 }], 23: [function (require, module, exports) { - var wait = require('./wait'); - - /** animate any numeric parameter of an object or array of objects */ - - var to = function (_wait7) { - _inherits(to, _wait7); - - /** - * @private - * @param {object} object to animate - * @param {object} goto - parameters to animate, e.g.: {alpha: 5, scale: {3, 5}, scale: 5, rotation: Math.PI} - * @param {number} duration - time to run - * @param {object} [options] - * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [options.pause] start the animation paused - * @param {boolean|number} [options.repeat] true: repeat animation forever n: repeat animation n times - * @param {boolean|number} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * @param {Function} [options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set - * @param {string|Function} [options.ease] name or function from easing.js (see http://easings.net for examples) - * @emits to:done animation expires - * @emits to:wait each update during a wait - * @emits to:first first update when animation starts - * @emits to:each each update while animation is running - * @emits to:loop when animation is repeated - * @emits to:reverse when animation is reversed - */ - function to(object, goto, duration, options) { - _classCallCheck2(this, to); - - options = options || {}; - - var _this8 = _possibleConstructorReturn(this, (to.__proto__ || Object.getPrototypeOf(to)).call(this, object, options)); - - _this8.type = 'To'; - if (Array.isArray(object)) { - _this8.list = object; - _this8.object = _this8.list[0]; - } - if (options.load) { - _this8.load(options.load); - } else { - _this8.goto = goto; - _this8.fixScale(); - _this8.duration = duration; - _this8.restart(); - } - return _this8; - } - - /** - * converts scale from { scale: n } to { scale: { x: n, y: n }} - * @private - */ - - - _createClass2(to, [{ - key: "fixScale", - value: function fixScale() { - if (typeof this.goto['scale'] !== 'undefined' && !Number.isNaN(this.goto['scale'])) { - this.goto['scale'] = { x: this.goto['scale'], y: this.goto['scale'] }; - } - } - }, { - key: "save", - value: function save() { - var save = _get(to.prototype.__proto__ || Object.getPrototypeOf(to.prototype), "save", this).call(this); - save.goto = this.goto; - save.start = this.start; - save.delta = this.delta; - save.keys = this.keys; - return save; - } - }, { - key: "load", - value: function load(_load7) { - _get(to.prototype.__proto__ || Object.getPrototypeOf(to.prototype), "load", this).call(this, _load7); - this.goto = _load7.goto; - this.start = _load7.start; - this.delta = _load7.delta; - this.keys = _load7.keys; - } - }, { - key: "restart", - value: function restart() { - var i = 0; - var start = this.start = []; - var delta = this.delta = []; - var keys = this.keys = []; - var goto = this.goto; - var object = this.object; - - // loops through all keys in goto object - for (var key in goto) { - - // handles keys with one additional level e.g.: goto = {scale: {x: 5, y: 3}} - if (isNaN(goto[key])) { - keys[i] = { key: key, children: [] }; - start[i] = []; - delta[i] = []; - var j = 0; - for (var key2 in goto[key]) { - keys[i].children[j] = key2; - start[i][j] = parseFloat(object[key][key2]); - start[i][j] = this._correctDOM(key2, start[i][j]); - start[i][j] = isNaN(this.start[i][j]) ? 0 : start[i][j]; - delta[i][j] = goto[key][key2] - start[i][j]; - j++; - } - } else { - start[i] = parseFloat(object[key]); - start[i] = this._correctDOM(key, start[i]); - start[i] = isNaN(this.start[i]) ? 0 : start[i]; - delta[i] = goto[key] - start[i]; - keys[i] = key; - } - i++; - } - this.time = 0; - } - }, { - key: "reverse", - value: function reverse() { - var object = this.object; - var keys = this.keys; - var goto = this.goto; - var delta = this.delta; - var start = this.start; - - for (var i = 0, _i = keys.length; i < _i; i++) { - var key = keys[i]; - if (isNaN(goto[key])) { - for (var j = 0, _j = key.children.length; j < _j; j++) { - delta[i][j] = -delta[i][j]; - start[i][j] = parseFloat(object[key.key][key.children[j]]); - start[i][j] = isNaN(start[i][j]) ? 0 : start[i][j]; - } - } else { - delta[i] = -delta[i]; - start[i] = parseFloat(object[key]); - start[i] = isNaN(start[i]) ? 0 : start[i]; - } - } - } - }, { - key: "calculate", - value: function calculate() /*elapsed*/{ - var object = this.object; - var list = this.list; - var keys = this.keys; - var goto = this.goto; - var time = this.time; - var start = this.start; - var delta = this.delta; - var duration = this.duration; - var ease = this.options.ease; - for (var i = 0, _i = this.keys.length; i < _i; i++) { - var key = keys[i]; - if (isNaN(goto[key])) { - var key1 = key.key; - for (var j = 0, _j = key.children.length; j < _j; j++) { - var key2 = key.children[j]; - var others = object[key1][key2] = time >= duration ? start[i][j] + delta[i][j] : ease(time, start[i][j], delta[i][j], duration); - if (list) { - for (var k = 1, _k = list.length; k < _k; k++) { - list[k][key1][key2] = others; - } - } - } - } else { - var _key = keys[i]; - var _others = object[_key] = time >= duration ? start[i] + delta[i] : ease(time, start[i], delta[i], duration); - if (list) { - for (var _j2 = 1, _j3 = this.list.length; _j2 < _j3; _j2++) { - list[_j2][_key] = _others; - } - } - } - } - } - }]); - - return to; - }(wait); - - module.exports = to; - }, { "./wait": 24 }], 24: [function (require, module, exports) { - var Easing = require('penner'); - var EventEmitter = require('eventemitter3'); - - var wait = function (_EventEmitter) { - _inherits(wait, _EventEmitter); - - /** - * @param {object|object[]} object or list of objects to animate - * @param {object} [options] - * @param {number} [options.wait=0] n milliseconds before starting animation (can also be used to pause animation for a length of time) - * @param {boolean} [options.pause] start the animation paused - * @param {(boolean|number)} [options.repeat] true: repeat animation forever n: repeat animation n times - * @param {(boolean|number)} [options.reverse] true: reverse animation (if combined with repeat, then pulse) n: reverse animation n times - * - * @param {number} [options.id] user-generated id (e.g., I use it to properly load animations when an object has multiple animations running) - * @param {Function} [options.load] loads an animation using an .save() object note the * parameters below cannot be loaded and must be re-set - * @param {Function|string} [options.ease] function (or penner function name) from easing.js (see http://easings.net for examples)* - * - * @emits {done} animation expires - * @emits {wait} each update during a wait - * @emits {first} first update when animation starts - * @emits {each} each update while animation is running - * @emits {loop} when animation is repeated - * @emits {reverse} when animation is reversed - */ - function wait(object, options) { - _classCallCheck2(this, wait); - - var _this9 = _possibleConstructorReturn(this, (wait.__proto__ || Object.getPrototypeOf(wait)).call(this)); - - _this9.object = object; - _this9.options = options || {}; - _this9.type = 'Wait'; - if (_this9.options.load) { - _this9.load(_this9.options.load); - } else { - _this9.time = 0; - } - if (_this9.options.ease && typeof _this9.options.ease !== 'function') { - _this9.options.easeName = _this9.options.ease; - _this9.options.ease = Easing[_this9.options.ease]; - } - if (!_this9.options.ease) { - _this9.options.ease = Easing['linear']; - } - return _this9; - } - - _createClass2(wait, [{ - key: "save", - value: function save() { - var save = { type: this.type, time: this.time, duration: this.duration, ease: this.options.easeName }; - var options = this.options; - if (options.wait) { - save.wait = options.wait; - } - if (typeof options.id !== 'undefined') { - save.id = options.id; - } - if (options.pause) { - save.pause = options.pause; - } - if (options.repeat) { - save.repeat = options.repeat; - } - if (options.reverse) { - save.reverse = options.reverse; - } - return save; - } - }, { - key: "load", - value: function load(_load8) { - this.options.wait = _load8.wait; - this.options.pause = _load8.pause; - this.options.repeat = _load8.repeat; - this.options.reverse = _load8.reverse; - this.options.id = _load8.id; - this.options.ease = _load8.ease; - if (this.options.ease && typeof this.options.ease !== 'function') { - this.options.easeName = this.options.ease; - this.options.ease = Easing[this.options.ease]; - } - if (!this.options.ease) { - this.options.ease = Easing['linear']; - } - this.time = _load8.time; - this.duration = _load8.duration; - } - - /** - * pause this entry - * @type {boolean} - */ - - }, { - key: "end", - value: function end(leftOver) { - if (this.options.reverse) { - this.reverse(); - this.time = leftOver; - if (!this.options.repeat) { - if (this.options.reverse === true) { - this.options.reverse = false; - } else { - this.options.reverse--; - } - } else { - if (this.options.repeat !== true) { - this.options.repeat--; - } - } - this.emit('loop', this.list || this.object); - } else if (this.options.repeat) { - this.time = leftOver; - if (this.options.repeat !== true) { - this.options.repeat--; - } - this.emit('loop', this.list || this.object); - } else { - this.done(); - this.emit('done', this.list || this.object, leftOver); - // this.list = this.object = null - return true; - } - } - }, { - key: "update", - value: function update(elapsed) { - var options = this.options; - if (options.pause) { - return; - } - if (options.wait) { - options.wait -= elapsed; - if (options.wait <= 0) { - elapsed = -options.wait; - options.wait = false; - } else { - this.emit('wait', elapsed, this.list || this.object); - return; - } - } - if (!this.first) { - this.first = true; - this.emit('first', this.list || this.object); - } - this.time += elapsed; - var leftOver = 0; - var duration = this.duration; - var time = this.time; - if (duration !== 0 && time > duration) { - leftOver = time - duration; - this.time = time = duration; - } - var force = this.calculate(elapsed); - this.emit('each', elapsed, this.list || this.object, this); - if (this.type === 'Wait' || duration !== 0 && time === duration) { - return this.end(leftOver); - } - return force || time === duration; - } - - // correct certain DOM values - - }, { - key: "_correctDOM", - value: function _correctDOM(key, value) { - switch (key) { - case 'opacity': - return isNaN(value) ? 1 : value; - } - return value; - } - }, { - key: "reverse", - value: function reverse() {} - }, { - key: "calculate", - value: function calculate() {} - }, { - key: "done", - value: function done() {} - }, { - key: "pause", - set: function set(value) { - this.options.pause = value; - }, - get: function get() { - return this.options.pause; - } - }]); - - return wait; - }(EventEmitter); - - module.exports = wait; - }, { "eventemitter3": 1, "penner": 2 }], 25: [function (require, module, exports) {}, {}] }, {}, [16]); diff --git a/docs/jsdoc/Ease.html b/docs/jsdoc/Ease.html index a34c5c0..9be1629 100644 --- a/docs/jsdoc/Ease.html +++ b/docs/jsdoc/Ease.html @@ -2205,7 +2205,7 @@

diff --git a/docs/jsdoc/EventEmitter.html b/docs/jsdoc/EventEmitter.html index cb333cc..35dc500 100644 --- a/docs/jsdoc/EventEmitter.html +++ b/docs/jsdoc/EventEmitter.html @@ -1905,7 +1905,7 @@

Returns:
diff --git a/docs/jsdoc/face.html b/docs/jsdoc/face.html index d9b4ac1..e29917d 100644 --- a/docs/jsdoc/face.html +++ b/docs/jsdoc/face.html @@ -675,7 +675,7 @@

diff --git a/docs/jsdoc/global.html b/docs/jsdoc/global.html index 3cd24cf..3691138 100644 --- a/docs/jsdoc/global.html +++ b/docs/jsdoc/global.html @@ -621,7 +621,7 @@

diff --git a/docs/jsdoc/index.html b/docs/jsdoc/index.html index 11f9b50..00d0820 100644 --- a/docs/jsdoc/index.html +++ b/docs/jsdoc/index.html @@ -619,7 +619,7 @@

Simple Usage

const PIXI = require(
 
         
diff --git a/docs/jsdoc/movie.html b/docs/jsdoc/movie.html index bcf440f..899b3cb 100644 --- a/docs/jsdoc/movie.html +++ b/docs/jsdoc/movie.html @@ -918,7 +918,7 @@

diff --git a/docs/jsdoc/node_modules_eventemitter3_index.js.html b/docs/jsdoc/node_modules_eventemitter3_index.js.html index a037bd5..04a0346 100644 --- a/docs/jsdoc/node_modules_eventemitter3_index.js.html +++ b/docs/jsdoc/node_modules_eventemitter3_index.js.html @@ -721,7 +721,7 @@

node_modules/eventemitter3/index.js

diff --git a/docs/jsdoc/node_modules_eventemitter3_umd_eventemitter3.js.html b/docs/jsdoc/node_modules_eventemitter3_umd_eventemitter3.js.html index e8da956..7595f4c 100644 --- a/docs/jsdoc/node_modules_eventemitter3_umd_eventemitter3.js.html +++ b/docs/jsdoc/node_modules_eventemitter3_umd_eventemitter3.js.html @@ -725,7 +725,7 @@

node_modules/eventemitter3/umd/eventemitter3.js

diff --git a/docs/jsdoc/shake.html b/docs/jsdoc/shake.html index abc0980..9977a0a 100644 --- a/docs/jsdoc/shake.html +++ b/docs/jsdoc/shake.html @@ -604,7 +604,7 @@

diff --git a/docs/jsdoc/src_face.js.html b/docs/jsdoc/src_face.js.html index eee61d5..a4c5bd2 100644 --- a/docs/jsdoc/src_face.js.html +++ b/docs/jsdoc/src_face.js.html @@ -455,7 +455,7 @@

src/face.js

diff --git a/docs/jsdoc/src_list.js.html b/docs/jsdoc/src_list.js.html index c5dd9e4..79ed34e 100644 --- a/docs/jsdoc/src_list.js.html +++ b/docs/jsdoc/src_list.js.html @@ -610,7 +610,7 @@

src/list.js

diff --git a/docs/jsdoc/src_load.js.html b/docs/jsdoc/src_load.js.html index 2e1433e..6a50441 100644 --- a/docs/jsdoc/src_load.js.html +++ b/docs/jsdoc/src_load.js.html @@ -426,7 +426,7 @@

src/load.js

diff --git a/docs/jsdoc/src_movie.js.html b/docs/jsdoc/src_movie.js.html index 3b8ad38..1b5ad3e 100644 --- a/docs/jsdoc/src_movie.js.html +++ b/docs/jsdoc/src_movie.js.html @@ -488,7 +488,7 @@

src/movie.js

diff --git a/docs/jsdoc/src_shake.js.html b/docs/jsdoc/src_shake.js.html index b9078e0..a635d5d 100644 --- a/docs/jsdoc/src_shake.js.html +++ b/docs/jsdoc/src_shake.js.html @@ -490,7 +490,7 @@

src/shake.js

diff --git a/docs/jsdoc/src_target.js.html b/docs/jsdoc/src_target.js.html index f995bcc..4d669c3 100644 --- a/docs/jsdoc/src_target.js.html +++ b/docs/jsdoc/src_target.js.html @@ -458,7 +458,7 @@

src/target.js

diff --git a/docs/jsdoc/src_tint.js.html b/docs/jsdoc/src_tint.js.html index 821d897..8d783c0 100644 --- a/docs/jsdoc/src_tint.js.html +++ b/docs/jsdoc/src_tint.js.html @@ -502,7 +502,7 @@

src/tint.js

diff --git a/docs/jsdoc/src_to.js.html b/docs/jsdoc/src_to.js.html index 85fc8ab..a5d86a1 100644 --- a/docs/jsdoc/src_to.js.html +++ b/docs/jsdoc/src_to.js.html @@ -581,7 +581,7 @@

src/to.js

diff --git a/docs/jsdoc/src_wait.js.html b/docs/jsdoc/src_wait.js.html index 66c9c48..89a242a 100644 --- a/docs/jsdoc/src_wait.js.html +++ b/docs/jsdoc/src_wait.js.html @@ -599,7 +599,7 @@

src/wait.js

diff --git a/docs/jsdoc/target.html b/docs/jsdoc/target.html index 6b6b09f..637dbb6 100644 --- a/docs/jsdoc/target.html +++ b/docs/jsdoc/target.html @@ -679,7 +679,7 @@

diff --git a/docs/jsdoc/tint.html b/docs/jsdoc/tint.html index 0162f17..7254e94 100644 --- a/docs/jsdoc/tint.html +++ b/docs/jsdoc/tint.html @@ -629,7 +629,7 @@

diff --git a/docs/jsdoc/to.html b/docs/jsdoc/to.html index 7733798..2302b37 100644 --- a/docs/jsdoc/to.html +++ b/docs/jsdoc/to.html @@ -862,7 +862,7 @@

diff --git a/docs/jsdoc/wait.html b/docs/jsdoc/wait.html index be0b376..593b712 100644 --- a/docs/jsdoc/wait.html +++ b/docs/jsdoc/wait.html @@ -911,7 +911,7 @@

diff --git a/package.json b/package.json index 23c57a6..f3ccf02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi-ease", - "version": "1.0.1", + "version": "1.0.2", "description": "pixi.js animation library using easing functions", "browser": "dist/index.js", "scripts": { @@ -8,7 +8,7 @@ "build-demo": "browserify -o docs/index.js ./node_modules/pixi.js/dist/pixi.min.js docs/code.js ", "transpile": "babel src/ --out-dir dist --source-maps inline", "docs": "jsdoc -c .jsdoc.json", - "bundle": "browserify src/index.js -o dist/pixi-ease.js && babel -mc -o dist/pixi-ease.min.js dist/pixi-ease.js", + "bundle": "browserify dist/index.js -o bundle/pixi-ease.js && uglifyjs -mc -o bundle/pixi-ease.min.js bundle/pixi-ease.js", "prepublishOnly": "npm run transpile && npm run build-demo && npm run bundle && npm run docs" }, "repository": {