Skip to content

Commit 0033747

Browse files
Improving draw something example
1 parent 01b194c commit 0033747

1 file changed

Lines changed: 40 additions & 9 deletions

File tree

examples/move_draw_something.html

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,55 @@
3131
</head>
3232
<body>
3333

34-
<div id="iphoneContainer"></div>
34+
<div id="iphoneContainer"></div>
3535

3636
<script>
3737
var videoCamera = new tracking.VideoCamera().hide().render().renderVideoCanvas('#iphoneContainer');
3838

3939
var plotCanvas = new tracking.Canvas().render(),
40-
drawPoints = [];
40+
segment = 0,
41+
found = false,
42+
drawSegments = [];
4143

4244
videoCamera.track(
43-
{
44-
type: 'color',
45-
color: 'magenta',
46-
callback: function(track) {
47-
drawPoints.push(track.x, track.y);
48-
drawSpline(videoCamera.canvas.context, drawPoints, 0.5, false);
45+
{
46+
type: 'color',
47+
color: 'magenta',
48+
onFound: function(track) {
49+
if (!drawSegments[segment]) {
50+
drawSegments[segment]= [];
51+
}
52+
53+
drawSegments[segment].push(track.x, track.y);
54+
55+
found = true;
56+
},
57+
onNotFound: function() {
58+
if (found) {
59+
segment++;
60+
found = false;
61+
}
62+
}
63+
}
64+
);
65+
66+
videoCamera.track(
67+
{
68+
type: 'color',
69+
color: 'cyan',
70+
onFound: function(track) {
71+
segment = 0;
72+
drawSegments = [];
73+
}
4974
}
50-
}
5175
);
76+
77+
(function loop() {
78+
for (var i = 0, len = drawSegments.length; i < len; i++) {
79+
drawSpline(videoCamera.canvas.context, drawSegments[i], 0.5, false);
80+
}
81+
requestAnimationFrame(loop);
82+
}());
5283
</script>
5384

5485
</body>

0 commit comments

Comments
 (0)