-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.js
109 lines (95 loc) · 3.68 KB
/
random.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var lengthField = document.querySelector(".length");
var rateField = document.querySelector(".rate");
var adjustField = document.querySelector(".adjust");
ctx.onComplete = function( ev ){
console.log(ev.renderedBuffer);
}
if(document.body.classList.contains("one")) {
startOne();
document.querySelector("button").addEventListener('click', function() {
startOne();
});
} else if (document.body.classList.contains("two")) {
var socket = io.connect('http://leon.ngrok.com');
var play;
var i = 0;
Leap.loop(function(frame) {
frame.hands.forEach(function(hand, index) {
var palm = hand.ringFinger.tipVelocity.map(function(a) { return Math.floor(a) })
if(Math.abs(palm[0])>=100) {
if(!play) {
play = startTwo(ctx);
}
play[0].playbackRate.value = 2;
} else {
if(play) {
play[0].playbackRate.value = 1;
}
}
});
}).use('screenPosition', {scale: 0.25});
var back = document.querySelector(".background");
var other = document.querySelector(".other");
back.height = window.innerHeight;
back.width = window.innerWidth/2;
other.height = window.innerHeight;
other.width = window.innerWidth/2;
var bctx = back.getContext("2d");
var octx = other.getContext("2d");
var squareHeight = 50;
var _ = "transparent", b = "#8CCBFF", c = "#84D1FF", d = "#242633";
var image = [
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, c, c, c, c, c, c, c, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, b, b, b, b, b, b, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, b, d, b, b, d, b, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, b, d, b, b, d, b, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, b, b, b, b, b, b, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, d, b, b, b, b, d, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, b, d, d, d, d, b, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, b, b, b, b, b, b, c, _, _, _, _, _, _],
[_, _, _, _, _, _, c, c, c, c, c, c, c, c, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]
];
socket.on('move head', function(msg){
console.log(msg.x, msg.y);
other.clearRect(0, 0, other.width, other.height);
other.lineWidth = .25;
for(var i=0;i<image.length;i++) {
for(var j=0;j<image[0].length;j++) {
octx.fillStyle = image[j][i];
octx.fillRect(msg.x/5, msg.y/5, squareHeight/5, squareHeight/5);
}
}
});
var i =0;
document.addEventListener('headtrackingEvent', function(e) {
i++;
bctx.clearRect(0, 0, back.width, back.height);
bctx.lineWidth = .25;
for(var i=0;i<image.length;i++) {
for(var j=0;j<image[0].length;j++) {
bctx.fillStyle = image[j][i];
bctx.fillRect(i*squareHeight+(10*e.x)-20, j*squareHeight+(-10*e.y), squareHeight, squareHeight);
if(i%10===0) {
socket.emit('head move', {x: i*squareHeight+(10*e.x), y: j*squareHeight+(-10*e.y)});
}
}
}
})
Leap.loopController.setBackground(true);
var videoInput = document.getElementById('vid');
var canvasInput = document.getElementById('inputCanvas');
var htracker = new headtrackr.Tracker();
htracker.init(videoInput, canvasInput);
htracker.start();
} else if (document.body.classList.contains("three")) {