-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawleapmotion.js
44 lines (37 loc) · 1 KB
/
drawleapmotion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Setup Leap loop with frame callback function
var controllerOptions = { enableGestures: true },
width = 960,
height = 500,
canvas = d3.select('div#container')
.append('canvas')
.attr('width', width)
.attr('height', height).node(),
ctx = canvas.getContext('2d'),
before = {},
after = {},
color = d3.scale.category20();
ctx.lineWidth = 5;
ctx.translate(width/2, height/2);
function draw() {
var a, b;
for (var id in after) {
b = before[id],
a = after[id];
if (!b) continue;
ctx.strokeStyle = color(id);
ctx.moveTo(b.tipPosition[0], -b.tipPosition[1]);
ctx.lineTo(a.tipPosition[0], -a.tipPosition[1]);
ctx.stroke();
ctx.beginPath();
}
before = after;
return true;
}
Leap.loop(controllerOptions, function(frame, done) {
after = {};
for (var i = 0; i < frame.pointables.length; i++) {
after[frame.pointables[i].id] = frame.pointables[i];
}
draw();
done();
});