forked from hachr/jsconf-2013-nodebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
80 lines (71 loc) · 2.01 KB
/
index.html
File metadata and controls
80 lines (71 loc) · 2.01 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://172.20.41.105');
</script>
</head>
<body ontouchstart="touchstart(event)" ontouchmove="touchstart(event)">
<script>
// document.body.addEventListener('touchstart', touchstart);
// document.body.addEventListener('touchmove', touchstart);
// var map = {
// "10": function () {
// socket.emit('forward');
// },
// "12": function () {
// socket.emit('backward');
// },
// "11": function () {
// socket.emit('stop');
// },
// "01": function () {
// socket.emit('hardLeft');
// },
// "00": function () {
// socket.emit('left');
// },
// "02": function () {
// socket.emit('hardLeft');
// },
// "20": function () {
// socket.emit('right');
// },
// "22": function () {
// socket.emit('right');
// },
// "21": function () {
// socket.emit('right');
// }
// };
function touchstart(event) {
[].slice.call(event.changedTouches).forEach(function (t) {
if (t.identifier === 0) {
var seg = fn(t.screenX, t.screenY);
document.getElementById("output").innerHTML = seg.x + " - " + seg.y;
socket.emit('move',seg);
}
});
}
function touchTranslator(rect, q) {
return cvt;
function cvt(x, y) {
var point = {
x: (x - rect.left) / (rect.right - rect.left),
y: (y - rect.top) / (rect.bottom - rect.top)
};
if (q) {
point.x = q * point.x | 0;
point.y = q * point.y | 0;
}
return point;
}
}
var fn = touchTranslator({
top: 0, left: 0,
bottom: screen.height, right: screen.width
}, 3);
</script>
<div id="output"></div>
</body>
</html>