Last active
August 29, 2015 14:00
-
-
Save scottgwald/11013668 to your computer and use it in GitHub Desktop.
[wearscript] picaboo step 2
This file contains hidden or 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> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script> | |
| </head> | |
| <body style="width:100%; height:100%; overflow:hidden; margin:0"> | |
| <img id="theImage" src="" width=640 height=360> | |
| <script> | |
| var lightThreshold = 25; | |
| var theImage = $('#theImage'); | |
| var isCovered; | |
| var currentPath = coveredPath; | |
| var picturesTaken = 0; | |
| var coveredPathDefault = "http://imgur.com/TVDbSR1.jpg"; | |
| var uncoveredPathDefault = "http://imgur.com/Mk0XZNL.jpg"; | |
| var coveredPath, uncoveredPath; | |
| loadDefaultPaths(); | |
| var isDefault = true; | |
| function loadDefaultPaths() { | |
| isDefault = true; | |
| coveredPath = coveredPathDefault; | |
| uncoveredPath = uncoveredPathDefault; | |
| } | |
| function loadLocalStoragePaths() { | |
| isDefault = false; | |
| if (localStorage['coveredPath']) | |
| coveredPath = localStorage['coveredPath']; | |
| if (localStorage['uncoveredPath']) | |
| uncoveredPath = localStorage['uncoveredPath']; | |
| } | |
| function togglePaths() { | |
| isDefault ? loadLocalStoragePaths() : loadDefaultPaths(); | |
| setImage(); | |
| } | |
| WS.gestureCallback('onGestureTWO_TAP', togglePaths); | |
| function setImage() { | |
| if (isCovered) { | |
| if (currentPath != coveredPath) { | |
| WS.say("where are you"); | |
| theImage.attr('src', coveredPath); | |
| currentPath = coveredPath; | |
| } | |
| } else { | |
| if (currentPath != uncoveredPath) { | |
| WS.say("picaboo"); | |
| theImage.attr('src', uncoveredPath); | |
| currentPath = uncoveredPath; | |
| } | |
| } | |
| } | |
| WS.gestureCallback('onGestureTAP', function () { | |
| isDefault = false; | |
| WS.say('tapped'); | |
| console.log("Pictures taken: " + picturesTaken); | |
| if (picturesTaken < 2) { | |
| WS.cameraPhoto(function(path) { | |
| console.log("Got camera callback"); | |
| if (picturesTaken == 0) { | |
| localStorage['uncoveredPath'] = path; | |
| uncoveredPath = path; | |
| } else if (picturesTaken == 1) { | |
| localStorage['coveredPath'] = path; | |
| coveredPath = path; | |
| } | |
| picturesTaken += 1; | |
| setImage(); | |
| }); | |
| } | |
| }); | |
| function main() { | |
| if (WS.scriptVersion(1)) return; | |
| WS.sound('SUCCESS'); | |
| WS.sensorOn('light', .01, function (data) { | |
| isCovered = data['values'][0] <= lightThreshold; | |
| setImage(); | |
| }); | |
| } | |
| window.onload = main; | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or 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":"Picaboo"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment