[ Launch: leap setup ] 4736524 by enjalot
-
-
Save enjalot/4736524 to your computer and use it in GitHub Desktop.
leap setup
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
{"description":"leap setup","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"leap.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"hud.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/XV1rxwx.png"} |
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
var onoffColors = ["#B40101", "#20B420"]; | |
var svg = d3.select("svg"); | |
var hub = svg.append("g") | |
.classed("hub", true); | |
hub.append("rect") | |
.classed("indicator", true) | |
.attr({ | |
width: 20, | |
height: 20, | |
x: 50, | |
y: 50, | |
stroke: "#000", | |
"stroke-width":2 | |
}) | |
.on("click", tributary.leap.toggle); | |
var hand1 = hub.append("g") | |
.classed("hand", true) | |
.classed("one", true); | |
var hand2 = hub.append("g") | |
.classed("hand", true) | |
.classed("two", true); | |
update(); | |
function update() { | |
hub.select("rect.indicator") | |
.style("fill", tributary.leap.connected ? onoffColors[1] : onoffColors[0]); | |
} | |
tributary.leap.events.off("open"); | |
tributary.leap.events.on("open", function(d) { | |
console.log("open"); | |
update(); | |
}) | |
tributary.leap.events.off("close"); | |
tributary.leap.events.on("close", function(d) { | |
console.log("close"); | |
update(); | |
}) | |
tributary.leap.events.off("frame"); | |
tributary.leap.events.on("frame", function(d) { | |
console.log(d); | |
}) |
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
tributary.leap = { | |
events: _.clone(Backbone.Events) | |
}; | |
// Support both the WebSocket and MozWebSocket objects | |
if ((typeof(WebSocket) == 'undefined') && | |
(typeof(MozWebSocket) != 'undefined')) { | |
WebSocket = MozWebSocket; | |
} | |
// Create the socket with event handlers | |
tributary.leap.init = function() { | |
if(tributary.ws) { | |
tributary.ws.close(); | |
} | |
console.log("Starting"); | |
//Create and open the socket | |
tributary.ws = new WebSocket("ws://localhost:6437/"); | |
var ws = tributary.ws; | |
// On successful connection | |
ws.onopen = function(event) { | |
console.log("Open"); | |
tributary.leap.connected = true; | |
tributary.leap.events.trigger("open"); | |
}; | |
// On message received | |
ws.onmessage = function(event) { | |
tributary.leap.events.trigger("frame", JSON.parse(event.data)); | |
}; | |
// On socket close | |
ws.onclose = function(event) { | |
ws = null; | |
tributary.leap.connected = false; | |
tributary.leap.events.trigger("close"); | |
} | |
//On socket error | |
ws.onerror = function(event) { | |
console.error("Received error"); | |
}; | |
} | |
var socketState; | |
if(!tributary.ws || tributary.ws.readyState != 1) { | |
tributary.leap.connected = false; | |
} else { | |
tributary.leap.connected = true; | |
} | |
tributary.leap.toggle = function() { | |
if(tributary.ws.readyState === 1) { | |
tributary.ws.close(); | |
} else { | |
tributary.leap.init(); | |
} | |
} | |
tributary.leap.init(); | |
tributary.events.on("restart", function() { | |
tributary.leap.init(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment