1 /**
  2  * The MIT License (MIT)
  3  *
  4  * Copyright (c) 2016 DeNA Co., Ltd.
  5  *
  6  * Permission is hereby granted, free of charge, to any person obtaining a copy
  7  * of this software and associated documentation files (the "Software"), to deal
  8  * in the Software without restriction, including without limitation the rights
  9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  * copies of the Software, and to permit persons to whom the Software is
 11  * furnished to do so, subject to the following conditions:
 12  *
 13  * The above copyright notice and this permission notice shall be included in
 14  * all copies or substantial portions of the Software.
 15  *
 16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 22  * SOFTWARE.
 23  */
 24 
 25 /// <reference path="base.js"/>
 26 
 27 /**
 28  * A class that provides interpolation methods used by tweens.
 29  * @constructor
 30  */
 31 createjs.Ease = function() {
 32 };
 33 
 34 /**
 35  * An interface that provides an interpolation method (a.k.a. an easing method)
 36  * used by tweens.
 37  * @interface
 38  */
 39 createjs.Ease.Delegate = function() {};
 40 
 41 /**
 42  * Returns the interpolated value.
 43  * @param {number} t
 44  * @return {number}
 45  */
 46 createjs.Ease.Delegate.prototype.interpolate = function(t) {
 47   /// <param type="number" name="t"/>
 48   /// <returns type="number"/>
 49 };
 50 
 51 /**
 52  * A class that implements the linear-interpolation method used by tweens.
 53  * @implements {createjs.Ease.Delegate}
 54  * @constructor
 55  */
 56 createjs.Ease.Linear = function() {
 57 };
 58 
 59 /** @override */
 60 createjs.Ease.Linear.prototype.interpolate = function(t) {
 61   /// <param type="number" name="t"/>
 62   /// <returns type="number"/>
 63   return t;
 64 };
 65 
 66 /**
 67  * A class that implements the interpolation method generated by Flash Pro.
 68  * @param {number} amount
 69  * @implements {createjs.Ease.Delegate}
 70  * @constructor
 71  */
 72 createjs.Ease.FlashPro = function(amount) {
 73   /// <param type="number" name="amount"/>
 74   createjs.assert(amount != 0);
 75 
 76   /**
 77    * @const {number}
 78    * @private
 79    */
 80   this.amount_ = amount;
 81 };
 82 
 83 /** @override */
 84 createjs.Ease.FlashPro.prototype.interpolate = function(t) {
 85   if (this.amount_ < 0) {
 86     return t * (t * -this.amount_ + 1 + this.amount_);
 87   }
 88   return t * ((2 - t) * this.amount_ + (1 - this.amount_));
 89 };
 90 
 91 /**
 92  * A specialized class of the createjs.Ease.FlashPro class with its amount 1,
 93  * which is used by games very often.
 94  * @implements {createjs.Ease.Delegate}
 95  * @constructor
 96  */
 97 createjs.Ease.FlashProOne = function() {
 98 };
 99 
100 /** @override */
101 createjs.Ease.FlashProOne.prototype.interpolate = function(t) {
102   /// <param type="number" name="t"/>
103   /// <returns type="number"/>
104   return t * (2 - t);
105 };
106 
107 /**
108  * A class that implements the polynomial-in interpolation method of the
109  * specified degree as shown in the following graph.
110  *
111  *   f(t) ^
112  *        |                   *
113  *        |                   *
114  *        |                   *
115  *        |                   *
116  *        |                  *
117  *        |                  *
118  *        |                 *
119  *        |               **
120  *        |          *****
121  *        ***********---------> t
122  *
123  * @param {number} pow
124  * @implements {createjs.Ease.Delegate}
125  * @constructor
126  */
127 createjs.Ease.PowIn = function(pow) {
128   /// <param type="number" name="pow"/>
129   /**
130    * @const {number}
131    * @private
132    */
133   this.pow_ = pow;
134 };
135 
136 /** @override */
137 createjs.Ease.PowIn.prototype.interpolate = function(t) {
138   /// <param type="number" name="t"/>
139   /// <returns type="number"/>
140   return Math.pow(t, this.pow_);
141 };
142 
143 /**
144  * A class that implements the polynomial-out interpolation method of the
145  * specified degree as shown in the following graph.
146  *
147  *   f(t) ^
148  *        *
149  *        *
150  *        *
151  *        *
152  *        |*
153  *        |*
154  *        | *
155  *        |  **
156  *        |    *****
157  *        ----------*********-> t
158  *
159  * @implements {createjs.Ease.Delegate}
160  * @constructor
161  */
162 createjs.Ease.PowOut = function(pow) {
163   /// <param type="number" name="pow"/>
164   /**
165    * @const {number}
166    * @private
167    */
168   this.pow_ = pow;
169 };
170 
171 /** @override */
172 createjs.Ease.PowOut.prototype.interpolate = function(t) {
173   /// <param type="number" name="t"/>
174   /// <returns type="number"/>
175   return 1 - Math.pow(1 - t, this.pow_);
176 };
177 
178 /**
179  * A class that implements the polynomial-in-and-out interpolation method of the
180  * specified degree as shown in the following graph.
181  *
182  *   f(t) ^
183  *        |              ******
184  *        |            **
185  *        |           *
186  *        |          *
187  *        |         *
188  *        |         *
189  *        |        *
190  *        |       *
191  *        |     **
192  *        ******--------------> t
193  *
194  * @param {number} pow
195  * @implements {createjs.Ease.Delegate}
196  * @constructor
197  */
198 createjs.Ease.PowInOut = function(pow) {
199   /// <param type="number" name="pow"/>
200   /**
201    * @const {number}
202    * @private
203    */
204   this.pow_ = pow;
205 };
206 
207 /** @override */
208 createjs.Ease.PowInOut.prototype.interpolate = function(t) {
209   /// <param type="number" name="t"/>
210   /// <returns type="number"/>
211   t *= 2;
212   if (t < 1) return 0.5 * Math.pow(t, this.pow_);
213   return 1 - 0.5 * Math.abs(Math.pow(2 - t, this.pow_));
214 };
215 
216 /**
217  * A class that implements the quadratic-in interpolation method. (This class is
218  * the specialized class of the createjs.Ease.PowIn class with its degree 2.)
219  * @implements {createjs.Ease.Delegate}
220  * @constructor
221  */
222 createjs.Ease.QuadIn = function() {
223 };
224 
225 /** @override */
226 createjs.Ease.QuadIn.prototype.interpolate = function(t) {
227   /// <param type="number" name="t"/>
228   /// <returns type="number"/>
229   return t * t;
230 };
231 
232 /**
233  * A class that implements the quadratic-out interpolation method. (This class
234  * is the specialized class of the createjs.Ease.PowOut class with its degree
235  * 2.)
236  * @implements {createjs.Ease.Delegate}
237  * @constructor
238  */
239 createjs.Ease.QuadOut = function() {
240 };
241 
242 /** @override */
243 createjs.Ease.QuadOut.prototype.interpolate = function(t) {
244   /// <param type="number" name="t"/>
245   /// <returns type="number"/>
246   var t_ = 1 - t;
247   return 1 - t_ * t_;
248 };
249 
250 /**
251  * A class that implements the quadratic-in-and-out interpolation method. (This
252  * class is the specialized class of the createjs.Ease.PowInOut class with its
253  * degree 2.)
254  * @implements {createjs.Ease.Delegate}
255  * @constructor
256  */
257 createjs.Ease.QuadInOut = function() {
258 };
259 
260 /** @override */
261 createjs.Ease.QuadInOut.prototype.interpolate = function(t) {
262   /// <param type="number" name="t"/>
263   /// <returns type="number"/>
264   t *= 2;
265   if (t < 1) return 0.5 * t * t;
266   var t_ = 2 - t;
267   return 1 - 0.5 * t_ * t_;
268 };
269 
270 /**
271  * A class that implements the cubic-in interpolation method. (This class is the
272  * specialized class of the createjs.Ease.PowIn class with its degree 3.)
273  * @implements {createjs.Ease.Delegate}
274  * @constructor
275  */
276 createjs.Ease.CubicIn = function() {
277 };
278 
279 /** @override */
280 createjs.Ease.CubicIn.prototype.interpolate = function(t) {
281   /// <param type="number" name="t"/>
282   /// <returns type="number"/>
283   return t * t * t;
284 };
285 
286 /**
287  * A class that implements the cubic-out interpolation method. (This class is
288  * the specialized class of the createjs.Ease.PowOut class with its degree 3.)
289  * @implements {createjs.Ease.Delegate}
290  * @constructor
291  */
292 createjs.Ease.CubicOut = function() {
293 };
294 
295 /** @override */
296 createjs.Ease.CubicOut.prototype.interpolate = function(t) {
297   /// <param type="number" name="t"/>
298   /// <returns type="number"/>
299   var t_ = 1 - t;
300   return 1 - t_ * t_ * t_;
301 };
302 
303 /**
304  * A class that implements the cubic-in-and-out interpolation method. (This
305  * class is the specialized class of the createjs.Ease.PowInOut class with its
306  * degree 3.)
307  * @implements {createjs.Ease.Delegate}
308  * @constructor
309  */
310 createjs.Ease.CubicInOut = function() {
311 };
312 
313 /** @override */
314 createjs.Ease.CubicInOut.prototype.interpolate = function(t) {
315   /// <param type="number" name="t"/>
316   /// <returns type="number"/>
317   t *= 2;
318   if (t < 1) return 0.5 * t * t * t;
319   var t_ = 2 - t;
320   return 1 - 0.5 * t_ * t_ * t_;
321 };
322 
323 /**
324  * A class that implements the 4th-degree-in polynomial interpolation method.
325  * (This class is the specialized class of the createjs.Ease.PowIn class with
326  * its degree 4.)
327  * @implements {createjs.Ease.Delegate}
328  * @constructor
329  */
330 createjs.Ease.QuartIn = function() {
331 };
332 
333 /** @override */
334 createjs.Ease.QuartIn.prototype.interpolate = function(t) {
335   /// <param type="number" name="t"/>
336   /// <returns type="number"/>
337   return t * t * t * t;
338 };
339 
340 /**
341  * A class that implements the 4th-degree-out polynomial interpolation method.
342  * (This class is the specialized class of the createjs.Ease.PowOut class with
343  * its degree 4.)
344  * @implements {createjs.Ease.Delegate}
345  * @constructor
346  */
347 createjs.Ease.QuartOut = function() {
348 };
349 
350 /** @override */
351 createjs.Ease.QuartOut.prototype.interpolate = function(t) {
352   /// <param type="number" name="t"/>
353   /// <returns type="number"/>
354   var t_ = 1 - t;
355   return 1 - t_ * t_ * t_ * t_;
356 };
357 
358 /**
359  * A class that implements the 4th-degree-in-and-out polynomial interpolation
360  * method. (This class is the specialized class of the createjs.Ease.PowInOut
361  * class with its degree 4.)
362  * @implements {createjs.Ease.Delegate}
363  * @constructor
364  */
365 createjs.Ease.QuartInOut = function() {
366 };
367 
368 /** @override */
369 createjs.Ease.QuartInOut.prototype.interpolate = function(t) {
370   /// <param type="number" name="t"/>
371   /// <returns type="number"/>
372   t *= 2;
373   if (t < 1) return 0.5 * t * t * t * t;
374   var t_ = 2 - t;
375   return 1 - 0.5 * t_ * t_ * t_ * t_;
376 };
377 
378 /**
379  * A class that implements the 5th-degree-in polynomial interpolation method.
380  * (This class is the specialized class of the createjs.Ease.PowIn class with
381  * its degree 5.)
382  * @implements {createjs.Ease.Delegate}
383  * @constructor
384  */
385 createjs.Ease.QuintIn = function() {
386 };
387 
388 /** @override */
389 createjs.Ease.QuintIn.prototype.interpolate = function(t) {
390   /// <param type="number" name="t"/>
391   /// <returns type="number"/>
392   return t * t * t * t * t;
393 };
394 
395 /**
396  * A class that implements the 5th-degree-out polynomial interpolation method.
397  * (This class is the specialized class of the createjs.Ease.PowOut class with
398  * its degree 5.)
399  * @implements {createjs.Ease.Delegate}
400  * @constructor
401  */
402 createjs.Ease.QuintOut = function() {
403 };
404 
405 /** @override */
406 createjs.Ease.QuintOut.prototype.interpolate = function(t) {
407   /// <param type="number" name="t"/>
408   /// <returns type="number"/>
409   var t_ = 1 - t;
410   return 1 - t_ * t_ * t_ * t_ * t_;
411 };
412 
413 /**
414  * A class that implements the 5th-degree-in-and-out polynomial interpolation
415  * method. (This class is the specialized class of the createjs.Ease.PowInOut
416  * class with its degree 5.)
417  * @implements {createjs.Ease.Delegate}
418  * @constructor
419  */
420 createjs.Ease.QuintInOut = function() {
421 };
422 
423 /** @override */
424 createjs.Ease.QuintInOut.prototype.interpolate = function(t) {
425   /// <param type="number" name="t"/>
426   /// <returns type="number"/>
427   t *= 2;
428   if (t < 1) return 0.5 * t * t * t * t * t;
429   var t_ = 2 - t;
430   return 1 - 0.5 * t_ * t_ * t_ * t_ * t_;
431 };
432 
433 /**
434  * A class that implements the trigonometric-in interpolation method.
435  * @implements {createjs.Ease.Delegate}
436  * @constructor
437  */
438 createjs.Ease.SineIn = function() {
439 };
440 
441 /** @override */
442 createjs.Ease.SineIn.prototype.interpolate = function(t) {
443   /// <param type="number" name="t"/>
444   /// <returns type="number"/>
445   return 1 - createjs.cos(t * 90);
446 };
447 
448 /**
449  * A class that implements the trigonometric-out interpolation method.
450  * @implements {createjs.Ease.Delegate}
451  * @constructor
452  */
453 createjs.Ease.SineOut = function() {
454 };
455 
456 /** @override */
457 createjs.Ease.SineOut.prototype.interpolate = function(t) {
458   /// <param type="number" name="t"/>
459   /// <returns type="number"/>
460   return createjs.sin(t * 90);
461 };
462 
463 /**
464  * A class that implements the trigonometric-in-and-out interpolation method.
465  * @implements {createjs.Ease.Delegate}
466  * @constructor
467  */
468 createjs.Ease.SineInOut = function() {
469 };
470 
471 /** @override */
472 createjs.Ease.SineInOut.prototype.interpolate = function(t) {
473   /// <param type="number" name="t"/>
474   /// <returns type="number"/>
475   return -0.5 * (createjs.cos(180 * t) - 1);
476 };
477 
478 /**
479  * A class that implements the back-in interpolation method.
480  * @implements {createjs.Ease.Delegate}
481  * @constructor
482  */
483 createjs.Ease.BackIn = function(amount) {
484   /**
485    * @const {number}
486    * @private
487    */
488   this.amount_ = amount;
489 };
490 
491 /** @override */
492 createjs.Ease.BackIn.prototype.interpolate = function(t) {
493   /// <param type="number" name="t"/>
494   /// <returns type="number"/>
495   return t * t * ((this.amount_ + 1) * t - this.amount_);
496 };
497 
498 /**
499  * A class that implements the back-out interpolation method.
500  * @implements {createjs.Ease.Delegate}
501  * @constructor
502  */
503 createjs.Ease.BackOut = function(amount) {
504   /// <param type="number" name="amplitude"/>
505   /**
506    * @const {number}
507    * @private
508    */
509   this.amount_ = amount;
510 };
511 
512 /** @override */
513 createjs.Ease.BackOut.prototype.interpolate = function(t) {
514   /// <param type="number" name="t"/>
515 /// <returns type="number"/>
516   return (--t * t * ((this.amount_ +1) * t +this.amount_) +1);
517 };
518 
519 /**
520  * A class that implements the back-in-and-out interpolation method.
521  * @implements {createjs.Ease.Delegate}
522  * @constructor
523  */
524 createjs.Ease.BackInOut = function(amount) {
525   /// <param type="number" name="amplitude"/>
526   /**
527    * @const {number}
528    * @private
529    */
530   this.amount_ = amount * 1.525;
531 };
532 
533 /** @override */
534 createjs.Ease.BackInOut.prototype.interpolate = function(t) {
535   /// <param type="number" name="t"/>
536   /// <returns type="number"/>
537   t *= 2;
538   if (t < 1) {
539     return 0.5 * (t * t * ((this.amount_ + 1) * t - this.amount_));
540   } else {
541     t -= 2;
542     return 0.5 * (t * t * ((this.amount_ + 1) * t + this.amount_) + 2);
543   };
544 };
545 
546 /**
547  * A class that implements the circular-in interpolation method.
548  * @implements {createjs.Ease.Delegate}
549  * @constructor
550  */
551 createjs.Ease.CircIn = function() {
552 };
553 
554 /** @override */
555 createjs.Ease.CircIn.prototype.interpolate = function(t) {
556   /// <param type="number" name="t"/>
557   /// <returns type="number"/>
558   return -(Math.sqrt(1 - t * t) - 1);
559 };
560 
561 /**
562  * A class that implements the circular-out interpolation method.
563  * @implements {createjs.Ease.Delegate}
564  * @constructor
565  */
566 createjs.Ease.CircOut = function() {
567 };
568 
569 /** @override */
570 createjs.Ease.CircOut.prototype.interpolate = function(t) {
571   /// <param type="number" name="t"/>
572   /// <returns type="number"/>
573   return Math.sqrt(1 - (--t) * t);
574 };
575 
576 /**
577  * A class that implements the circular-in-and-out interpolation method.
578  * @implements {createjs.Ease.Delegate}
579  * @constructor
580  */
581 createjs.Ease.CircInOut = function() {
582 };
583 
584 /** @override */
585 createjs.Ease.CircInOut.prototype.interpolate = function(t) {
586   /// <param type="number" name="t"/>
587   /// <returns type="number"/>
588   t *= 2;
589   if (t < 1) {
590     return -0.5 * (Math.sqrt(1 - t * t) - 1);
591   } else {
592     t -= 2;
593     return 0.5 * (Math.sqrt(1 - t * t) + 1);
594   }
595 };
596 
597 /**
598  * A class that implements the bounce-in interpolation method.
599  * @implements {createjs.Ease.Delegate}
600  * @constructor
601  */
602 createjs.Ease.BounceIn = function() {
603 };
604 
605 /** @override */
606 createjs.Ease.BounceIn.prototype.interpolate = function(t) {
607   /// <param type="number" name="t"/>
608   /// <returns type="number"/>
609   t = 1 - t;
610   if (t < 1 / 2.75) {
611     return 1 - (7.5625 * t * t);
612   } else if (t < 2 / 2.75) {
613     t -= 1.5 / 2.75;
614     return 1 - (7.5625 * t * t + 0.75);
615   } else if (t < 2.5 / 2.75) {
616     t -= 2.25 / 2.75;
617     return 1 - (7.5625 * t * t + 0.9375);
618   } else {
619     t -= 2.625 / 2.75;
620     return 1 - (7.5625 * t * t + 0.984375);
621   }
622 };
623 
624 /**
625  * A class that implements the bounce-out interpolation method.
626  * @implements {createjs.Ease.Delegate}
627  * @constructor
628  */
629 createjs.Ease.BounceOut = function() {
630 };
631 
632 /** @override */
633 createjs.Ease.BounceOut.prototype.interpolate = function(t) {
634   /// <param type="number" name="t"/>
635   /// <returns type="number"/>
636   if (t < 1 / 2.75) {
637     return (7.5625 * t * t);
638   } else if (t < 2 / 2.75) {
639     t -= 1.5 / 2.75;
640     return (7.5625 * t * t + 0.75);
641   } else if (t < 2.5 / 2.75) {
642     t -= 2.25 / 2.75;
643     return (7.5625 * t * t + 0.9375);
644   } else {
645     t -= 2.625 / 2.75;
646     return (7.5625 * t * t + 0.984375);
647   }
648 };
649 
650 /**
651  * A class that implements the bounce-in-and-out interpolation method.
652  * @implements {createjs.Ease.Delegate}
653  * @constructor
654  */
655 createjs.Ease.BounceInOut = function() {
656 };
657 
658 /** @override */
659 createjs.Ease.BounceInOut.prototype.interpolate = function(t) {
660   /// <param type="number" name="t"/>
661   /// <returns type="number"/>
662   if (t < 0.5) {
663     t = 1 - 2 * t;
664     if (t < 1 / 2.75) {
665       return (1 - (7.5625 * t * t)) * 0.5;
666     } else if (t < 2 / 2.75) {
667       t -= 1.5 / 2.75;
668       return (1 - (7.5625 * t * t + 0.75)) * 0.5;
669     } else if (t < 2.5 / 2.75) {
670       t -= 2.25 / 2.75;
671       return (1 - (7.5625 * t * t + 0.9375)) * 0.5;
672     } else {
673       t -= 2.625 / 2.75;
674       return (1 - (7.5625 * t * t + 0.984375)) * 0.5;
675     }
676   } else {
677     t = t * 2 - 1;
678     if (t < 1 / 2.75) {
679       return (7.5625 * t * t) * 0.5 + 0.5;
680     } else if (t < 2 / 2.75) {
681       t -= 1.5 / 2.75;
682       return (7.5625 * t * t + 0.75) * 0.5 + 0.5;
683     } else if (t < 2.5 / 2.75) {
684       t -= 2.25 / 2.75;
685       return (7.5625 * t * t + 0.9375) * 0.5 + 0.5;
686     } else {
687       t -= 2.625 / 2.75;
688       return (7.5625 * t * t + 0.984375) * 0.5 + 0.5;
689     }
690   }
691 };
692 
693 /**
694  * A class that implements the elastic-in interpolation method.
695  * @param {number} amplitude
696  * @param {number} period
697  * @implements {createjs.Ease.Delegate}
698  * @constructor
699  */
700 createjs.Ease.ElasticIn = function(amplitude, period) {
701   /// <param type="number" name="amplitude"/>
702   /// <param type="number" name="period"/>
703   /**
704    * @const {number}
705    * @private
706    */
707   this.amplitude_ = amplitude;
708 
709   /**
710    * @const {number}
711    * @private
712    */
713   this.period_ = period;
714 };
715 
716 /** @override */
717 createjs.Ease.ElasticIn.prototype.interpolate = function(t) {
718   /// <param type="number" name="t"/>
719   /// <returns type="number"/>
720   if (t == 0 || t == 1) {
721     return t;
722   }
723   var M_2PI = 3.14159265358979323846264338327950288 * 2;  // Math.PI * 2;
724   var s = this.period_ / M_2PI * Math.asin(1 / this.amplitude_);
725   --t;
726   return -(this.amplitude_ * Math.pow(2, 10 * t) * Math.sin((t - s) * M_2PI /
727       this.period_));
728 };
729 
730 /**
731  * A class that implements the elastic-out interpolation method.
732  * @param {number} amplitude
733  * @param {number} period
734  * @implements {createjs.Ease.Delegate}
735  * @constructor
736  */
737 createjs.Ease.ElasticOut = function(amplitude, period) {
738   /// <param type="number" name="amplitude"/>
739   /// <param type="number" name="period"/>
740   /**
741    * @const {number}
742    * @private
743    */
744   this.amplitude_ = amplitude;
745 
746   /**
747    * @const {number}
748    * @private
749    */
750   this.period_ = period;
751 };
752 
753 /** @override */
754 createjs.Ease.ElasticOut.prototype.interpolate = function(t) {
755   /// <param type="number" name="t"/>
756   /// <returns type="number"/>
757   if (t == 0 || t == 1) {
758     return t;
759   }
760   var M_2PI = 3.14159265358979323846264338327950288 * 2;  // Math.PI * 2;
761   var s = this.period_ / M_2PI * Math.asin(1 / this.amplitude_);
762   return (this.amplitude_ * Math.pow(2, -10 * t) *
763           Math.sin((t - s) * M_2PI / this.period_) + 1);
764 };
765 
766 /**
767  * A class that implements the elastic-in-and-out interpolation method.
768  * @param {number} amplitude
769  * @param {number} period
770  * @implements {createjs.Ease.Delegate}
771  * @constructor
772  */
773 createjs.Ease.ElasticInOut = function(amplitude, period) {
774   /// <param type="number" name="amplitude"/>
775   /// <param type="number" name="period"/>
776   /**
777    * @const {number}
778    * @private
779    */
780   this.amplitude_ = amplitude;
781 
782   /**
783    * @const {number}
784    * @private
785    */
786   this.period_ = period;
787 };
788 
789 /** @override */
790 createjs.Ease.ElasticInOut.prototype.interpolate = function(t) {
791   /// <param type="number" name="t"/>
792   /// <returns type="number"/>
793   var M_2PI = 3.14159265358979323846264338327950288 * 2;  // Math.PI * 2;
794   var s = this.period_ / M_2PI * Math.asin(1 / this.amplitude_);
795   t *= 2;
796   if (t < 1) {
797     --t;
798     return -0.5 * (this.amplitude_ * Math.pow(2, 10 * t) *
799                    Math.sin((t - s) * M_2PI / this.period_));
800   } else {
801     --t;
802     return (this.amplitude_ * Math.pow(2, -10 * t) *
803             Math.sin((t - s) * M_2PI / this.period_) * 0.5 + 1);
804   }
805 };
806 
807 /**
808  * The global instance of the linear-interpolation function.
809  * @const {createjs.Ease.Delegate}
810  */
811 createjs.Ease.linear = new createjs.Ease.Linear();
812 
813 /**
814  * The global instance of the createjs.Ease.FlashPro class with its amount 1.
815  * @const {createjs.Ease.FlashProOne}
816  * @private
817  */
818 createjs.Ease.flashProOne_ = new createjs.Ease.FlashProOne();
819 
820 /**
821  * Creates an interpolation object that emulates the easing function used by
822  * Flash Pro.
823  * @param {number} amount
824  * @return {createjs.Ease.Delegate}
825  */
826 createjs.Ease.get = function(amount) {
827   if (amount == 0) {
828     return createjs.Ease.linear;
829   }
830   if (amount >= 1) {
831     return createjs.Ease.flashProOne_;
832   }
833   if (amount <= -0.99) {
834     return createjs.Ease.quadIn;
835   }
836   return new createjs.Ease.FlashPro(amount);
837 };
838 
839 /**
840  * Creates a new createjs.Ease.PowIn instance. This method emulates the
841  * createjs.Ease.getPowIn method of TweenJS.
842  * @param {number} pow
843  * @return {createjs.Ease.Delegate}
844  */
845 createjs.Ease.getPowIn = function(pow) {
846   return new createjs.Ease.PowIn(pow);
847 };
848 
849 
850 /**
851  * Creates a new createjs.Ease.PowOut instance. This method emulates the
852  * createjs.Ease.getPowOut method of TweenJS.
853  * @param {number} pow
854  * @return {createjs.Ease.Delegate}
855  */
856 createjs.Ease.getPowOut = function(pow) {
857   return new createjs.Ease.PowOut(pow);
858 };
859 
860 /**
861  * Creates a new createjs.Ease.PowInOut instance. This method emulates the
862  * createjs.Ease.getPowInOut method of TweenJS.
863  * @param {number} pow
864  * @return {createjs.Ease.Delegate}
865  */
866 createjs.Ease.getPowInOut = function(pow) {
867   return new createjs.Ease.PowInOut(pow);
868 };
869 
870 /**
871  * The global instance of the createjs.Ease.QuadInOut class. This property
872  * emulates the createjs.Ease.quadInOut property of TweenJS.
873  * @const {createjs.Ease.QuadIn}
874  */
875 createjs.Ease.quadIn = new createjs.Ease.QuadIn();
876 
877 /**
878  * The global instance of the createjs.Ease.QuadOut class. This property
879  * emulates the createjs.Ease.quadOut property of TweenJS.
880  * @const {createjs.Ease.QuadOut}
881  */
882 createjs.Ease.quadOut = new createjs.Ease.QuadOut();
883 
884 /**
885  * The global instance of the createjs.Ease.QuadInOut class. This property
886  * emulates the createjs.Ease.quadInOut property of TweenJS.
887  * @const {createjs.Ease.QuadInOut}
888  */
889 createjs.Ease.quadInOut = new createjs.Ease.QuadInOut();
890 
891 /**
892  * The global instance of the createjs.Ease.CubicIn class. This property
893  * emulates the createjs.Ease.cubicIn property of TweenJS.
894  * @const {createjs.Ease.CubicIn}
895  */
896 createjs.Ease.cubicIn = new createjs.Ease.CubicIn();
897 
898 /**
899  * The global instance of the createjs.Ease.CubicOut class. This property
900  * emulates the createjs.Ease.cubiccOut property of TweenJS.
901  * @const {createjs.Ease.CubicOut}
902  */
903 createjs.Ease.cubicOut = new createjs.Ease.CubicOut();
904 
905 /**
906  * The global instance of the createjs.Ease.CubicInOut class. This property
907  * emulates the createjs.Ease.cubicInOut property of TweenJS.
908  * @const {createjs.Ease.CubicInOut}
909  */
910 createjs.Ease.cubicInOut = new createjs.Ease.CubicInOut();
911 
912 /**
913  * The global instance of the createjs.Ease.QuartIn class. This property
914  * emulates the createjs.Ease.quartIn property of TweenJS.
915  * @const {createjs.Ease.QuartIn}
916  */
917 createjs.Ease.quartIn = new createjs.Ease.QuartIn();
918 
919 /**
920  * The global instance of the createjs.Ease.QuartOut class. This property
921  * emulates the createjs.Ease.quartOut property of TweenJS.
922  * @const {createjs.Ease.QuartOut}
923  */
924 createjs.Ease.quartOut = new createjs.Ease.QuartOut();
925 
926 /**
927  * The global instance of the createjs.Ease.QuartInOut class. This property
928  * emulates the createjs.Ease.quartInOut property of TweenJS.
929  * @const {createjs.Ease.QuartInOut}
930  */
931 createjs.Ease.quartInOut = new createjs.Ease.QuartInOut();
932 
933 /**
934  * The global instance of the createjs.Ease.QuintIn class. This property
935  * emulates the createjs.Ease.quintIn property of TweenJS.
936  * @const {createjs.Ease.QuintIn}
937  */
938 createjs.Ease.quintIn = new createjs.Ease.QuintIn();
939 
940 /**
941  * The global instance of the createjs.Ease.QuintOut class. This property
942  * emulates the createjs.Ease.quintOut property of TweenJS.
943  * @const {createjs.Ease.QuintOut}
944  */
945 createjs.Ease.quintOut = new createjs.Ease.QuintOut();
946 
947 /**
948  * The global instance of the createjs.Ease.QuintInOut class. This property
949  * emulates the createjs.Ease.quintInOut property of TweenJS.
950  * @const {createjs.Ease.QuintInOut}
951  */
952 createjs.Ease.quintInOut = new createjs.Ease.QuintInOut();
953 
954 /**
955  * The global instance of the createjs.Ease.SineIn class. This property emulates
956  * the createjs.Ease.sineIn property of TweenJS.
957  * @const {createjs.Ease.SineIn}
958  */
959 createjs.Ease.sineIn = new createjs.Ease.SineIn();
960 
961 /**
962  * The global instance of the createjs.Ease.SineOut class. This property
963  * emulates the createjs.Ease.sineOut property of TweenJS.
964  * @const {createjs.Ease.SineOut}
965  */
966 createjs.Ease.sineOut = new createjs.Ease.SineOut();
967 
968 /**
969  * The global instance of the createjs.Ease.SineInOut class. This property
970  * emulates the createjs.Ease.sineInOut property of TweenJS.
971  * @const {createjs.Ease.SineInOut}
972  */
973 createjs.Ease.sineInOut = new createjs.Ease.SineInOut();
974 
975 /**
976  * Creates a new createjs.Ease.BackIn instance. This method emulates the
977  * createjs.Ease.getBackIn method of TweenJS.
978  * @param {number} amount
979  * @return {createjs.Ease.BackIn}
980  */
981 createjs.Ease.getBackIn = function(amount) {
982   return new createjs.Ease.BackIn(amount);
983 };
984 
985 /**
986  * The global instance of the createjs.Ease.BackIn class. This property emulates
987  * the createjs.Ease.backIn property of TweenJS.
988  * @const {createjs.Ease.BackIn}
989  */
990 createjs.Ease.backIn = new createjs.Ease.BackIn(1.7);
991 
992 /**
993  * Creates a new createjs.Ease.BackOut instance. This method emulates the
994  * createjs.Ease.getBackOut method of TweenJS.
995  * @param {number} amount
996  * @return {createjs.Ease.BackOut}
997  */
998 createjs.Ease.getBackOut = function(amount) {
999   return new createjs.Ease.BackOut(amount);
1000 };
1001 
1002 /**
1003  * The global instance of the createjs.Ease.BackOut class. This property
1004  * emulates the createjs.Ease.backOut property of TweenJS.
1005  * @const {createjs.Ease.BackOut}
1006  */
1007 createjs.Ease.backOut = new createjs.Ease.BackOut(1.7);
1008 
1009 /**
1010  * Creates a new createjs.Ease.BackInOut instance. This method emulates the
1011  * createjs.Ease.getBackInOut method of TweenJS.
1012  * @param {number} amount
1013  * @return {createjs.Ease.BackInOut}
1014  */
1015 createjs.Ease.getBackInOut = function(amount) {
1016   return new createjs.Ease.BackInOut(amount);
1017 };
1018 
1019 /**
1020  * The global instance of the createjs.Ease.BackInOut class. This property
1021  * emulates the createjs.Ease.backInOut property of TweenJS.
1022  * @const {createjs.Ease.BackInOut}
1023  */
1024 createjs.Ease.backInOut = new createjs.Ease.BackInOut(1.7);
1025 
1026 /**
1027  * The global instance of the createjs.Ease.CircIn class. This property emulates
1028  * the createjs.Ease.circIn property of TweenJS.
1029  * @const {createjs.Ease.CircIn}
1030  */
1031 createjs.Ease.circIn = new createjs.Ease.CircIn();
1032 
1033 /**
1034  * The global instance of the createjs.Ease.CircOut class. This property
1035  * emulates the createjs.Ease.circOut property of TweenJS.
1036  * @const {createjs.Ease.CircOut}
1037  */
1038 createjs.Ease.circOut = new createjs.Ease.CircOut();
1039 
1040 /**
1041  * The global instance of the createjs.Ease.CircInOut class. This property
1042  * emulates the createjs.Ease.circInOut property of TweenJS.
1043  * @const {createjs.Ease.CircInOut}
1044  */
1045 createjs.Ease.circInOut = new createjs.Ease.CircInOut();
1046 
1047 /**
1048  * The global instance of the createjs.Ease.BounceIn class. This property
1049  * emulates the createjs.Ease.bounceIn property of TweenJS.
1050  * @const {createjs.Ease.BounceIn}
1051  */
1052 createjs.Ease.bounceIn = new createjs.Ease.BounceIn();
1053 
1054 /**
1055  * The global instance of the createjs.Ease.BounceOut class. This property
1056  * emulates the createjs.Ease.bounceOut property of TweenJS.
1057  * @const {createjs.Ease.BounceOut}
1058  */
1059 createjs.Ease.bounceOut = new createjs.Ease.BounceOut();
1060 
1061 /**
1062  * The global instance of the createjs.Ease.BounceInOut class. This property
1063  * emulates the createjs.Ease.bounceInOut property of TweenJS.
1064  * @const {createjs.Ease.BounceInOut}
1065  */
1066 createjs.Ease.bounceInOut = new createjs.Ease.BounceInOut();
1067 
1068 /**
1069  * Creates a new createjs.Ease.ElasticIn instance. This method emulates the
1070  * createjs.Ease.getElasticIn method of TweenJS.
1071  * @param {number} amplitude
1072  * @param {number} period
1073  * @return {createjs.Ease.ElasticIn}
1074  */
1075 createjs.Ease.getElasticIn = function(amplitude, period) {
1076   return new createjs.Ease.ElasticIn(amplitude, period);
1077 };
1078 
1079 /**
1080  * The global instance of the createjs.Ease.ElasticIn class with its amplitude 1
1081  * and period 0.3. This property emulates the createjs.Ease.elasticIn property
1082  * of TweenJS.
1083  * @const {createjs.Ease.ElasticIn}
1084  */
1085 createjs.Ease.elasticIn = new createjs.Ease.ElasticIn(1, 0.3);
1086 
1087 /**
1088  * Creates a new createjs.Ease.ElasticOut instance. This method emulates the
1089  * createjs.Ease.getElasticOut method of TweenJS.
1090  * @param {number} amplitude
1091  * @param {number} period
1092  * @return {createjs.Ease.ElasticOut}
1093  */
1094 createjs.Ease.getElasticOut = function(amplitude, period) {
1095   return new createjs.Ease.ElasticOut(amplitude, period);
1096 };
1097 
1098 /**
1099  * The global instance of the createjs.Ease.ElasticOut class with its amplitude
1100  * 1 and period 0.3. This property emulates the createjs.Ease.elasticOut
1101  * property of TweenJS.
1102  * @const {createjs.Ease.ElasticOut}
1103  */
1104 createjs.Ease.elasticOut = new createjs.Ease.ElasticOut(1, 0.3);
1105 
1106 /**
1107  * Creates a new createjs.Ease.ElasticInOut instance. This method emulates the
1108  * createjs.Ease.getElasticInOut method of TweenJS.
1109  * @param {number} amplitude
1110  * @param {number} period
1111  * @return {createjs.Ease.ElasticInOut}
1112  */
1113 createjs.Ease.getElasticInOut = function(amplitude, period) {
1114   return new createjs.Ease.ElasticInOut(amplitude, period);
1115 };
1116 
1117 /**
1118  * The global instance of the createjs.Ease.ElasticInOut class with its
1119  * amplitude 1 and period ~0.45. This property emulates the
1120  * createjs.Ease.elasticInOut property of TweenJS.
1121  * @const {createjs.Ease.ElasticInOut}
1122  * @deprecated
1123  */
1124 createjs.Ease.elasticInOut = new createjs.Ease.ElasticInOut(1, 0.3 * 1.5);
1125 
1126 /**
1127  * The all easing methods defined in the original CreateJS.
1128  * @const {Object.<string,Function>}
1129  * @private
1130  */
1131 createjs.Ease.ALL_METHODS_ = {
1132   'linear': createjs.Ease.linear,
1133   'none': createjs.Ease.linear,
1134   'get': createjs.Ease.get,
1135   'getPowIn': createjs.Ease.getPowIn,
1136   'getPowOut': createjs.Ease.getPowOut,
1137   'getPowInOut': createjs.Ease.getPowInOut,
1138   'quadIn': createjs.Ease.quadIn,
1139   'quadOut': createjs.Ease.quadOut,
1140   'quadInOut': createjs.Ease.quadInOut,
1141   'cubicIn': createjs.Ease.cubicIn,
1142   'cubicOut': createjs.Ease.cubicOut,
1143   'cubicInOut': createjs.Ease.cubicInOut,
1144   'quartIn': createjs.Ease.quartIn,
1145   'quartOut': createjs.Ease.quartOut,
1146   'quartInOut': createjs.Ease.quartInOut,
1147   'quintIn': createjs.Ease.quintIn,
1148   'quintOut': createjs.Ease.quintOut,
1149   'quintInOut': createjs.Ease.quintInOut,
1150   'sineIn': createjs.Ease.sineIn,
1151   'sineOut': createjs.Ease.sineOut,
1152   'sineInOut': createjs.Ease.sineInOut,
1153   'getBackIn': createjs.Ease.getBackIn,
1154   'backIn': createjs.Ease.backIn,
1155   'getBackOut': createjs.Ease.getBackOut,
1156   'backOut': createjs.Ease.backOut,
1157   'getBackInOut': createjs.Ease.getBackInOut,
1158   'backInOut': createjs.Ease.backInOut,
1159   'circIn': createjs.Ease.circIn,
1160   'circOut': createjs.Ease.circOut,
1161   'circInOut': createjs.Ease.circInOut,
1162   'bounceIn': createjs.Ease.bounceIn,
1163   'bounceOut': createjs.Ease.bounceOut,
1164   'bounceInOut': createjs.Ease.bounceInOut,
1165   'getElasticIn': createjs.Ease.getElasticIn,
1166   'elasticIn': createjs.Ease.elasticIn,
1167   'getElasticOut': createjs.Ease.getElasticOut,
1168   'elasticOut': createjs.Ease.elasticOut,
1169   'getElasticInOut': createjs.Ease.getElasticInOut,
1170   'elasticInOut': createjs.Ease.elasticInOut
1171 };
1172 
1173 /**
1174  * The all easing methods defined in the original CreateJS.
1175  * @const {Object.<string,Function>}
1176  * @private
1177  */
1178 createjs.Ease.MINIMAL_METHODS_ = {
1179   'linear': createjs.Ease.linear,
1180   'none': createjs.Ease.linear,
1181   'get': createjs.Ease.get,
1182   'quadIn': createjs.Ease.quadIn,
1183   'quadOut': createjs.Ease.quadOut,
1184   'quadInOut': createjs.Ease.quadInOut,
1185   'cubicIn': createjs.Ease.cubicIn,
1186   'cubicOut': createjs.Ease.cubicOut,
1187   'cubicInOut': createjs.Ease.cubicInOut
1188 };
1189 
1190 /**
1191  * A table of exported functions.
1192  * @type {Object}
1193  * @const
1194  */
1195 createjs.Ease.exports =
1196     createjs.exportStatic('createjs.Ease', createjs.Ease.MINIMAL_METHODS_);
1197