Created
November 11, 2012 15:37
-
-
Save zenorocha/4055243 to your computer and use it in GitHub Desktop.
tracking.js - Draw Something Example
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
var videoCamera = new tracking.VideoCamera().hide().render().renderVideoCanvas('#iphoneContainer'); | |
var plotCanvas = new tracking.Canvas().render(), | |
drawSegments = [], | |
eraseFound = false, | |
pencilFound = false, | |
segment = 0, | |
selectedElement = document.getElementById('selected'); | |
videoCamera.track({ | |
type: 'color', | |
color: 'magenta', | |
onFound: function(track) { | |
if (!drawSegments[segment]) { | |
drawSegments[segment]= []; | |
} | |
drawSegments[segment].push(track.x, track.y); | |
if (!pencilFound) { | |
selectedElement.className = 'pencil'; | |
} | |
pencilFound = true; | |
}, | |
onNotFound: function() { | |
if (pencilFound) { | |
segment++; | |
pencilFound = false; | |
selectedElement.className = ''; | |
} | |
} | |
}); | |
videoCamera.track({ | |
type: 'color', | |
color: 'cyan', | |
onFound: function(track) { | |
segment = 0; | |
drawSegments = []; | |
if (!eraseFound) { | |
selectedElement.className = 'erase'; | |
} | |
eraseFound = true; | |
}, | |
onNotFound: function() { | |
if (eraseFound) { | |
eraseFound = false; | |
selectedElement.className = ''; | |
} | |
} | |
}); | |
(function loop() { | |
for (var i = 0, len = drawSegments.length; i < len; i++) { | |
drawSpline(videoCamera.canvas.context, drawSegments[i], 0.5, false); | |
} | |
requestAnimationFrame(loop); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment