-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.js
More file actions
66 lines (54 loc) · 2.08 KB
/
testing.js
File metadata and controls
66 lines (54 loc) · 2.08 KB
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
// Store frame for motion functions
var previousFrame = null;
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
// Setup Leap loop with frame callback function
var controllerOptions = {enableGestures: true};
var colorMap = ["red", "blue", "green", "black", "purple"];
var lastThreePositions = [0, 1, 2];
var tempPositions = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]];
var counter = 0;
var change = false;
Leap.loop({frameEventName: "animationFrame"}, function(frame) {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
frame.pointables.forEach(function(pointable) {
var position = pointable.stabilizedTipPosition;
var normalized = frame.interactionBox.normalizePoint(position);
var x = ctx.canvas.width * normalized[0];
var y = ctx.canvas.height * (1 - normalized[1]);
tempPositions[pointable.type] = [x, y]
ctx.beginPath();
ctx.fillStyle = colorMap[pointable.type];
ctx.fillRect(x, y, 20, 20);
});
});
setInterval(function() {
lastThreePositions[counter % 3] = tempPositions.slice();
counter += 1;
// console.log(lastThreePositions[0])
// console.log(lastThreePositions)
checkMovement(lastThreePositions);
}, 400);
function toggle() {
var x = document.getElementById("sidebar");
if (x.style.display === "none") {
console.log("display");
x.style.display = "block";
} else {
console.log("hide");
x.style.display = "none";
}
}
function checkMovement(lastThreePositions) {
var fingers_one = lastThreePositions[0];
var fingers_two = lastThreePositions[1];
var fingers_three = lastThreePositions[2];
// console.log("This is fingers one", fingers_one)
// console.log(fingers_one[2][0], " | ", fingers_two[2][0], " | ", fingers_three[2][0])
for (var i = 0; i < fingers_one.length; i++){
if(fingers_one[2][0] < fingers_two[2][0] && fingers_two[2][0] < fingers_three[2][0]) {
toggle();
console.log("hit");
}
}
}