-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
518 lines (429 loc) · 19.1 KB
/
index.html
File metadata and controls
518 lines (429 loc) · 19.1 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="width=device-width,initial-scale=1.0" name="viewport">
<meta charset="utf-8">
<title>.: vissom :.</title>
<link rel="stylesheet" href="css/main.css">
<!--<link rel="manifest" href="manifest.json">-->
</head>
<body>
<script type="text/javascript" src="lib/engine.io.js"></script>
<script type="text/javascript">
var 水 = {}; // TODO: remove soon
</script>
<script type="text/javascript" src="lib/shui.deps.js"></script>
<script type="text/javascript" src="lib/shui.js"></script>
<script type="text/javascript">
var multicast = cosinedesign.toolbox.multicast;
</script>
<!-- question: is this ok here? will clientSdtate.newDotSize still work with this script here? -->
<script type="text/javascript" src="js/viewController.js"></script>
<script type="text/javascript">
var toolbox = cosinedesign.toolbox,
calibration = {
alphaOffset: 0,
events: {
absolute: ('ondeviceorientationabsolute' in window),
relative: ('ondeviceorientation' in window)
}
},
targets = {
x1: 0.2,
x2: 0.8
},
channel,
queue,
delimiter = "|",
oPipe,
socket,
useEngineIO = false,
state = {
paint: false // set to true for active painting
};
sway.config.url = 'http://192.168.1.240:1000';
function paint() {
if (channel) {
state.socket.send(channel.name + delimiter + 'active' + delimiter + state.paint);
}
state.paint = !state.paint;
}
function correctCompass(o) {
o.heading = o.webkitCompassHeading || o.alpha;
return o;
}
function showDebugData(el, o) {
var out = "<br>"
+ "alpha (yaw) " + o.alpha + "</br>"
+ "beta (pitch) " + o.beta + "</br>"
+ "gamma (roll) " + o.gamma + "</br>"
+ "absolute " + o.absolute + "</br>";
if (o.events.absolute) {
out = out + "Absolute Events</br>"
}
if (o.events.relative) {
out = out + "Relative Events</br>"
}
if (o.heading) {
out = out + "heading " + o.heading + "</br>"
}
if (o.heading1) {
out = out + "heading1 " + o.heading1 + "</br>"
}
if (o.heading2) {
out = out + "heading2 " + o.heading2 + "</br>"
}
if (o.heading90) {
out = out + "heading90 " + o.heading90 + "</br>"
}
if (o.webkitCompassHeading) {
out = out + "compass " + o.webkitCompassHeading + "</br>"
}
out += "</div>";
el.innerHTML = out;
return o;
}
function updateQueue(queue) {
var q = state.queue = queue;
state.elQueueCount = state.elQueueCount || document.getElementById('queueCount');
state.elQueueCount.innerText = q.count;
}
sway.api.onDie.add(function () {
sway.actions.quit();
});
// Listen for queue update messages
sway.api.onQueueChange.add(function (res) {
if (res.queue) updateQueue(res.queue);
});
// Listen for queue update messages
sway.api.onChannelChange.add(function (res) {
if (state.queued) {
state.queued = false;
if (res.channel) initializeChannel(res.channel);
}
});
function initializeSocket (inputConfig) {
if (useEngineIO) {
socket = state.socket = new sway.Socket({address: inputConfig.address + ':' + inputConfig.port});
socket.connect();
return;
}
return state.socket = new sway.WebSocket({address: 'ws://' + inputConfig.address + ':' + inputConfig.port});
}
// Done whenver we get our channel
function initializeChannel (channel) {
state.channel = channel;
var plugin = state.plugin = channel[channel.plugin];
var orientation = plugin.orientation,
inputConfig = plugin.input;
//oPipe.next(showObject);
socket = initializeSocket(inputConfig);
// orientation pipe
oPipe = toolbox.pipe(showObject);
oPipe.add(shui.pipeline.buildHandlersForInput(shui.pipeline.plugins, 'scale', orientation));
oPipe.add(shui.pipeline.buildHandlersForInput(shui.pipeline.plugins, 'ratioPolar', orientation));
function showObject(o) {
//divInput.innerHTML = JSON.stringify(o);
return o;
}
// add a send-to-sway-realtime handler/pipe
var sendPipe = toolbox.pipe(function (data) {
if (!data) return;
// translate the data first into the socket packet
socket.send(channel.name + delimiter + data.alpha + delimiter + data.beta + delimiter + data.gamma);
//var packet = { channel: channel.name, orientation: data };
//socket.send(packet);
return data;
});
//sendPipe.next(showData);
// add a throttle for sPipe
var throttle = toolbox.throttle(sendPipe);
throttle.interval(40);
// add the pipe to
oPipe.next(throttle);
shui.motion.init();
// if (state.queued) sway.actions.calibrate();
if (state.queued) {
clientState.bypassCalibration ? sway.actions.confirm() : sway.actions.calibrate();
} else {
sway.actions.confirm();
}
}
// register motion handlers
sway.oninitialized = multicast(function (res) {
sway.user.setHeartbeat();
// TODO: if the user is not in a channel this crashes!
if (res.channel) {
initializeChannel(res.channel);
} else {
if (res.queue) {
queue = state.queue = res.queue;
updateQueue(queue);
}
}
//sway.management.getTimer();
});
// initialize sway (connects to server)
sway.init();
/**
* Click handler - walk user through calibration steps
*/
var calibrationViews;
function calibrateViewNext () {
var c = calibrationViews;
switch (c.currentStep) {
case 'step1':
calibration.heading1 = calibration.heading;
// send generated position #2 (one ping only, please)
socket.send(state.channel.name + delimiter + targets.x2 + delimiter + .5 + delimiter + 0 );
c.steps.step1.classList.remove('current-step');
c.steps.step2.classList.add('current-step');
c.currentStep = 'step2';
break;
case 'step2':
calibration.heading2 = calibration.heading;
// TODO: calc & show next position - heading90
c.steps.step2.classList.remove('current-step');
c.steps.step3.classList.add('current-step');
c.currentStep = 'step3';
break;
case 'step3':
// TODO: record heading90 offset
alert('JIM GENERATE 90 POSITION HERE!');
calibration.heading90 = calibration.heading;
clientState.changeView('confirm');
c.steps.step3.classList.remove('current-step');
c.steps.step1.classList.add('current-step');
sway.actions.calibrateComplete();
c.currentStep = 'step1';
}
}
sway.actions = {
// Show the splashscreen for the installation
"splash": function () {
calibrationViews = {
debugAlpha: document.getElementById('debugAlpha'),
currentStep: 'step1',
steps: {
step1: document.getElementById('calibrate1'),
step2: document.getElementById('calibrate2'),
step3: document.getElementById('calibrate3')
}
};
clientState.changeView('splash');
//alert('splash viewable');
},
// Show project description/artist statement screen
"info": function () {
clientState.changeView('info');
},
// Notify user that they are waiting
"queue": function () {
if (state.channel) {
if (clientState.bypassCalibration)
{
sway.actions.confirm();
return;
}
else {
sway.actions.calibrate();
return;
}
}
if (state.queue) {
state.queued = true;
updateQueue(state.queue);
clientState.changeView('queue');
}
},
// Select shape for the user
//"shape": function () {},
// Calibrate user into the system
"calibrate": function () {
// generate a position within space
var space = {
x: { min: 100, max: 240 },
y: { min: -20, max: 75 }
},
c = state.channel.state,
d = delimiter;
// send size, shape, color
socket.send(state.channel.name + d + 'size' + d + 4);
socket.send(state.channel.name + d + 'shape' + d + c.shape);
socket.send(state.channel.name + d + 'color' + d + (c.color.r / 255) + d + (c.color.g / 255) + d + (c.color.b / 255));
// send generated position 1 (one ping only, please)
socket.send(state.channel.name + delimiter + targets.x1 + delimiter + .5 + delimiter + 0 );
// create the user's shape
clientState.shapeHandler(c.shape, c.color);
// Make calibrate notification visible
clientState.changeView('calibrate');
// add a pipe specific to calibration
var calPipe = toolbox.pipe(function (o) {
if (o) {
correctCompass(o);
calibration.compass = o.webkitCompassHeading;
calibration.absolute = o.absolute;
calibration.heading = o.heading;
// slow this the eff down so we maybe can get the right values instead of a million DOM updates
window.requestAnimationFrame(function () {
showDebugData(calibrationViews.debugAlpha, calibration);
});
}
return o;
});
var throttledPipe = toolbox.throttle(calPipe);
throttledPipe.interval(100);
shui.motion.onOrientation = throttledPipe;
},
"calibrateComplete": function () {
// Cut off the motion handler so the last value is now the calibration info.
shui.motion.onOrientation = function () {};
sway.actions.confirm();
},
// Calibration
// - we put one shape onscreen at targetX1; record that angle.
// - we put same shape at targetX2; record that angle.
// display shape and brief instruction to user before user clicks "start" button to begin playing
"confirm": function () {
var userInstruction = document.getElementById('userInstruction'),
c = state.channel.state,
d = delimiter;
if (clientState.bypassCalibration) {
socket.send(state.channel.name + d + 'size' + d + 4);
socket.send(state.channel.name + d + 'shape' + d + c.shape);
socket.send(state.channel.name + d + 'color' + d + (c.color.r / 255) + d + (c.color.g / 255) + d + (c.color.b / 255));
// create the user's shape
clientState.shapeHandler(c.shape, c.color);
}
clientState.bypassCalibration ?
userInstruction.innerText = "Okay, you're ready to paint! Your cursor's color and shape is:" :
userInstruction.innerText = "Okay! We've calibrated your phone and you're ready to paint. Remember, your color and shape is:";
clientState.changeView('confirm');
},
// Enter play state
"play": function () {
clientState.changeView('play');
//sway.actions.play();
// Now assign the play pipe to the orientation handler
shui.motion.onOrientation = oPipe;
},
// Quit the interaction
"quit": function () {
shui.motion.onOrientation = function () {};
if (sway.heartbeat) window.clearInterval(sway.heartbeat);
clientState.changeView('quit');
}
};
</script>
<section id="splash" class="splash">
<header><svg class="logo"><use xlink:href="vissom-logo.svg#logo"></use></svg></header>
<h1>Welcome to Visualize Somerville 2</h1>
<nav>
<button onclick="sway.actions.info()">Want to learn more?</button>
<button onclick="sway.actions.queue()">Want to play?</button>
</nav>
</section>
<section id="info" class="info">
<article>
<p><strong>Visualize Somerville 2</strong> (#VisSom2) combines technology, activity, and community into a large scale interactive installation. This event was hatched by the group <strong>Optexture</strong>: a think tank of dreamers, coders, makers, and futurists.</p>
<p>We created Visualize Somerville last year, and this year have upped the ante by providing interactivity for all participants.</p>
<p><strong class="highlight">Visualize Somerville 2 is the attempt to disrupt our views of current day technology.</strong></p>
<p>Everyone uses their personal devices, Ipads, smartphones, to keep connected like never before. But this also has a downside, as we also get lost in our own world and forget the world around you. How many of us have turned to our phones when we are traveling? Nervous?</p>
<p>Visualize Somerville 2 takes that device, and brings new meaning to it: direct involvement and collaboration with the climbers, other painters, and the art you create as a collective.</p>
<p>This is also a Masters Capstone project for a member of Optexture (Jon MacLeod). Thank you for coming, and enjoy!</p>
</article>
<nav><button onclick="sway.actions.splash()">Continue</button></nav>
</section>
<section id="queue" class="queue">
<article>
<p>There are:</p>
<div class="waiting">
<svg class="circular" viewBox="25 25 50 50">
<circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"/>
</svg>
<div id="queueCount" class="queue--number"></div>
</div>
<p>players waiting ahead of you. We will get you painting as soon as we can!</p>
</article>
</section>
<section id="calibrate" class="calibrate">
<header>
<svg class="shape"></svg>
</header>
<article id="calibrate1" class="current-step">
<p>Let's get your device calibrated!</p>
<p>Look on the wall and find the shape and color shown above. Point your device at the shape, and then click the button below.</p>
</article>
<article id="calibrate2">
<p>Great! Let's calibrate to a second point.</p>
<p>Find the shape on the wall, point at it, and then click the button.</p>
</article>
<article id="calibrate3">
<p>Just one more to go!</p>
<p>Please point your phone at your shape and then click the button below.</p>
</article>
<div id="debugAlpha"></div>
<nav><button onclick="calibrateViewNext()">Continue</button></nav>
</section>
<section id="confirm">
<article>
<p id="userInstruction"></p>
<div class="user-shape">
<svg class="shape"></svg>
</div>
<p>To paint: on the next screen, click and hold the <strong>paint</strong> button to create! You'll also be able to adjust your brush size.</p>
</article>
<nav><button onclick="sway.actions.play()">Let's start!</button></nav>
</section>
<section id="play" class="play">
<nav>
<button onclick="sway.actions.quit()">End session</button>
<!--<button onclick="sway.actions.calibrate()">Recalibrate</button>-->
</nav>
<article><button id="paintButton" class="control">Hold to paint</button></article>
<div class="display-shape">
<div>Your shape:</div>
<div>
<svg class="shape"></svg>
</div>
</div>
<div class="control">
<label for="dotSize">Brush Size</label>
<input type="range" min="1" max="10" value="4" id="dotSize" onchange="clientState.newDotSize(event)">
</div>
</section>
<section id="disco" class="end">
<header><svg class="logo"><use xlink:href="vissom-logo.svg#logo"></use></svg></header>
<p>You've been disconnected due to inactivity. Thanks for playing with us!</p>
<nav>
<button onclick="sway.actions.info()">Want to learn more?</button>
<button onclick="sway.actions.queue()">Want to play again?</button>
</nav>
</section>
<section id="quit" class="end">
<header><svg class="logo"><use xlink:href="vissom-logo.svg#logo"></use></svg></header>
<p>That was awesome. Thanks for playing with us!</p>
<nav>
<button onclick="sway.actions.info()">Want to learn more?</button>
<button onclick="sway.actions.queue()">Want to play again?</button>
</nav>
</section>
<script type="text/javascript" src="js/viewController.js"></script>
<script>
// lock display orientation to portrait mode, if possible
if (window.screen && window.orientation && window.orientation.lock) {
var lock = window.screen.orientation.lock('portrait');
lock.catch(function () {
});
}
// apply event handlers to "paint" button
clientState.pressEvents();
clientState.onPaintEnd = function () {
if (state.socket) state.socket.send(state.channel.name + delimiter + 'active' + delimiter + 0);
};
clientState.onPaintStart = function () {
if (state.socket) state.socket.send(state.channel.name + delimiter + 'active' + delimiter + 1);
};
</script>
</body>
</html>