Skip to content

Instantly share code, notes, and snippets.

@bwhite
Forked from amiller/glass.html
Created March 2, 2014 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bwhite/9300809 to your computer and use it in GitHub Desktop.
Save bwhite/9300809 to your computer and use it in GitHub Desktop.
[wearscript] Big to Glass Calibration
<html style="width:100%; height:100%; overflow:hidden">
<head>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>-->
</head>
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function cb(data) {
// Changes canvas color with head rotation
if (data['type'] == WS.sensor('orientation')) {
ctx.fillStyle = 'hsl(' + data['values'][0] + ', 90%, 50%)'
ctx.fillRect(0, 0, 640, 360);
}
}
function onGesture(name) {
if (name == 'TAP') {
if (!READY) {
WS.sound('DISALLOWED');
return;
}
WS.sound('TAP');
READY = false;
points.push([point_x, point_y]);
WS.cameraOn(.1, 720, 1280, function (data) {
if (READY)
return;
READY = true;
WS.cameraOff();
WS.publish('calibimageb64pt', data, points[points.length - 1], session);
WS.sound('SUCCESS');
draw();
});
}
}
var points = []
READY = true;
function draw() {
// Draw one point on the screen
ctx.fillStyle = 'black'
ctx.fillRect(0, 0, 640, 360);
var cols = 4;
var rows = 3;
var margin = 5;
var n = points.length % (cols*rows);
var col = n % cols;
var row = Math.floor(n / cols);
if (n == 0)
session = Math.random();
point_x = (col+0) * ((640+0)/(cols-1)) - 0;
point_y = (row+0) * ((360+0)/(rows-1)) - 0;
ctx.beginPath();
ctx.arc(point_x,point_y,5,0,2*Math.PI);
ctx.closePath();
ctx.fillStyle = 'red'
ctx.fill();
WS.say('ABC'[row] + '. ' + col)
}
function server() {
WS.log('Time to Calibrate');
WS.gestureCallback('onGesture', onGesture);
draw();
}
function main() {
if (WS.scriptVersion(1)) return;
ctx = document.getElementById('canvas').getContext("2d");
WS.serverConnect('{{WSUrl}}', 'server');
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment