Created
April 26, 2014 16:45
-
-
Save kevint2u/11324846 to your computer and use it in GitHub Desktop.
[wearscript] quizmode
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"> | |
<canvas id="canvas" width="640" height="360" style="display:block"></canvas> | |
<script> | |
// Constants | |
var DBG = true; | |
var i = 0; | |
var secondLineText = "Second line"; | |
var wakeTime; | |
var timeDeltaText = ""; | |
var wakeInterval = 300000; | |
var timeNow = new Date().getTime(); | |
var tillNextWake = Math.floor(wakeInterval / 1000); | |
var deltasMaxLength = 10; | |
var timeDeltas = []; | |
var woken; | |
var timeDeltaTitleText = "Between Last Wakes:"; | |
var batteryLevelText = "Battery level: "; | |
var showDashboard = true; | |
var cameraCB; | |
var showImageInterval = 10000; | |
var pauseFudgeFactor = 500; | |
var videoLength = 10; | |
// AUXILIARY FUNCTIONS | |
function drawModeName(name) { | |
upperBase = 40; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawSecondLine(name) { | |
upperBase = 90; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawTextLine(text, _number) { | |
var number = _number; | |
if ( number === undefined ) { | |
console.log("No number given, setting to 0"); | |
number = 0; | |
} | |
baseline = 40 + 50 * number; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(text, 10, baseline); | |
} | |
function clearCanvas() { | |
context.fillStyle = "rgb(0, 0, 0)"; | |
context.fillRect(0, 0, 640, 360); | |
} | |
Date.prototype.today = function () { | |
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear(); | |
} | |
Date.prototype.timeNow = function () { | |
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds(); | |
} | |
// MAIN | |
function draw() { | |
if (showDashboard) { | |
clearCanvas(); | |
drawTextLine(firstLineText, 0 ); | |
drawTextLine(secondLineText, 1 ); | |
drawTextLine(tillNextWake, 2 ); | |
drawTextLine(timeDeltaTitleText, 3 ); | |
drawTextLine(timeDeltaText, 4 ); | |
drawTextLine(batteryLevelText, 5 ); | |
} | |
// list of last times | |
// drawModeName("" + i); | |
// drawSecondLine(secondLineText); | |
} | |
currentTimeString = function () { | |
return new Date().today() + " @ " + new Date().timeNow(); | |
} | |
timeString = function(date) { | |
return date.today() + " @ " + date.timeNow(); | |
} | |
function server() { | |
if (!DBG) WS.serverConnect('0.0.0.0', null); | |
WS.log('Welcome to WearScript'); | |
WS.say('Welcome to WearScript'); | |
WS.sound('SUCCESS'); | |
WS.dataLog(true, false, 1); | |
WS.sensorOn("battery", 1, function (data) { | |
console.log("Got battery callback"); | |
console.log(JSON.stringify(data)); | |
batteryLevelText = "Battery Level: " + Math.round(data.values[0] * 100) + "%"; | |
if (Math.round(data.values[0] * 100) <= 20) WS.say("Low battery."); | |
batteryLevelText += " @ " + new Date(parseInt(data.timestamp * 1000)).timeNow(); | |
}); | |
clearCanvas(); | |
drawModeName("Rock and roll"); | |
var updateCurrentTime = function() { | |
var date = new Date(); | |
timeNow = date.getTime(); | |
tillNextWake = "Till Next Wake: " + Math.ceil((wakeInterval - (timeNow - wakeTime)) / 1000); | |
//firstLineText = currentTimeString(); | |
firstLineText = timeString(date); | |
draw(); | |
} | |
var updateWakeTime = function () { | |
if (wakeTime != undefined) { | |
woken = true; | |
} | |
var date = new Date(); | |
lastWakeTime = wakeTime; | |
wakeTime = date.getTime(); | |
wakeTimeString = timeString(date); | |
wakeTimeDelta = wakeTime - lastWakeTime; | |
if (woken) { | |
timeDeltas.unshift(Math.floor(wakeTimeDelta / 1000)); | |
if (timeDeltas.length > deltasMaxLength) timeDeltas.pop(); | |
} | |
timeDeltaText = JSON.stringify(timeDeltas); | |
secondLineText = "Last Wake: " + currentTimeString(); | |
//thirdLineText = "Time since last wake: "; | |
//secondLineText = "current time"; | |
draw(); | |
} | |
updateCurrentTime(); | |
updateWakeTime(); | |
// WS.cameraOn(0.5, 480, 640, cameraCB); | |
setInterval(updateCurrentTime, 1000); | |
var img = new Image(); | |
img.onload = function() { | |
context.drawImage(img, 0, 0); | |
} | |
cameraCB = function(data) { | |
WS.log("Got camera callback."); | |
showDashboard = false; | |
WS.cameraOff(); | |
//context.drawImage(img, 0, 0); | |
img.src = 'data:image/jpg;base64,' + data; | |
setTimeout(function() { | |
showDashboard = true; | |
//WS.liveCardCreate(true, .45); | |
WS.activityDestroy(); | |
}, showImageInterval); | |
//WS.say("Creating live card"); | |
//WS.liveCardDestroy(); | |
} | |
var periodic = function() { | |
WS.say("Cheese balls"); | |
WS.wake(); | |
WS.activityCreate(); | |
WS.displayWebView(); | |
// secondLineText = "LastWake: " + new Date().today() + " @ " + new Date().timeNow(); | |
updateWakeTime(); | |
WSRAW.recordWSVideo(videoLength); | |
WS.activityDestroy(); | |
//setTimeout(function() {WS.cameraOn(0.5, 480, 640, cameraCB);}, pauseFudgeFactor); | |
} | |
setInterval( periodic, wakeInterval ); | |
// Below this are more examples, uncomment to use them | |
WS.liveCardCreate(true, .2); | |
WSRAW.recordWSVideo(videoLength); | |
/* | |
var tree = new WS.Cards(); | |
tree.add('Body text', 'Footer text', function () {WS.say('selected')}, function () {WS.say('tapped')}, 'Menu0', function () {WS.say('menu0')}, 'Menu1', function () {WS.say('menu1')}); | |
tree.add('Body text', 'Footer text', (new WS.Cards()).add('Child0', '0').add('Child1', '1')); | |
WS.cardTree(tree); | |
WS.displayCardTree(); | |
*/ | |
/* | |
WS.speechRecognize('Say Something', function (data) { | |
WS.log('speech: ' + data); | |
WS.say('you said ' + data); | |
}); | |
*/ | |
//WS.cameraPhoto(); | |
//WS.cameraVideo(); | |
//WS.cameraOff(); | |
//WS.shutdown(); | |
} | |
function main() { | |
if (WS.scriptVersion(1)) return; | |
context = 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
<html style="width:100%; height:100%; overflow:hidden"> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<script type="text/javascript"> | |
function kimonoCallback(data) { | |
if(data.lastrunstatus=="success"){ | |
WS.say(JSON.stringify(data.count)); | |
console.log(JSON.stringify(data.results.collection1[0].question)); | |
console.log(JSON.stringify(data.results.collection1[0].answer)); | |
}else{ | |
getRandomWords(); | |
} | |
} | |
function getRandomWords(){ | |
var url = "http://www.kimonolabs.com/api/dwrmpm04?apikey=989877be85a3ca05477428c8b41d4fbe&callback=kimonoCallback&kimpath1="; | |
var num = Math.floor(Math.random()*1000000)+3000000; | |
url = url+num+"&kimpath2="; | |
$.ajax({ | |
"url": url, | |
"crossDomain":true, | |
"dataType":"jsonp" | |
}); | |
} | |
</script> | |
</head> | |
<body style="width:100%; height:100%; overflow:hidden; margin:0"> | |
<canvas id="canvas" width="640" height="360" style="display:block"></canvas> | |
<script> | |
// Constants | |
var DBG = true; | |
var i = 0; | |
var secondLineText = "Second line"; | |
var wakeTime; | |
var timeDeltaText = ""; | |
var wakeInterval = 5*60*1000; | |
var wordInterval = 10*1000; | |
var timeNow = new Date().getTime(); | |
var tillNextSet = Math.floor(wakeInterval / 1000); | |
var tillNextWord = Math.floor(wordInterval / 1000); | |
var deltasMaxLength = 10; | |
var timeDeltas = []; | |
var woken; | |
var timeDeltaTitleText = "Between Last Wakes:"; | |
var batteryLevelText = "Battery level: "; | |
var showDashboard = true; | |
var cameraCB; | |
var showImageInterval = 10000; | |
var pauseFudgeFactor = 500; | |
var videoLength = 10; | |
var animals = '{ "animals": [ { "spanish": "ardilla", "english": "squirrel" }, { "spanish": "Ballena", "english": "Whale" }, { "spanish": "Bandada", "english": "Flock of birds" }, { "spanish": "Buey (m)", "english": "Ox" }, { "spanish": "Burro", "english": "Donkey" }, { "spanish": "Caballo", "english": "Horse" }, { "spanish": "Cabra", "english": "Goat" }, { "spanish": "Cachorro", "english": "Cub (puppy)" }, { "spanish": "Camello", "english": "Camel" }, { "spanish": "Canguro", "english": "Kangaroo" }, { "spanish": "Carnero", "english": "Ram, mutton" }, { "spanish": "Cebra", "english": "Zebra" }, { "spanish": "Cerdo, Puerco", "english": "Pig" }, { "spanish": "Colmena", "english": "Beehive" }, { "spanish": "Conejo", "english": "Rabbit" }, { "spanish": "Cordero", "english": "Lamb" }, { "spanish": "Culebra", "english": "Snake" }, { "spanish": "DelfÃÂÃÂn (m)", "english": "Dolphin" }, { "spanish": "Elefante (m)", "english": "Elephant" }, { "spanish": "Foca", "english": "Seal" }, { "spanish": "Gato", "english": "Cat" }, { "spanish": "Jirafa", "english": "Giraffe" }, { "spanish": "GusanoLombriz", "english": "Worm" }, { "spanish": "LeÃÂón (m)", "english": "Lion" }, { "spanish": "Liebre (f)", "english": "Hare" }, { "spanish": "Lobo", "english": "Wolf" }, { "spanish": "Manada", "english": "Herd, fock, pack" }, { "spanish": "Mapache (m)MapachÃÂÃÂn", "english": "Raccoon" }, { "spanish": "Mono", "english": "Monkey" }, { "spanish": "Mulo", "english": "Mule" }, { "spanish": "MurciÃÂélago", "english": "Bat" }, { "spanish": "OrdeÃÂñar", "english": "To milk" }, { "spanish": "Oso", "english": "Bear" }, { "spanish": "Oveja", "english": "Sheep, ewe" }, { "spanish": "Panal (m)", "english": "Honeycomb" }, { "spanish": "Perro", "english": "Dog" }, { "spanish": "Potro", "english": "Colt" }, { "spanish": "Rana", "english": "Frog" }, { "spanish": "Rata", "english": "Rat" }, { "spanish": "RatÃÂón (m)", "english": "Mouse" }, { "spanish": "RebaÃÂño", "english": "Flock (of sheep)" }, { "spanish": "Sapo", "english": "Toad" }, { "spanish": "Serpiente (f)", "english": "Serpent, snake" }, { "spanish": "Ternero", "english": "Calf" }, { "spanish": "Tigre (m)", "english": "Tiger" }, { "spanish": "Toro", "english": "Bull" }, { "spanish": "Tortuga", "english": "Turtle" }, { "spanish": "Vaca", "english": "Cow" }, { "spanish": "Venado", "english": "StagDeer" }, { "spanish": "Yegua", "english": "Mare" }, { "spanish": "Zorro", "english": "Fox" }, { "spanish": "Solitario", "english": "Tape worm" } ]}'; | |
var cities = '{ "cities": [ { "spanish": "el aeropuerto", "english": "Air Port" }, { "spanish": "El anticuario", "english": "Antique Shop" }, { "spanish": "el ÃÂárbol", "english": "Tree" }, { "spanish": "El autobÃÂús", "english": "Bus" }, { "spanish": "el banco", "english": "Bank" }, { "spanish": "el cafÃÂé", "english": "Cafe" }, { "spanish": "el cafÃÂé internet", "english": "Internet Cafe" }, { "spanish": "El campo", "english": "Country" }, { "spanish": "el cementrairo", "english": "Cementary" }, { "spanish": "el centro comercial", "english": "Mall" }, { "spanish": "el cÃÂésped", "english": "Lawn/Grass" }, { "spanish": "el cine", "english": "Movie Theather" }, { "spanish": "el carro, el coche", "english": "Car" }, { "spanish": "el correo", "english": "Post office" }, { "spanish": "el cuadro", "english": "Block" }, { "spanish": "el edificio", "english": "Building" }, { "spanish": "el estadio", "english": "Stadium" }, { "spanish": "el estacionamiento", "english": "Parking Lot" }, { "spanish": "el gimnasio", "english": "Gym" }, { "spanish": "el hopsital", "english": "Hospital" }, { "spanish": "el jardÃÂÃÂn", "english": "Graden" }, { "spanish": "el lago", "english": "Lake" }, { "spanish": "el mercado", "english": "Market" }, { "spanish": "el mueso", "english": "Mueseum" }, { "spanish": "el Fuente", "english": "Fountain" }, { "spanish": "el parque", "english": "Park" }, { "spanish": "el piso", "english": "Floor (Story of the house)" }, { "spanish": "el puente", "english": "Bridge" }, { "spanish": "el quiosco", "english": "Kiosk" }, { "spanish": "el restaurante", "english": "Resturant" }, { "spanish": "el rÃÂÃÂo", "english": "River" }, { "spanish": "el supermercado", "english": "Super Market" }, { "spanish": "el teatro", "english": "Theater" }, { "spanish": "el zoolÃÂógico", "english": "zoo" }, { "spanish": "la acera", "english": "Side-Walk" }, { "spanish": "La avenida", "english": "Avenue" }, { "spanish": "la biblioteca", "english": "Library" }, { "spanish": "la calle", "english": "Street" }, { "spanish": "la camioneta", "english": "Truck" }, { "spanish": "La carnicerÃÂÃÂa", "english": "Brewery" }, { "spanish": "la discoteca", "english": "Dance Club" }, { "spanish": "La escuela", "english": "School" }, { "spanish": "la estaciÃÂón de bomberos", "english": "Fire Station" }, { "spanish": "la estaciÃÂón de tren", "english": "Train Station" }, { "spanish": "le floristerÃÂÃÂa", "english": "Flower Shop" }, { "spanish": "La galerÃÂÃÂa de arte", "english": "Art Gallery" }, { "spanish": "La gasolinera", "english": "Gas Station" }, { "spanish": "La estaciÃÂón de policÃÂÃÂa", "english": "Police Station" }, { "spanish": "La iglesia", "english": "Church" }, { "spanish": "La joyerÃÂÃÂa", "english": "Jewlery Shop" }, { "spanish": "La LiberÃÂÃÂa", "english": "Book Store" }, { "spanish": "La oficina del dentista", "english": "Dentist Office" }, { "spanish": "la panaderÃÂÃÂa", "english": "Bakery" }, { "spanish": "La peluquerÃÂÃÂa", "english": "Hair Salon" }, { "spanish": "la piscina", "english": "Pool" }, { "spanish": "la playa", "english": "Beach" }, { "spanish": "la plaza", "english": "Square" }, { "spanish": "la tienda de comestiblies", "english": "Grocery Store" }, { "spanish": "la tienda de juguetes", "english": "Toy Store" }, { "spanish": "la tienda de ropa", "english": "Clothing Store" }, { "spanish": "La zapaterÃÂÃÂa", "english": "Shoe Store" }, { "spanish": "Las montaÃÂñas", "english": "Mountains" }, { "spanish": "la ciudod", "english": "City" }, { "spanish": "Los Lugares", "english": "Places" }, { "spanish": "Las Direcciones", "english": "Directions" }, { "spanish": "a la derecha (de)", "english": "To the right of" }, { "spanish": "a la izquierda (de)", "english": "Next To" }, { "spanish": "detrÃÂás(de)", "english": "Behind" }, { "spanish": "entre", "english": "Between" }, { "spanish": "encima (de)", "english": "On top of" }, { "spanish": "enfrente (de)", "english": "infront of" }, { "spanish": "lejos (de)", "english": "Far From" }, { "spanish": "cerca (de)", "english": "Close to" }, { "spanish": "delante (de)", "english": "Infront" }, { "spanish": "debajo (de)", "english": "Below or Under" }, { "spanish": "nor", "english": "north" }, { "spanish": "sur", "english": "South" }, { "spanish": "este", "english": "East" }, { "spanish": "Oeste", "english": "West" }, { "spanish": "al cruz (de)", "english": "Across From" } ]}'; | |
var household = '{ "household": [ { "spanish": "el amario", "english": "closet" }, { "spanish": "el baÃÂño", "english": "bathroom" }, { "spanish": "la basura", "english": "trash can" }, { "spanish": "la calefacciÃÂón", "english": "heating" }, { "spanish": "la chimenea", "english": "fireplace" }, { "spanish": "la cocina", "english": "kitchen" }, { "spanish": "el comedor", "english": "dining room" }, { "spanish": "el cuarto", "english": "room" }, { "spanish": "la escalera", "english": "stairs" }, { "spanish": "el garaje", "english": "garage" }, { "spanish": "la habitaciÃÂón", "english": "bedroom" }, { "spanish": "la lavanderÃÂÃÂa", "english": "laundry room" }, { "spanish": "el pasillo", "english": "hall" }, { "spanish": "la piscina", "english": "pool" }, { "spanish": "el piso", "english": "apartment" }, { "spanish": "la planta baja", "english": "first floor" }, { "spanish": "la terraza", "english": "terrace" }, { "spanish": "la alfombra", "english": "rug" }, { "spanish": "la butaca", "english": "chair" }, { "spanish": "la cama", "english": "bed" }, { "spanish": "la cÃÂómoda", "english": "dresser" }, { "spanish": "la cortina", "english": "curtains" }, { "spanish": "el cuadro", "english": "painting" }, { "spanish": "el espejo", "english": "mirror" }, { "spanish": "la lÃÂámpara", "english": "lamp" }, { "spanish": "el sofÃÂá", "english": "sofa" }, { "spanish": "la aspiradora", "english": "vacuum cleaner" }, { "spanish": "la lavadora", "english": "washer" }, { "spanish": "el lavaplatos", "english": "dishwasher" }, { "spanish": "el microondas", "english": "microwave" }, { "spanish": "el radio", "english": "radio" }, { "spanish": "el refrigerador", "english": "refrigerator" }, { "spanish": "la secadora", "english": "dryer" }, { "spanish": "el ventilador", "english": "fan" }, { "spanish": "la sÃÂábana", "english": "sheet" }, { "spanish": "la baÃÂñera", "english": "bathtub" }, { "spanish": "el inodoro", "english": "toliet" }, { "spanish": "el jabÃÂón", "english": "soap" }, { "spanish": "el lavabo", "english": "bathroom sink" }, { "spanish": "la toalla", "english": "towel" }, { "spanish": "la estufa", "english": "stove" }, { "spanish": "el fregadero", "english": "kitchen sink" }, { "spanish": "el plato", "english": "plate" }, { "spanish": "la barbacoa", "english": "barbecue pit" }, { "spanish": "el cÃÂésped", "english": "lawn" }, { "spanish": "la ducha", "english": "shower" } ]}'; | |
var sports = '{ "sports": [ { "spanish": "el equipo", "english": "team" }, { "spanish": "ganar", "english": "to win" }, { "spanish": "el gol", "english": "goal" }, { "spanish": "jugar (eu)", "english": "to play" }, { "spanish": "el partido", "english": "game" }, { "spanish": "la tienda de deportes", "english": "sporting goods store" }, { "spanish": "andar en patineta", "english": "to skateboard" }, { "spanish": "el baloncesto", "english": "basketball (game)" }, { "spanish": "el bÃÂéisbol", "english": "baseball (game)" }, { "spanish": "esquiar", "english": "to ski" }, { "spanish": "el fÃÂútbol", "english": "soccer" }, { "spanish": "el fÃÂútbol americano", "english": "football (US)" }, { "spanish": "el hockey", "english": "hockey" }, { "spanish": "levantar pesas", "english": "to lift weights" }, { "spanish": "el surfing", "english": "surfing" }, { "spanish": "el tenis", "english": "tennis" }, { "spanish": "el voleibol", "english": "volleyball" }, { "spanish": "el bate", "english": "bat" }, { "spanish": "la bola", "english": "ball" }, { "spanish": "el casco", "english": "helmet" }, { "spanish": "la gorra", "english": "baseball cap" }, { "spanish": "el guante", "english": "glove" }, { "spanish": "los patines", "english": "skates" }, { "spanish": "la patineta", "english": "(the) skateboard" }, { "spanish": "la pelota", "english": "(the) baseball" }, { "spanish": "la raqueta", "english": "racket" }, { "spanish": "al aire libre", "english": "outdoors" }, { "spanish": "el campo", "english": "field" }, { "spanish": "la cancha", "english": "court" }, { "spanish": "el estadio", "english": "stadium" }, { "spanish": "la piscina", "english": "swimming pool" }, { "spanish": "sobre hielo", "english": "on ice" }, { "spanish": "cerrar (ie)", "english": "to close" }, { "spanish": "empezar (ie)", "english": "to begin" }, { "spanish": "entender (ie)", "english": "to understand" }, { "spanish": "favorito(a)", "english": "favorite" }, { "spanish": "loco(a)", "english": "crazy" }, { "spanish": "merendar (ie)", "english": "to have a snack" }, { "spanish": "peligroso(a)", "english": "dangerous" }, { "spanish": "pensar (ie)", "english": "to think, to plan" }, { "spanish": "perder (ie)", "english": "to lose" } ]}'; | |
var animalsJSON = JSON.parse(animals); | |
var citiesJSON = JSON.parse(cities); | |
var householdJSON = JSON.parse(household); | |
var sportsJSON = JSON.parse(sports); | |
var wordsDone = 0; | |
var wordsRight = 0; | |
var accuracy = 100.0; | |
var setSize = 4; | |
var counter = 0; | |
var setIndex = Math.floor((Math.random()*setSize)); | |
var quizzing = false; | |
var currWord; | |
var currDef; | |
var idle = true; | |
var context; | |
var wordsToDisplay = new Array(); | |
function drawModeName(name) { | |
upperBase = 40; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawSecondLine(name) { | |
upperBase = 90; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawTextLine(text, _number) { | |
var number = _number; | |
if ( number === undefined ) { | |
console.log("No number given, setting to 0"); | |
number = 0; | |
} | |
baseline = 88 + 100 * number; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '60pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(text, 10, baseline); | |
} | |
function clearCanvas() { | |
context.fillStyle = "rgb(0, 0, 0)"; | |
context.fillRect(0, 0, 640, 360); | |
} | |
Date.prototype.today = function () { | |
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear(); | |
} | |
Date.prototype.timeNow = function () { | |
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds(); | |
} | |
// MAIN | |
function draw() { | |
drawTextLine("Click for another word", 1); | |
if (showDashboard) { | |
// clearCanvas(); | |
// drawTextLine('Tests Taken: '+wordsDone,0); | |
// drawTextLine('Accuracy: '+accuracy+'%',1); | |
} | |
// list of last times | |
// drawModeName("" + i); | |
// drawSecondLine(secondLineText); | |
} | |
currentTimeString = function () { | |
return new Date().today() + " @ " + new Date().timeNow(); | |
} | |
timeString = function(date) { | |
return date.today() + " @ " + date.timeNow(); | |
} | |
function server() { | |
WS.wake(); | |
if (!DBG) WS.serverConnect('0.0.0.0', null); | |
WS.log('Welcome to WearScript'); | |
// WS.say('Welcome to WearScript'); | |
WS.sound('SUCCESS'); | |
WS.dataLog(true, false, 1); | |
WS.sensorOn("battery", 1, function (data) { | |
console.log("Got battery callback"); | |
console.log(JSON.stringify(data)); | |
batteryLevelText = "Battery Level: " + Math.round(data.values[0] * 100) + "%"; | |
if (Math.round(data.values[0] * 100) <= 20) WS.say("Low battery."); | |
batteryLevelText += " @ " + new Date(parseInt(data.timestamp * 1000)).timeNow(); | |
}); | |
clearCanvas(); | |
drawModeName("Rock and roll"); | |
// draw(); | |
var createDisplay = function(wordsDone,accuracy){ | |
WS.activityDestroy(); | |
setIndex = Math.floor((Math.random()*setSize)); | |
var tree = new WS.Cards(); | |
var roundedAcc = Math.round(accuracy * 100) / 100; | |
tree.add('Words Quizzed: '+wordsDone+'\n'+'Accuracy: '+roundedAcc+'%', 'Tap for a new word!',undefined,createQuiz); | |
WS.cardTree(tree); | |
WS.displayCardTree(); | |
} | |
var test = function(wordsDone,accuracy){ | |
var temp = accuracy; | |
if(quizzing){ | |
var ansTree = new WS.Cards(); | |
ansTree.add(decodeURIComponent(escape(currWord))+'\n'+decodeURIComponent(escape(currDef)),''); | |
WS.cardTree(ansTree); | |
WS.displayCardTree(); | |
setTimeout(function() { | |
quizzing = false; | |
test(wordsDone,accuracy); | |
}, 4000); | |
return | |
} | |
if(counter>4){ | |
createDisplay(wordsDone,accuracy); | |
counter = 0; | |
idle = true; | |
} | |
else{ | |
idle = false; | |
quizzing = true; | |
createQuiz(); | |
} | |
} | |
var processWord = function(w, d){ | |
word = w; | |
def = d; | |
WS.say(word); | |
var incorrectPhrase= "incorrect. The correct definition is: " + def; | |
WS.speechRecognize(decodeURIComponent(escape(word)), function speech(data) {if(def.toUpperCase().indexOf(data.toUpperCase())!=-1){WS.say('correct');wordsRight+=1;}else{WS.say(incorrectPhrase);}wordsDone+=1;accuracy=100*wordsRight/wordsDone;counter+=1;test(wordsDone,accuracy);}); | |
} | |
//processWord('goodbye','hello'); | |
var swipe_callback = function(){ | |
var tempTree = new WS.Cards();tempTree.add('Tap for a new word!','');WS.cardTree(tempTree);WS.displayCardTree(); | |
WS.say('CALLBACK!'); | |
createQuiz(); | |
console.log('!!!!!!!!!!!!!!!!!!!!callback!!!!!!!!!!!!!!!!!!!!!'); | |
} | |
var createQuiz = function(){ | |
quizzing = true; | |
var quiztree = new WS.Cards(); | |
if(setIndex==0){ | |
var currentSetSize=animalsJSON.animals.length; | |
for (var i=0;i<1;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)) | |
quiztree.add('','',processWord(animalsJSON.animals[wordIndex].spanish,animalsJSON.animals[wordIndex].english),function(){swipe_callback();}); | |
currWord = animalsJSON.animals[wordIndex].spanish; | |
currDef = animalsJSON.animals[wordIndex].english; | |
} | |
} | |
else if(setIndex==1){ | |
var currentSetSize=citiesJSON.cities.length; | |
for (var i=0;i<1;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)) | |
quiztree.add('','',processWord(citiesJSON.cities[wordIndex].spanish,citiesJSON.cities[wordIndex].english),function(){swipe_callback();}); | |
currWord = citiesJSON.cities[wordIndex].spanish; | |
currDef = citiesJSON.cities[wordIndex].english; | |
} | |
} | |
else if(setIndex==2){ | |
var currentSetSize=householdJSON.household.length; | |
for (var i=0;i<1;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)) | |
quiztree.add('','',processWord(householdJSON.household[wordIndex].spanish,householdJSON.household[wordIndex].english),function(){swipe_callback();}); | |
currWord = householdJSON.household[wordIndex].spanish; | |
currDef = householdJSON.household[wordIndex].english; | |
} | |
} | |
else if(setIndex==3){ | |
var currentSetSize=sportsJSON.sports.length; | |
for (var i=0;i<1;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)) | |
quiztree.add('','',processWord(sportsJSON.sports[wordIndex].spanish,sportsJSON.sports[wordIndex].english),function(){swipe_callback();}); | |
currWord = sportsJSON.sports[wordIndex].spanish; | |
currDef = sportsJSON.sports[wordIndex].english; | |
} | |
} | |
WS.cardTree(quiztree); | |
WS.displayCardTree(); | |
} | |
createDisplay(0,0); | |
var processScenery = function(wordsToDisplay,context,index){ | |
WS.wake(); | |
w = wordsToDisplay[0][0]; | |
d = wordsToDisplay[0][1]; | |
c = context; | |
displayScenery(w,d,c); | |
} | |
var displayScenery = function(w,d,c){ | |
WS.wake(); | |
var tree = new WS.Cards(); | |
tree.add(decodeURIComponent(escape(w))+'\n'+d,c); | |
WS.cardTree(tree); | |
WS.displayCardTree(); | |
} | |
var newWord = function(){ | |
if(sceneryMode){ | |
WS.wake(); | |
// display a new word. | |
processScenery(wordsToDisplay,context); | |
wordsToDisplay.splice(0, 1); | |
if(wordsToDisplay.length==0){ | |
sceneryMode=false; | |
createDisplay(wordsDone,accuracy); | |
} | |
WS.wake(); | |
} | |
} | |
var wakeUp = function(){ | |
if(idle){ | |
sceneryMode = true; | |
setIndex = Math.floor((Math.random()*setSize)); | |
if(setIndex==0){ | |
var currentSetSize=animalsJSON.animals.length; | |
for (var i=0;i<6;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)); | |
wordsToDisplay.push([animalsJSON.animals[wordIndex].spanish,animalsJSON.animals[wordIndex].english]); | |
context = 'animals'; | |
} | |
} | |
else if(setIndex==1){ | |
var currentSetSize=citiesJSON.cities.length; | |
for (var i=0;i<6;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)); | |
wordsToDisplay.push([citiesJSON.cities[wordIndex].spanish,citiesJSON.cities[wordIndex].english]); | |
context = 'cities'; | |
} | |
} | |
else if(setIndex==2){ | |
var currentSetSize=householdJSON.household.length; | |
for (var i=0;i<6;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)); | |
wordsToDisplay.push([householdJSON.household[wordIndex].spanish,householdJSON.household[wordIndex].english]); | |
context = 'household'; | |
} | |
} | |
else if(setIndex==3){ | |
var currentSetSize=sportsJSON.sports.length; | |
for (var i=0;i<6;i++) | |
{ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)); | |
wordsToDisplay.push([sportsJSON.sports[wordIndex].spanish,sportsJSON.sports[wordIndex].english]); | |
context = 'sports'; | |
} | |
} | |
} | |
} | |
setInterval(wakeUp,wakeInterval); | |
setInterval(newWord,wordInterval); | |
// WS.wake(); | |
// WS.activityCreate(); | |
// Below this are more examples, uncomment to use them | |
WS.liveCardCreate(true, .2); | |
WSRAW.recordWSVideo(videoLength); | |
/* | |
var tree = new WS.Cards(); | |
tree.add('Body text', 'Footer text', function () {WS.say('selected')}, function () {WS.say('tapped')}, 'Menu0', function () {WS.say('menu0')}, 'Menu1', function () {WS.say('menu1')}); | |
tree.add('Body text', 'Footer text', (new WS.Cards()).add('Child0', '0').add('Child1', '1')); | |
WS.cardTree(tree); | |
WS.displayCardTree(); | |
*/ | |
/* | |
WS.speechRecognize('Say Something', function (data) { | |
WS.log('speech: ' + data); | |
WS.say('you said ' + data); | |
}); | |
*/ | |
//WS.cameraPhoto(); | |
//WS.cameraVideo(); | |
//WS.cameraOff(); | |
//WS.shutdown(); | |
} | |
function main() { | |
if (WS.scriptVersion(1)) return; | |
context = 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