Advertisement
Guest User

Untitled

a guest
May 28th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. var armSize = 50;
  2. var posX = 0;
  3. var posY = 0;
  4. var stopSpams = false;
  5. var current = 0;
  6.  
  7. function drawArm()
  8. {
  9. if(stopSpams)
  10. return;
  11.  
  12. var send = [];
  13. if(current == 0)
  14. { // upper left
  15. send.push({x: posX + 0, y: posY + 0});
  16. send.push({x: posX + 0, y: posY + armSize});
  17. send.push({x: posX + armSize, y: posY + armSize});
  18. }
  19.  
  20. if(current == 1)
  21. { // upper right
  22. send.push({x: posX + armSize * 2, y: posY + 0});
  23. send.push({x: posX + armSize, y: posY + 0});
  24. send.push({x: posX + armSize, y: posY + armSize});
  25. }
  26.  
  27. if(current == 2)
  28. { // lower right
  29. send.push({x: posX + armSize * 2, y: posY + armSize * 2});
  30. send.push({x: posX + armSize * 2, y: posY + armSize});
  31. send.push({x: posX + armSize, y: posY + armSize});
  32. }
  33.  
  34. if(current == 3)
  35. { // lower left
  36. send.push({x: posX + 0, y: posY + armSize * 2});
  37. send.push({x: posX + armSize, y: posY + armSize * 2});
  38. send.push({x: posX + armSize, y: posY + armSize});
  39. }
  40.  
  41. if(current == 4)
  42. {
  43. // randomize posX, posY, set timeout and return
  44. posX = Math.floor(Math.random() * 1200);
  45. posY = Math.floor(Math.random() * 700);
  46. current = 0;
  47. setTimeout(drawArm, 100);
  48. return;
  49. }
  50.  
  51. socket.emit('update', { points: send, color: color, id: 1 });
  52.  
  53. current++;
  54. drawArm();
  55. }
  56.  
  57.  
  58. function chaim()
  59. {
  60. if(stopSpams)
  61. return;
  62.  
  63. var send = [];
  64. if(current == 0)
  65. { // top triangle
  66. send.push({x: posX + armSize * 2, y: posY + 0}); // top point
  67. send.push({x: posX + 0, y: posY + armSize * 4}); // left point
  68. send.push({x: posX + armSize * 4, y: posY + armSize * 4}); // right point
  69. send.push({x: posX + armSize * 2, y: posY + 0}); // back to top
  70. }
  71.  
  72. if(current == 1)
  73. { // bottom triangle
  74. send.push({x: posX + armSize * 2, y: posY + armSize * 5}); // bottom point
  75. send.push({x: posX + 0, y: posY + armSize * 1}); // left point
  76. send.push({x: posX + armSize * 4, y: posY + armSize * 1}); // right point
  77. send.push({x: posX + armSize * 2, y: posY + armSize * 5}); // bottom point
  78. }
  79.  
  80. if(current == 2)
  81. {
  82. // randomize posX, posY, set timeout and return
  83. posX = Math.floor(Math.random() * 1200);
  84. posY = Math.floor(Math.random() * 700);
  85. current = 0;
  86. setTimeout(chaim, 100);
  87. return;
  88. }
  89.  
  90. socket.emit('update', { points: send, color: color, id: 1 });
  91.  
  92. current++;
  93. chaim();
  94. }
  95.  
  96. function chunk (arr, len) {
  97.  
  98. var chunks = [],
  99. i = 0,
  100. n = arr.length;
  101.  
  102. while (i < n) {
  103. chunks.push(arr.slice(i, i += len));
  104. }
  105.  
  106. return chunks;
  107. }
  108. recording = [];
  109. function startDrawing(start) {
  110. newPoints = [ start ];
  111.  
  112. $(canvas).mousemove(function (event) {
  113. var next = getMousePos(canvas, event);
  114. if (getDist(start, next) >= MIN_POINT_DIST) {
  115. if (!isDrawing || isDirty) {
  116. newPath(start, color);
  117. isDrawing = true;
  118. isDirty = false;
  119. }
  120.  
  121. ctx.lineTo(next.x, next.y);
  122. ctx.stroke();
  123. newPoints.push(next);
  124. start = next;
  125.  
  126. if (newPoints.length >= MIN_UPDATE_POINTS) {
  127. sendUpdate(newPoints);
  128. newPoints = [ newPoints[newPoints.length - 1] ];
  129. }
  130. }
  131. });
  132. }
  133. $(canvas).unbind('mousedown');
  134. $(canvas).mousedown(function (event) {
  135. startDrawing(getMousePos(canvas, event));
  136. });
  137.  
  138. function chunkSend(p){
  139. p.forEach(function(a)
  140. {
  141. sendUpdateOld (a);
  142. });
  143. }
  144.  
  145. var sendUpdateOld = function(p){
  146. socket.emit('update', { points: p, color: color, id: 1 });
  147. }
  148.  
  149. sendUpdate = function(p){
  150. recording.push(p);
  151. sendUpdateOld(p);
  152. }
  153.  
  154. function randColor(){
  155. var chr = "0123456789abcdef";
  156. function r(){
  157. return chr[Math.round(Math.random()*chr.length)-1];
  158. }
  159. return '#' + r() +r() +r() +r() +r() +r();
  160. }
  161.  
  162. var spamtimer;
  163. $('body').append($('<button>reset</button>').click(function(){ recording = []; }));
  164. $('body').append($('<button>send</button>').click(function(){ chunkSend(recording); }));
  165. $('body').append($('<button>spam</button>').click(function(){ spamtimer = setInterval(function(){ chunkSend(recording); color = randColor(); }, 100); }));
  166. $('body').append($('<button>stop</button>').click(function(){ stopSpams = true; current = 0; clearInterval(spamtimer); }));
  167. $('body').append($('<button>swastika</button>').click(function(){ stopSpams = false; current = 0; drawArm(); }));
  168. $('body').append($('<button>david star</button>').click(function(){ stopSpams = false; current = 0; chaim(); }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement