Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function chunk (arr, len) {
- var chunks = [],
- i = 0,
- n = arr.length;
- while (i < n) {
- chunks.push(arr.slice(i, i += len));
- }
- return chunks;
- }
- recording = [];
- function startDrawing(start) {
- newPoints = [ start ];
- $(canvas).mousemove(function (event) {
- var next = getMousePos(canvas, event);
- if (getDist(start, next) >= MIN_POINT_DIST) {
- if (!isDrawing || isDirty) {
- newPath(start, color);
- isDrawing = true;
- isDirty = false;
- }
- ctx.lineTo(next.x, next.y);
- ctx.stroke();
- newPoints.push(next);
- start = next;
- if (newPoints.length >= MIN_UPDATE_POINTS) {
- sendUpdate(newPoints);
- newPoints = [ newPoints[newPoints.length - 1] ];
- }
- }
- });
- }
- $(canvas).unbind('mousedown');
- $(canvas).mousedown(function (event) {
- startDrawing(getMousePos(canvas, event));
- });
- function chunkSend(p){
- p.forEach(function(a){
- sendUpdateOld (a);
- });
- }
- var sendUpdateOld = sendUpdate;
- sendUpdate = function(p){
- recording.push(p);
- sendUpdateOld(p);
- }
- function randColor(){
- var chr = "0123456789abcdef";
- function r(){
- return chr[Math.round(Math.random()*chr.length)-1];
- }
- return '#' + r() +r() +r() +r() +r() +r();
- }
- var spamtimer;
- $('body').append($('<button>reset</button>').click(function(){ recording = []; }));
- $('body').append($('<button>send</button>').click(function(){ chunkSend(recording); }));
- $('body').append($('<button>spam</button>').click(function(){ spamtimer = setInterval(function(){ chunkSend(recording); color = randColor(); }, 100); }));
- $('body').append($('<button>stop</button>').click(function(){ clearInterval(spamtimer); }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement