Created
June 14, 2014 21:07
-
-
Save fluidglassml/47a8b97b783b918f7122 to your computer and use it in GitHub Desktop.
[wearscript] tinder chd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html style="width:100%; height:100%; overflow:hidden"> | |
<head> | |
<!-- You can include external scripts here like so... --> | |
<!--<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" bgcolor="#000"> | |
<canvas id="canvas" width="640" height="360" style="display:block"></canvas> | |
<script> | |
function server() { | |
var home = undefined; | |
var prevX; | |
var prevY; | |
var prevNo; | |
var prevYes; | |
var sendNo = false; | |
var sendYes = false; | |
var i = 0; | |
WS.sensorOn('orientation', 0.15, function (data) { | |
//console.log(data['values']); | |
var orientationX = data['values'][0]; | |
var orientationY = data['values'][1]; | |
++i; | |
/*console.log("orientationX: " + orientationX); | |
console.log("prevX: " + prevX); | |
console.log((Math.abs(orientationX - prevX) + 360) % 360)*/ | |
if (prevX && (Math.abs(orientationX - prevX) + 360) % 360 > 30 && !prevNo) { | |
console.log('NO'); | |
sendNo = true; | |
// WS.publish('tinderYes', 'nod'); | |
prevNo = true; | |
} | |
else { | |
prevNo = false; | |
sendNo = false; | |
} | |
orientationY = (orientationY + 360) % 360; | |
if(i%5 == 0) { | |
//console.log("orientationY: " + orientationY); | |
//console.log("prevY: " + prevY); | |
console.log("diffY: " + Math.abs(orientationY - prevY)); | |
} | |
if (prevY && Math.abs(orientationY - prevY) > 8 && !prevYes) { | |
console.log('YES'); | |
sendYes = true; | |
// WS.publish('tinderYes', 'nod'); | |
console.log("diffY: " + Math.abs(orientationY - prevY)); | |
prevYes = true; | |
} | |
else { | |
prevYes = false; | |
sendYes = false; | |
} | |
if (sendYes) sendString = 'yes'; | |
if (sendNo) sendString = 'no'; | |
if (sendNo || sendYes) | |
WS.publish('tinderGestures', sendString); | |
prevX = orientationX; | |
prevY = orientationY; | |
}); | |
WS.gestureCallback('onGesture', function (gesture) { | |
var sendString, sendNo = false, sendYes = false; | |
if (gesture == 'SWIPE_LEFT') { | |
sendNo = true; | |
} | |
else if (gesture == 'SWIPE_RIGHT') { | |
sendYes = true; | |
} | |
if (sendYes) sendString = 'yes'; | |
if (sendNo) sendString = 'no'; | |
if (sendNo || sendYes) { | |
console.log("send: " + sendString); | |
WS.publish('tinderGestures', sendString); | |
} | |
}); | |
WS.cameraOnBackgroundUnsafe(10, 10000, 10000); | |
WS.dataLog(true, false, .15); | |
} | |
function main() { | |
if (WS.scriptVersion(1)) return; | |
ctx = document.getElementById('canvas').getContext("2d"); | |
WS.serverConnect('{{WSUrl}}', server); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"Amputinder"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WS.cameraOnBackgroundUnsafe(10, 10000, 10000); | |
WS.dataLog(true, false, .15); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment