Skip to content

Instantly share code, notes, and snippets.

@patrickoshaughnessey
Created May 22, 2014 16:09
Show Gist options
  • Save patrickoshaughnessey/bd05ac273582749ab1e2 to your computer and use it in GitHub Desktop.
Save patrickoshaughnessey/bd05ac273582749ab1e2 to your computer and use it in GitHub Desktop.
[wearscript] HelloWearscript.html
<!-- Sample WearScript -->
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function server() {
WS.log('Welcome to WearScript'); // Write to Android Log and Playground console
WS.say('Welcome to WearScript'); // Text-to-Speech
WS.sound('SUCCESS')
// Changes canvas color with head rotation
WS.sensorOn('orientation', .15, function (data) {
ctx.fillStyle = 'hsl(' + data['values'][0] + ', 90%, 50%)'
ctx.fillRect(0, 0, 640, 360);
});
// Stream several sensors (can view in the Sensors tab)
var sensors = ['gps', 'accelerometer', 'magneticField', 'gyroscope',
'light', 'gravity', 'linearAcceleration', 'rotationVector'];
for (var i = 0; i < sensors.length; i++)
WS.sensorOn(sensors[i], .15);
// Stream camera frames (can view in the Images tab)
WS.cameraOn(.25);
WS.dataLog(false, true, .15);
// Hookup touch and eye gesture callbacks
WS.gestureCallback('onTwoFingerScroll', function (v, v2, v3) {
WS.log('onTwoFingerScroll: ' + v + ', ' + v2 + ', ' + v3);
});
WS.gestureCallback('onEyeGesture', function (name) {
WS.log('onEyeGesture: ' + name);
});
WS.gestureCallback('onGesture', function (name) {
WS.log('onGesture: ' + name);
});
WS.gestureCallback('onFingerCountChanged', function (i, i2) {
WS.log('onFingerCountChanged: ' + i + ', ' + i2);
});
WS.gestureCallback('onScroll', function (v, v2, v3) {
WS.log('onScroll: ' + v + ', ' + v2 + ', ' + v3);
});
}
function main() {
if (WS.scriptVersion(1)) return;
ctx = document.getElementById('canvas').getContext("2d");
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script></body></html>
<!-- Sample WearScript -->
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function server() {
WS.log('Welcome to WearScript'); // Write to Android Log and Playground console
WS.say('Welcome to WearScript'); // Text-to-Speech
WS.sound('SUCCESS')
// Changes canvas color with head rotation
WS.sensorOn('orientation', .15, function (data) {
ctx.fillStyle = 'hsl(' + data['values'][0] + ', 90%, 50%)'
ctx.fillRect(0, 0, 640, 360);
});
// Stream several sensors (can view in the Sensors tab)
var sensors = ['gps', 'accelerometer', 'magneticField', 'gyroscope',
'light', 'gravity', 'linearAcceleration', 'rotationVector'];
for (var i = 0; i < sensors.length; i++)
WS.sensorOn(sensors[i], .15);
// Stream camera frames (can view in the Images tab)
WS.cameraOn(.25);
WS.dataLog(false, true, .15);
// Hookup touch and eye gesture callbacks
WS.gestureCallback('onTwoFingerScroll', function (v, v2, v3) {
WS.log('onTwoFingerScroll: ' + v + ', ' + v2 + ', ' + v3);
});
WS.gestureCallback('onEyeGesture', function (name) {
WS.log('onEyeGesture: ' + name);
});
WS.gestureCallback('onGesture', function (name) {
WS.log('onGesture: ' + name);
});
WS.gestureCallback('onFingerCountChanged', function (i, i2) {
WS.log('onFingerCountChanged: ' + i + ', ' + i2);
});
WS.gestureCallback('onScroll', function (v, v2, v3) {
WS.log('onScroll: ' + v + ', ' + v2 + ', ' + v3);
});
}
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