Skip to content

Instantly share code, notes, and snippets.

@fluidglassml
Created April 24, 2014 17:11
Show Gist options
  • Save fluidglassml/11262145 to your computer and use it in GitHub Desktop.
Save fluidglassml/11262145 to your computer and use it in GitHub Desktop.
[wearscript] Costello Myo
<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>
var abbott = ["Strange as it may seem, they give ball players nowadays very peculiar names. ","Nicknames, nicknames. Now, on the St. Louis team we have Who's on first, What's on second, I Don't Know is on third-- ","I'm telling you. Who's on first, What's on second, I Don't Know is on third-- ","Yes. ","Yes. ","Who. ","Who. ","Who is on first. ","I'm not asking you--I'm telling you. Who is on first. ","That's the man's name. ","Yes. "];
var costello = ["Funny names? ","That's what I want to find out. I want you to tell me the names of the fellows on the St. Louis team. ","You know the fellows' names? ","Well, then who's playing first? ","I mean the fellow's name on first base. ","The fellow playin' first base. ","The guy on first base. ","Well, what are you askin' me for? ","I'm asking you--who's on first? ","That's who's name? "];
var lines = [];
var rand = Math.floor(Math.random()*10000).toString();
console.log("My rand is " + rand);
var currentLine = 0;
var role;
role = "Costello";
lines = costello;
function getLines(){
WS.publish()
}
function speakLine(line) {
return function(){WS.say(line);};
}
function showLine(i) {
var tree = new WS.Cards();
tree.add(lines[i], role, speakLine(lines[i]));
tree.add("Stand by for your next line", role, function() {WS.say("line done"); WS.publish("lineDone", {actor: role, line: currentLine});}, "reset", function () {WS.publish("reset", "dummydata"); WS.say("reset");});
WS.cardTree(tree);
}
showLine(currentLine);
WS.displayCardTree();
function batteryCB(data) {
console.log(JSON.stringify(data));
WS.publish("battery", {"level": data["values"][0]});
}
function advanceCB(channel, data) {
WS.say("advance");
console.log("advance: " + JSON.stringify(data));
console.log("I am actor " + data.actor);
if (data.actor != "Abbott") {
currentLine++;
showLine(currentLine);
}
}
function nextLine() {
currentLine++;
showLine(currentLine);
}
function reset() {
currentLine = 0;
showLine(currentLine);
}
function server() {
// WS.publish("newglass", rand);
// WS.subscribe("actor", actor_cb);
WS.sensorOn("battery", .2, batteryCB);
WS.subscribe("lineDone", advanceCB);
WS.subscribe("reset", resetCB);
WS.subscribe("director", directorCB);
}
function directorCB(channel, data) {
if (data.role == role) nextLine();
if (data.command == 'reset') reset();
}
function resetCB() {
currentLine = 0;
showLine(currentLine);
}
function main() {
if (WS.scriptVersion(1)) return;
ctx = document.getElementById('canvas').getContext("2d");
// WS.serverConnect('ws://glassprov.media.mit.edu:8080/ws', server);
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script>
</body>
</html>
{"name":"Costello Myo"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment