-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.html
More file actions
47 lines (41 loc) · 1.17 KB
/
Copy pathcontroller.html
File metadata and controls
47 lines (41 loc) · 1.17 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
<!DOCTYPE html>
<html>
<head>
<title>Controller</title>
<style>
html {
cursor: pointer;
}
</style>
</head>
<body>
<script>
var wsAddress = document.location.origin.replace(/.+?\:\/\//, 'ws://');
var ws = new WebSocket(wsAddress);
ws.onopen = onWsOpen;
function onWsOpen() {
console.log('Connected');
}
var NUMBER_OF_SOUNDS = 8;
var idx = Math.floor(Math.random() * NUMBER_OF_SOUNDS);
function play() {
ws.send(idx);
}
console.log('Using sound: %d', idx);
document.addEventListener('click', play);
document.addEventListener('touch', play);
// random color bg
var letters = ['A', 'B', 'C', 'D', 'E', 'F'];
for(var i=9; i>=0; --i)
letters.unshift(new String(i));
function getRandomColor() {
var color = '#';
color += letters[Math.floor(Math.random() * letters.length)];
color += letters[Math.floor(Math.random() * letters.length)];
color += letters[Math.floor(Math.random() * letters.length)];
return color;
}
document.bgColor = getRandomColor();
</script>
</body>
</html>