源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
6.7 KiB

  1. cc = cc or {}
  2. cc.tweenfunc = cc.tweenfunc or BaseClass()
  3. function cc.tweenfunc.easeIn(time, rate)
  4. return math.pow(time, rate)
  5. end
  6. function cc.tweenfunc.easeOut(time, rate)
  7. return math.pow(time, 1 / rate)
  8. end
  9. function cc.tweenfunc.easeInOut(time, rate)
  10. time = time * 2
  11. if (time < 1) then
  12. return 0.5 * math.pow(time, rate)
  13. else
  14. return (1.0 - 0.5 * math.pow(2 - time, rate))
  15. end
  16. end
  17. -- Sine Ease
  18. function cc.tweenfunc.sineEaseIn(time)
  19. return -1 * math.cos(time * M_PI_2) + 1;
  20. end
  21. function cc.tweenfunc.sineEaseOut(time)
  22. return math.sin(time * M_PI_2);
  23. end
  24. function cc.tweenfunc.sineEaseInOut(time)
  25. return -0.5 * (math.cos(M_PI * time) - 1);
  26. end
  27. -- Quad Ease
  28. function cc.tweenfunc.quadEaseIn(time)
  29. return time * time;
  30. end
  31. function cc.tweenfunc.quadEaseOut(time)
  32. return -1 * time * (time - 2);
  33. end
  34. function cc.tweenfunc.quadEaseInOut(time)
  35. time = time*2;
  36. if (time < 1) then
  37. return 0.5 * time * time;
  38. end
  39. time = time - 1
  40. return -0.5 * (time * (time - 2) - 1);
  41. end
  42. -- Cubic Ease
  43. function cc.tweenfunc.cubicEaseIn(time)
  44. return time * time * time;
  45. end
  46. function cc.tweenfunc.cubicEaseOut(time)
  47. time = time - 1;
  48. return (time * time * time + 1);
  49. end
  50. function cc.tweenfunc.cubicEaseInOut(time)
  51. time = time*2;
  52. if (time < 1) then
  53. return 0.5 * time * time * time;
  54. end
  55. time = time - 2;
  56. return 0.5 * (time * time * time + 2);
  57. end
  58. -- Quart Ease
  59. function cc.tweenfunc.quartEaseIn(time)
  60. return time * time * time * time;
  61. end
  62. function cc.tweenfunc.quartEaseOut(time)
  63. time = time - 1;
  64. return -(time * time * time * time - 1);
  65. end
  66. function cc.tweenfunc.quartEaseInOut(time)
  67. time = time*2;
  68. if (time < 1) then
  69. return 0.5 * time * time * time * time;
  70. end
  71. time = time - 2;
  72. return -0.5 * (time * time * time * time - 2);
  73. end
  74. -- Quint Ease
  75. function cc.tweenfunc.quintEaseIn(time)
  76. return time * time * time * time * time;
  77. end
  78. function cc.tweenfunc.quintEaseOut(time)
  79. time = time - 1
  80. return (time * time * time * time * time + 1);
  81. end
  82. function cc.tweenfunc.quintEaseInOut(time)
  83. time = time*2;
  84. if (time < 1) then
  85. return 0.5 * time * time * time * time * time;
  86. end
  87. time = time - 2;
  88. return 0.5 * (time * time * time * time * time + 2);
  89. end
  90. -- Expo Ease
  91. function cc.tweenfunc.expoEaseIn(time)
  92. return time == 0 and 0 or math.pow(2, 10 * (time/1 - 1)) - 1 * 0.001;
  93. end
  94. function cc.tweenfunc.expoEaseOut(time)
  95. return time == 1 and 1 or (-math.pow(2, -10 * time / 1) + 1);
  96. end
  97. function cc.tweenfunc.expoEaseInOut(time)
  98. time = time / 0.5;
  99. if (time < 1) then
  100. time = 0.5 * math.pow(2, 10 * (time - 1));
  101. else
  102. time = 0.5 * (-math.pow(2, -10 * (time - 1)) + 2);
  103. end
  104. return time;
  105. end
  106. -- Circ Ease
  107. function cc.tweenfunc.circEaseIn(time)
  108. return -1 * (math.sqrt(1 - time * time) - 1);
  109. end
  110. function cc.tweenfunc.circEaseOut(time)
  111. time = time - 1;
  112. return math.sqrt(1 - time * time);
  113. end
  114. function cc.tweenfunc.circEaseInOut(time)
  115. time = time * 2;
  116. if (time < 1) then
  117. return -0.5 * (math.sqrt(1 - time * time) - 1);
  118. end
  119. time = time - 2;
  120. return 0.5 * (math.sqrt(1 - time * time) + 1);
  121. end
  122. function cc.tweenfunc.elasticEaseOut( time, period )
  123. local newT = 0
  124. if time == 0 or time == 1 then
  125. newT = time
  126. else
  127. local s = period / 4
  128. newT = math.pow(2, -10 * time) * math.sin((time - s) * M_PI_X_2 / period) + 1;
  129. end
  130. return newT
  131. end
  132. function cc.tweenfunc.elasticEaseIn(time, period)
  133. local newT = 0;
  134. if (time == 0 or time == 1) then
  135. newT = time;
  136. else
  137. local s = period / 4;
  138. time = time - 1;
  139. newT = -math.pow(2, 10 * time) * math.sin((time - s) * M_PI_X_2 / period);
  140. end
  141. return newT
  142. end
  143. function cc.tweenfunc.elasticEaseInOut(time, period)
  144. local newT = 0;
  145. if (time == 0 or time == 1) then
  146. newT = time;
  147. else
  148. time = time * 2;
  149. if (not period or period == 0) then
  150. period = 0.3 * 1.5;
  151. end
  152. local s = period / 4;
  153. time = time - 1;
  154. if (time < 0) then
  155. newT = -0.5 * math.pow(2, 10 * time) * math.sin((time -s) * M_PI_X_2 / period);
  156. else
  157. newT = math.pow(2, -10 * time) * math.sin((time - s) * M_PI_X_2 / period) * 0.5 + 1;
  158. end
  159. end
  160. return newT;
  161. end
  162. -- Back Ease
  163. function cc.tweenfunc.backEaseIn(time)
  164. local overshoot = 1.70158;
  165. return time * time * ((overshoot + 1) * time - overshoot);
  166. end
  167. function cc.tweenfunc.backEaseOut(time)
  168. local overshoot = 1.70158;
  169. time = time - 1;
  170. return time * time * ((overshoot + 1) * time + overshoot) + 1;
  171. end
  172. function cc.tweenfunc.backEaseInOut(time)
  173. local overshoot = 1.70158 * 1.525;
  174. time = time * 2;
  175. if (time < 1) then
  176. return (time * time * ((overshoot + 1) * time - overshoot)) / 2;
  177. else
  178. time = time - 2;
  179. return (time * time * ((overshoot + 1) * time + overshoot)) / 2 + 1;
  180. end
  181. end
  182. -- Bounce Ease
  183. function cc.tweenfunc.bounceTime(time)
  184. if (time < 1 / 2.75) then
  185. return 7.5625 * time * time;
  186. elseif (time < 2 / 2.75) then
  187. time = time - 1.5 / 2.75;
  188. return 7.5625 * time * time + 0.75;
  189. elseif(time < 2.5 / 2.75) then
  190. time = time - 2.25 / 2.75;
  191. return 7.5625 * time * time + 0.9375;
  192. end
  193. time = time - 2.625 / 2.75;
  194. return 7.5625 * time * time + 0.984375;
  195. end
  196. function cc.tweenfunc.bounceEaseIn(time)
  197. return 1 - cc.tweenfunc.bounceTime(1 - time);
  198. end
  199. function cc.tweenfunc.bounceEaseOut(time)
  200. return cc.tweenfunc.bounceTime(time);
  201. end
  202. function cc.tweenfunc.bounceEaseInOut(time)
  203. local newT = 0;
  204. if (time < 0.5) then
  205. time = time * 2;
  206. newT = (1 - cc.tweenfunc.bounceTime(1 - time)) * 0.5;
  207. else
  208. newT = cc.tweenfunc.bounceTime(time * 2 - 1) * 0.5 + 0.5;
  209. end
  210. return newT;
  211. end
  212. -- Custom Ease
  213. function cc.tweenfunc.customEase(time, easingParam)
  214. if (easingParam) then
  215. local tt = 1-time;
  216. return easingParam[1]*tt*tt*tt + 3*easingParam[3]*time*tt*tt + 3*easingParam[5]*time*time*tt + easingParam[7]*time*time*time;
  217. end
  218. return time;
  219. end
  220. function cc.tweenfunc.quadraticIn(time)
  221. return math.pow(time,2);
  222. end
  223. function cc.tweenfunc.quadraticOut(time)
  224. return -time*(time-2);
  225. end
  226. function cc.tweenfunc.quadraticInOut(time)
  227. local resultTime = time;
  228. time = time*2;
  229. if (time < 1) then
  230. resultTime = time * time * 0.5;
  231. else
  232. time = time - 1
  233. resultTime = -0.5 * (time * (time - 2) - 1);
  234. end
  235. return resultTime;
  236. end
  237. function cc.tweenfunc.bezieratFunction( a, b, c, d, t )
  238. return (math.pow(1-t,3) * a + 3*t*(math.pow(1-t,2))*b + 3*math.pow(t,2)*(1-t)*c + math.pow(t,3)*d );
  239. end