Advertisement
Guest User

Untitled

a guest
May 28th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. function chunk (arr, len) {
  2.  
  3. var chunks = [],
  4. i = 0,
  5. n = arr.length;
  6.  
  7. while (i < n) {
  8. chunks.push(arr.slice(i, i += len));
  9. }
  10.  
  11. return chunks;
  12. }
  13. recording = [];
  14. function startDrawing(start) {
  15. newPoints = [ start ];
  16.  
  17. $(canvas).mousemove(function (event) {
  18. var next = getMousePos(canvas, event);
  19. if (getDist(start, next) >= MIN_POINT_DIST) {
  20. if (!isDrawing || isDirty) {
  21. newPath(start, color);
  22. isDrawing = true;
  23. isDirty = false;
  24. }
  25.  
  26. ctx.lineTo(next.x, next.y);
  27. ctx.stroke();
  28. newPoints.push(next);
  29. start = next;
  30.  
  31. if (newPoints.length >= MIN_UPDATE_POINTS) {
  32. sendUpdate(newPoints);
  33. newPoints = [ newPoints[newPoints.length - 1] ];
  34. }
  35. }
  36. });
  37. }
  38. $(canvas).unbind('mousedown');
  39. $(canvas).mousedown(function (event) {
  40. startDrawing(getMousePos(canvas, event));
  41. });
  42.  
  43. function chunkSend(p){
  44. p.forEach(function(a){
  45. sendUpdateOld (a);
  46. });
  47.  
  48. }
  49.  
  50. var sendUpdateOld = function(p){
  51. socket.emit('update', { points: p, color: color, id: 1 });
  52. }
  53.  
  54. sendUpdate = function(p){
  55. recording.push(p);
  56. sendUpdateOld(p);
  57. }
  58.  
  59. function randColor(){
  60. var chr = "0123456789abcdef";
  61. function r(){
  62. return chr[Math.round(Math.random()*chr.length)-1];
  63. }
  64. return '#' + r() +r() +r() +r() +r() +r();
  65. }
  66.  
  67. var spamtimer;
  68. $('body').append($('<button>reset</button>').click(function(){ recording = []; }));
  69. $('body').append($('<button>send</button>').click(function(){ chunkSend(recording); }));
  70. $('body').append($('<button>spam</button>').click(function(){ spamtimer = setInterval(function(){ chunkSend(recording); color = randColor(); }, 100); }));
  71. $('body').append($('<button>stop</button>').click(function(){ clearInterval(spamtimer); }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement