-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhackathon3.html
More file actions
145 lines (117 loc) · 4.01 KB
/
hackathon3.html
File metadata and controls
145 lines (117 loc) · 4.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html>
<head>
<title>Hand visualization</title>
<script src='http://cdn.zigfu.com/zigjs/zig.min.js'></script>
<script type="text/javascript">
function loaded() {
//load canvas
var canvas=document.getElementById('test');
var ctx = canvas.getContext('2d');
var draw = false;
ctx.strokeStyle = "#ff0000";
ctx.lineWidth = 3;
ctx.lineCap = "round";
var faderValue = 0.0;
// var elt = document.getElementById("btn");
// Create cursor and cursor dom element
var c = zig.controls.Cursor();
var ce = document.createElement('div');
ce.id = 'mycursor';
document.body.appendChild(ce);
console.log("Browser plugin installed: " + zig.pluginInstalled);
console.log("Browser plugin version: " + zig.pluginVersion);
console.log("Zig.js version: " + zig.version);
zig.addEventListener('statuschange', function() {
console.log("Sensor connected: " + zig.sensorConnected);
});
// Adding Fader
var f = zig.controls.Fader(zig.Orientation.Z);
f.addEventListener('valuechange', function (f) {
//console.log('Fader value: ' + (f.value));
})
zig.singleUserSession.addListener(f);
// Adding swipe detector
var swipeDetector = zig.controls.SwipeDetector();
swipeDetector.addEventListener('swipe', function (dir) {
console.log('SwipeDetector: Swipe direction: ' + dir);
});
zig.singleUserSession.addListener(swipeDetector);
console.log("Adding sessionstart and sessionend listeners");
// 1. show/hide cursor on session start/end
zig.singleUserSession.addEventListener('sessionstart', function (focusPosition) {
ce.style.display = 'block';
console.log("sessionstart");
});
zig.singleUserSession.addEventListener('sessionend', function () {
ce.style.display = 'none';
console.log("sessionend");
});
ctx.beginPath();
// 2. move the cursor element on cursor move
c.addEventListener('move', function (cursor) {
ce.style.left = (c.x * window.innerWidth - (ce.offsetWidth / 2)) + "px";
ce.style.top = (c.y * window.innerHeight - (ce.offsetHeight / 2)) + "px";
//console.log("%o %o", c.x, c.y);
if (true/*draw*/) {
var x, y;
x = Math.round(c.x * canvas.width);
y = Math.round(c.y * canvas.height);
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x, y);
ctx.arc(x, y, 10, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
}
});
// 3. Add/remove 'pushed' class on cursor push/release
c.addEventListener('push', function(c) {
ce.classList.add('pushed');
console.log("push")
});
/*
c.addEventListener('release', function (c) {
ce.classList.remove('pushed');
draw = !draw; // toggle draw state
console.log("release");
});
*/
/*
// 4. Simulate mouse click on our virtual cursor
c.addEventListener('click', function(c) {
var xpos = c.x * window.innerWidth;
var ypos = c.y * window.innerHeight;
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 1, xpos, ypos, xpos, ypos, false, false, false, false, 0, null);
//elt.dispatchEvent(evt);
});
*/
// Add cursor to our single user UI session
zig.singleUserSession.addListener(c);
}
document.addEventListener('DOMContentLoaded', loaded, false);
</script>
<style>
#test {
background:#f00 url(Assets/Bricks.jpg);
}
#mycursor {
position: fixed;
display : none; /* hidden until a session starts */
width : 40px;
height : 40px;
background-color: blue;
border-radius: 10px;
-moz-border-radius: 10px;
}
#mycursor.pushed {
background-color: red;
}
</style>
</head>
<body>
<!-- button id="btn" onclick="alert('Hello World')">Click Me</button -->
<canvas id="test" width="2000" height="400" style="border:1px solid black"></canvas>
</body>
</html>