-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathone-finger-position.html
82 lines (77 loc) · 2.08 KB
/
one-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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>One 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>One Finger Position</h1>
<p>Show the one 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/Xmiqf66Qr9A" frameborder="0" allowfullscreen></iframe></p>
<div id="content">
<canvas></canvas>
</div>
<script>
$(function() {
$('#movie').hide();
$('#movie-link').click(function() {
$('#movie').toggle();
});
var centerX = 0;
var centerY = 0;
sizing();
draw(centerX, centerY);
Leap.loop(function(frame){
if (frame.fingers[0]) {
var x = frame.fingers[0].tipPosition[0];
var y = frame.fingers[0].tipPosition[1];
var z = frame.fingers[0].tipPosition[2];
draw(x + centerX, $("canvas").height() - y, z);
}
});
$(window).resize(function() {
sizing();
draw(centerX, centerY);
});
function sizing() {
$("canvas").attr({height:$("#content").height()});
$("canvas").attr({width:$("#content").width()});
centerX = $("canvas").width() / 2;
centerY = $("canvas").height() / 2;
}
function draw(x, y, radius) {
if (typeof radius === 'undefined') {
radius = 10;
} else {
radius = radius < 10 ? 10 : radius;
}
var canvas = $('canvas')[0];
var context = canvas.getContext('2d');
context.clearRect(0, 0, $("canvas").width(), $("canvas").height());
context.beginPath();
context.arc(x, y, radius, 0, Math.PI * 2, false);
context.stroke();
}
});
</script>
</body>
</html>