Created
November 7, 2012 15:47
-
-
Save frankpinto/4032378 to your computer and use it in GitHub Desktop.
Receive drawing and draw it using PaperScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Receive the data from the server and draw what the other client sent | |
*/ | |
var socketedPaper = {}; | |
document.addEventListener('paperReady', function() { | |
paper.install(socketedPaper); | |
socketedPaper.socket = socket; | |
//socketedPaper.projects[0].activate(); | |
console.log('In redraw', socketedPaper); | |
// Install PaperScope context | |
var setupRedraw = (function() { | |
console.log(this); | |
var originalLayer; | |
var secondLayer; | |
var pathsDrawn = 0; | |
var redraw = (function(packet) { | |
console.log(this); | |
if (!secondLayer) | |
{ | |
originalLayer = this.projects[0].activeLayer; | |
secondLayer = new this.Layer(); | |
} | |
else | |
secondLayer.activate(); | |
paths = packet.data; | |
while (pathsDrawn < paths.length) | |
{ | |
var newPath = new this.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'); | |
this.views[0].draw(); | |
// Switch back to what user is doing | |
originalLayer.activate(); | |
}).bind(this); | |
socket.on('pathReady', redraw); | |
}).bind(socketedPaper); | |
setupRedraw(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment