Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.js 3.9 KiB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // easing functions from "Tween.js"
  2. exports.linear = function(n){
  3. return n;
  4. };
  5. exports.inQuad = function(n){
  6. return n * n;
  7. };
  8. exports.outQuad = function(n){
  9. return n * (2 - n);
  10. };
  11. exports.inOutQuad = function(n){
  12. n *= 2;
  13. if (n < 1) return 0.5 * n * n;
  14. return - 0.5 * (--n * (n - 2) - 1);
  15. };
  16. exports.inCube = function(n){
  17. return n * n * n;
  18. };
  19. exports.outCube = function(n){
  20. return --n * n * n + 1;
  21. };
  22. exports.inOutCube = function(n){
  23. n *= 2;
  24. if (n < 1) return 0.5 * n * n * n;
  25. return 0.5 * ((n -= 2 ) * n * n + 2);
  26. };
  27. exports.inQuart = function(n){
  28. return n * n * n * n;
  29. };
  30. exports.outQuart = function(n){
  31. return 1 - (--n * n * n * n);
  32. };
  33. exports.inOutQuart = function(n){
  34. n *= 2;
  35. if (n < 1) return 0.5 * n * n * n * n;
  36. return -0.5 * ((n -= 2) * n * n * n - 2);
  37. };
  38. exports.inQuint = function(n){
  39. return n * n * n * n * n;
  40. }
  41. exports.outQuint = function(n){
  42. return --n * n * n * n * n + 1;
  43. }
  44. exports.inOutQuint = function(n){
  45. n *= 2;
  46. if (n < 1) return 0.5 * n * n * n * n * n;
  47. return 0.5 * ((n -= 2) * n * n * n * n + 2);
  48. };
  49. exports.inSine = function(n){
  50. return 1 - Math.cos(n * Math.PI / 2 );
  51. };
  52. exports.outSine = function(n){
  53. return Math.sin(n * Math.PI / 2);
  54. };
  55. exports.inOutSine = function(n){
  56. return .5 * (1 - Math.cos(Math.PI * n));
  57. };
  58. exports.inExpo = function(n){
  59. return 0 == n ? 0 : Math.pow(1024, n - 1);
  60. };
  61. exports.outExpo = function(n){
  62. return 1 == n ? n : 1 - Math.pow(2, -10 * n);
  63. };
  64. exports.inOutExpo = function(n){
  65. if (0 == n) return 0;
  66. if (1 == n) return 1;
  67. if ((n *= 2) < 1) return .5 * Math.pow(1024, n - 1);
  68. return .5 * (-Math.pow(2, -10 * (n - 1)) + 2);
  69. };
  70. exports.inCirc = function(n){
  71. return 1 - Math.sqrt(1 - n * n);
  72. };
  73. exports.outCirc = function(n){
  74. return Math.sqrt(1 - (--n * n));
  75. };
  76. exports.inOutCirc = function(n){
  77. n *= 2
  78. if (n < 1) return -0.5 * (Math.sqrt(1 - n * n) - 1);
  79. return 0.5 * (Math.sqrt(1 - (n -= 2) * n) + 1);
  80. };
  81. exports.inBack = function(n){
  82. var s = 1.70158;
  83. return n * n * (( s + 1 ) * n - s);
  84. };
  85. exports.outBack = function(n){
  86. var s = 1.70158;
  87. return --n * n * ((s + 1) * n + s) + 1;
  88. };
  89. exports.inOutBack = function(n){
  90. var s = 1.70158 * 1.525;
  91. if ( ( n *= 2 ) < 1 ) return 0.5 * ( n * n * ( ( s + 1 ) * n - s ) );
  92. return 0.5 * ( ( n -= 2 ) * n * ( ( s + 1 ) * n + s ) + 2 );
  93. };
  94. exports.inBounce = function(n){
  95. return 1 - exports.outBounce(1 - n);
  96. };
  97. exports.outBounce = function(n){
  98. if ( n < ( 1 / 2.75 ) ) {
  99. return 7.5625 * n * n;
  100. } else if ( n < ( 2 / 2.75 ) ) {
  101. return 7.5625 * ( n -= ( 1.5 / 2.75 ) ) * n + 0.75;
  102. } else if ( n < ( 2.5 / 2.75 ) ) {
  103. return 7.5625 * ( n -= ( 2.25 / 2.75 ) ) * n + 0.9375;
  104. } else {
  105. return 7.5625 * ( n -= ( 2.625 / 2.75 ) ) * n + 0.984375;
  106. }
  107. };
  108. exports.inOutBounce = function(n){
  109. if (n < .5) return exports.inBounce(n * 2) * .5;
  110. return exports.outBounce(n * 2 - 1) * .5 + .5;
  111. };
  112. // aliases
  113. exports['in-quad'] = exports.inQuad;
  114. exports['out-quad'] = exports.outQuad;
  115. exports['in-out-quad'] = exports.inOutQuad;
  116. exports['in-cube'] = exports.inCube;
  117. exports['out-cube'] = exports.outCube;
  118. exports['in-out-cube'] = exports.inOutCube;
  119. exports['in-quart'] = exports.inQuart;
  120. exports['out-quart'] = exports.outQuart;
  121. exports['in-out-quart'] = exports.inOutQuart;
  122. exports['in-quint'] = exports.inQuint;
  123. exports['out-quint'] = exports.outQuint;
  124. exports['in-out-quint'] = exports.inOutQuint;
  125. exports['in-sine'] = exports.inSine;
  126. exports['out-sine'] = exports.outSine;
  127. exports['in-out-sine'] = exports.inOutSine;
  128. exports['in-expo'] = exports.inExpo;
  129. exports['out-expo'] = exports.outExpo;
  130. exports['in-out-expo'] = exports.inOutExpo;
  131. exports['in-circ'] = exports.inCirc;
  132. exports['out-circ'] = exports.outCirc;
  133. exports['in-out-circ'] = exports.inOutCirc;
  134. exports['in-back'] = exports.inBack;
  135. exports['out-back'] = exports.outBack;
  136. exports['in-out-back'] = exports.inOutBack;
  137. exports['in-bounce'] = exports.inBounce;
  138. exports['out-bounce'] = exports.outBounce;
  139. exports['in-out-bounce'] = exports.inOutBounce;