BezierCurveUtils.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. t = t("BaseClass");
  6. i.default = class extends t.default {
  7. constructor() {
  8. super();
  9. }
  10. static get ins() {
  11. return this.getInstance();
  12. }
  13. showSpotMove(e, t, i, s, o, a, n) {
  14. var r = this.getCurveFuncAroundSrcPoint(t, i, o);
  15. return this.tweenHelper(
  16. e.item,
  17. s,
  18. function (t) {
  19. t = r(t);
  20. (e.item.x = t.x), (e.item.y = t.y), (e.particle1.x = t.x), (e.particle1.y = t.y);
  21. },
  22. "smooth",
  23. a,
  24. n
  25. );
  26. }
  27. showCurveByRandomPoint(e, t, i, s, o, a, n) {
  28. (e.x = t.x), (e.y = t.y);
  29. var r = this.getCurveFuncAroundSrcPoint(t, i, o);
  30. this.tweenHelper(
  31. e,
  32. s,
  33. function (t) {
  34. e.isValid && ((t = r(t)), (e.x = t.x), (e.y = t.y));
  35. },
  36. "smooth",
  37. a,
  38. n
  39. );
  40. }
  41. showCurveBySurePoint(i, t, e, s, o, a = "linear", n, r, l) {
  42. var h = this.getCurveFunc(t, s, e);
  43. this.tweenHelper(
  44. i,
  45. o,
  46. function (t) {
  47. var e = h(t);
  48. (i.x = e.x), (i.y = e.y), l && l.apply(r, [t]);
  49. },
  50. a,
  51. n,
  52. r
  53. );
  54. }
  55. getCurveFuncAroundSrcPoint(t, e, i = 100) {
  56. i = this.getControllPointAroundSrcPoint(t, e, i);
  57. return this.getCurveFunc(t, e, i);
  58. }
  59. getCurveFuncAroundMidPoint(t, e) {
  60. var i = this.getControllPointAroundMidPoint(t, e);
  61. return this.getCurveFunc(t, e, i);
  62. }
  63. getControllPointAroundSrcPoint(t, e, i) {
  64. var s = Math.random() * Math.PI * 2,
  65. i = new cc.Vec2(Math.sin(s) * i, Math.cos(s) * i);
  66. return t.add(i);
  67. }
  68. getControllPointAroundMidPoint(t, e) {
  69. var i = t.sub(e).mag() / 4,
  70. t = t.lerp(e, 0.5),
  71. e = Math.random() * Math.PI * 2;
  72. return t.add(new cc.Vec2(i * Math.sin(e), i * Math.cos(e)));
  73. }
  74. getCurveFunc(i, s, o) {
  75. return function (t) {
  76. var e = (1 - t) * (1 - t) * i.x + 2 * t * (1 - t) * o.x + t * t * s.x,
  77. t = (1 - t) * (1 - t) * i.y + 2 * t * (1 - t) * o.y + t * t * s.y;
  78. return new cc.Vec2(e, t);
  79. };
  80. }
  81. phase1Easing(t) {
  82. t = (2 - t) / 2;
  83. return 1 - (Math.cos(Math.PI / 4) - Math.cos((90 * t * Math.PI) / 180)) / Math.cos(Math.PI / 4);
  84. }
  85. phase3Easing(t) {
  86. t = (t + 1) / 2;
  87. return (Math.cos(Math.PI / 4) - Math.cos((90 * t * Math.PI) / 180)) / Math.cos(Math.PI / 4);
  88. }
  89. tweenHelper(t, e, o, i, s, a) {
  90. var n = {t: 0},
  91. r =
  92. e <= 2
  93. ? cc
  94. .tween()
  95. .to(
  96. e / 2,
  97. {t: 0.5},
  98. {
  99. progress: function (t, e, i, s) {
  100. o(t + (e - t) * s);
  101. },
  102. easing: this.phase1Easing
  103. }
  104. )
  105. .call(function () {
  106. n.t = 0.5;
  107. })
  108. .to(
  109. e / 2,
  110. {t: 1},
  111. {
  112. progress: function (t, e, i, s) {
  113. o(t + (e - t) * s);
  114. },
  115. easing: this.phase3Easing
  116. }
  117. )
  118. : cc
  119. .tween()
  120. .to(
  121. 1.5,
  122. {t: 1.5 / e},
  123. {
  124. progress: function (t, e, i, s) {
  125. o(t + (e - t) * s);
  126. },
  127. easing: this.phase1Easing
  128. }
  129. )
  130. .call(function () {
  131. n.t = 1.5 / e;
  132. })
  133. .to(
  134. e - 1.5 - 0.5,
  135. {t: 1 - 0.5 / e},
  136. {
  137. progress: function (t, e, i, s) {
  138. o(t + (e - t) * s);
  139. },
  140. easing: function (t) {
  141. return t;
  142. }
  143. }
  144. )
  145. .call(function () {
  146. n.t = 1 - 0.5 / e;
  147. })
  148. .to(
  149. 0.5,
  150. {t: 1},
  151. {
  152. progress: function (t, e, i, s) {
  153. o(t + (e - t) * s);
  154. },
  155. easing: this.phase3Easing
  156. }
  157. );
  158. return cc
  159. .tween(n)
  160. .then(r)
  161. .call(function () {
  162. s && s.call(a, t);
  163. })
  164. .start();
  165. }
  166. };