Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

121 wiersze
2.9 KiB

  1. define([
  2. 'js/rendering/renderer'/*,
  3. 'picture'*/
  4. ], function (
  5. renderer/*,
  6. picture*/
  7. ) {
  8. return {
  9. build: function (config) {
  10. let obj = {
  11. lines: []
  12. };
  13. let maxDeviate = config.maxDeviate || (scale * 0.3);
  14. let fx = config.fromX * scale;
  15. let fy = config.fromY * scale;
  16. let tx = config.toX * scale;
  17. let ty = config.toY * scale;
  18. let angle = Math.atan2(ty - fy, tx - fx);
  19. let distance = Math.sqrt(Math.pow(tx - fx, 2) + Math.pow(ty - fy, 2));
  20. let divDistance = Math.min(20, distance);
  21. let divisions = config.divisions || Math.max(1, distance / divDistance);
  22. let x = fx;
  23. let y = fy;
  24. for (let i = 0; i < divisions; i++) {
  25. let line = {
  26. sprites: []
  27. };
  28. let ntx = fx + (Math.cos(angle) * (divDistance * i)) + ~~(Math.random() * (maxDeviate * 2)) - maxDeviate;
  29. let nty = fy + (Math.sin(angle) * (divDistance * i)) + ~~(Math.random() * (maxDeviate * 2)) - maxDeviate;
  30. if (i === divisions - 1) {
  31. ntx = tx;
  32. nty = ty;
  33. }
  34. let nAngle = Math.atan2(nty - y, ntx - x);
  35. let steps = ~~(Math.sqrt(Math.pow(ntx - x, 2) + Math.pow(nty - y, 2)) / scaleMult);
  36. let patches = {};
  37. for (let j = 0; j < steps; j++) {
  38. let alpha = 1;
  39. if ((config.colors) && (i === divisions - 1) && (j > (steps * 0.75)))
  40. alpha = 1 - (j / steps);
  41. let c = (config.colors || [0xffeb38, 0xfaac45, 0xfafcfc])[~~(Math.random() * (config.colors ? config.colors.length : 3))];
  42. line.sprites.push(renderer.buildRectangle({
  43. x: ~~(x / scaleMult) * scaleMult,
  44. y: ~~(y / scaleMult) * scaleMult,
  45. w: scaleMult,
  46. h: scaleMult,
  47. alpha: alpha,
  48. color: c,
  49. layerName: 'effects'
  50. }));
  51. let xx = x;
  52. let yy = y;
  53. if ((!patches[xx + '-' + yy]) && (!config.colors)) {
  54. patches[xx + '-' + yy] = 1;
  55. let lightPatch = renderer.buildObject({
  56. sheetName: 'white',
  57. x: 0,
  58. y: 0,
  59. cell: 0,
  60. layerName: 'lightPatches'
  61. });
  62. lightPatch.alpha = Math.random() * 0.5;
  63. lightPatch.tint = '0xffffff';
  64. lightPatch.x = ~~((xx - scaleMult) / scaleMult) * scaleMult;
  65. lightPatch.y = ~~((yy - scaleMult) / scaleMult) * scaleMult;
  66. lightPatch.width = scaleMult * 3;
  67. lightPatch.height = scaleMult * 3;
  68. lightPatch.blendMode = PIXI.BLEND_MODES.OVERLAY;
  69. lightPatch.pluginName = 'picture';
  70. line.sprites.push(lightPatch);
  71. }
  72. x += Math.cos(nAngle) * scaleMult;
  73. y += Math.sin(nAngle) * scaleMult;
  74. }
  75. obj.lines.push(line);
  76. }
  77. return obj;
  78. },
  79. toHex: function rgbToHex (r, g, b) {
  80. let componentToHex = function (c) {
  81. let hex = c.toString(16);
  82. return hex.length === 1 ? '0' + hex : hex;
  83. };
  84. return '0x' + componentToHex(r) + componentToHex(g) + componentToHex(b);
  85. },
  86. update: function (obj) {
  87. },
  88. destroy: function (obj) {
  89. obj.lines.forEach(function (l) {
  90. l.sprites.forEach(function (s) {
  91. s.parent.removeChild(s);
  92. });
  93. });
  94. }
  95. };
  96. });