-
Notifications
You must be signed in to change notification settings - Fork 3
/
multiple-finger-position.html
90 lines (85 loc) · 2.47 KB
/
multiple-finger-position.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Multiple Finger Position</title>
<script src="http://js.leapmotion.com/0.2.0/leap.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<style type="text/css">
body{
margin: 0px;
padding: 0px;
position: relative;
}
body #content{
width: 100%;
height: 100%;
position: fixed;
}
canvas { background-color: #e8e8e8; }
</style>
</head>
<body>
<ul>
<li><a href="index.html">Menu</a></li>
</ul>
<h1>Multiple Finger Position</h1>
<p>Show the multiple finger position of the Leap Motion Controller.</p>
<p><a id="movie-link" href="javascript:void(0)">Show Movie</a></p>
<p id="movie"><iframe width="560" height="315" src="http://www.youtube.com/embed/H5GrQidL8xg" frameborder="0" allowfullscreen></iframe></p>
<div id="content">
<canvas></canvas>
</div>
<script>
$(function() {
$('#movie').hide();
$('#movie-link').click(function() {
$('#movie').toggle();
});
var centerX = new Array(1);
var centerY = new Array(1);
sizing();
draw(centerX, centerY);
Leap.loop(function(frame){
if (frame.fingers.length > 0) {
var x = new Array(frame.fingers.length);
var y = new Array(frame.fingers.length);
var z = new Array(frame.fingers.length);
for (var i = 0; i < frame.fingers.length; i++) {
x[i] = frame.fingers[i].tipPosition[0] + centerX[0];
y[i] = $("canvas").height() - frame.fingers[i].tipPosition[1];
z[i] = frame.fingers[i].tipPosition[2];
};
draw(x, y, z);
}
});
$(window).resize(function() {
sizing();
draw(centerX, centerY);
});
function sizing() {
$("canvas").attr({height:$("#content").height()});
$("canvas").attr({width:$("#content").width()});
centerX[0] = $("canvas").width() / 2;
centerY[0] = $("canvas").height() / 2;
}
function draw(x, y, radius) {
var canvas = $('canvas')[0];
var context = canvas.getContext('2d');
context.clearRect(0, 0, $("canvas").width(), $("canvas").height());
for (var i = 0; i < x.length; i++) {
if (typeof radius === 'undefined') {
radius = new Array(x.length);
radius[i] = 10;
} else {
radius[i] = radius[i] < 10 ? 10 : radius[i];
}
context.beginPath();
context.arc(x[i], y[i], radius[i], 0, Math.PI * 2, false);
context.stroke();
};
}
});
</script>
</body>
</html>