Skip to content

Instantly share code, notes, and snippets.

@frankpinto
Created October 25, 2012 02:49
Show Gist options
  • Save frankpinto/3950173 to your computer and use it in GitHub Desktop.
Save frankpinto/3950173 to your computer and use it in GitHub Desktop.
This scope?
/*
* Receive the data from the server and draw what the other client sent
*/
// Get current PaperScope context
var newScope = (function(paper, socket) {
console.log(this);
paper.install(this);
var originalLayer;
var secondLayer;
var pathsDrawn = 0;
socket.on('pathReady', function(packet) {
if (!secondLayer)
{
originalLayer = project.activeLayer;
secondLayer = new Layer();
}
else
secondLayer.activate();
console.log('About to draw here');
paths = packet.data;
while (pathsDrawn < paths.length)
{
var newPath = new Path();
newPath.strokeColor = 'red';
newPath.fillColor = 'red';
newPath.strokeWidth = 1;
newPath.closed = true;
for (index in paths[pathsDrawn].points)
newPath.add(paths[pathsDrawn].points[index]);
pathsDrawn++;
}
// Make sure it draws immediately
var canvasElement = document.getElementById('canvas');
view.draw();
// Switch back to what user is doing
originalLayer.activate();
});
return this;
})(paper, socket);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment