Last active
December 20, 2015 05:59
-
-
Save lptr/6082218 to your computer and use it in GitHub Desktop.
Prezi Player API controlled by Leap Motion
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
<!doctype html> | |
<html> | |
<head> | |
<title>Prezi Leap gesture test</title> | |
<script src="http://prezi.github.io/prezi-player/lib/PreziPlayer/prezi_player.js"></script> | |
<script src="http://js.leapmotion.com/0.2.0-beta6/leap.js"></script> | |
<script> | |
// This is the ID of the prezi you want to navigate with your Leap | |
var preziId = "ognosdkexpfy"; | |
var init = function() { | |
var step = 0; | |
var feedback = function(message) { | |
var display = document.getElementById("message"); | |
display.innerHTML = message; | |
console.log(message); | |
} | |
Leap.loop({enableGestures: true}, function(frame) { | |
if (frame.gestures.length == 0) | |
return; | |
for (var i = 0; i < frame.gestures.length; i++) | |
{ | |
var gesture = frame.gestures[i]; | |
if (gesture.type != "swipe" || gesture.state != "start") | |
continue; | |
console.log(frame); | |
if (gesture.pointableIds.length == 0) { | |
feedback("No fingers!"); | |
continue; | |
} | |
var dx = gesture.direction[0]; | |
// Make sure we move horizontally a lot | |
if (Math.abs(dx) < 0.1) { | |
feedback("Not enough horizontal movement: " + dx); | |
continue; | |
} | |
if (dx < 0) { | |
feedback("Moving back"); | |
step--; | |
} else { | |
feedback("Moving forward"); | |
step++; | |
} | |
if (step < 0) step = 0; | |
if (step >= player.getStepCount()) step = player.getStepCount() - 1; | |
player.toStep(step); | |
} | |
}); | |
} | |
</script> | |
</head> | |
<body onload="init();"> | |
<h1>Prezi Leap gesture test</h1> | |
<p>Swipe your fingers left-to-right to move ahead in the prezi, right-to-left to move backwards. If you swipe with one finger, the prezi moves by one frame. If you use more, it moves more.</p> | |
<p>Source: <a href="https://gist.github.com/lptr/6082218">https://gist.github.com/lptr/6082218</a></p> | |
<script>var d=document.createElement('div'), p=document.createElement('script'), pp=document.createElement('script'), incl; incl = function(){ d.id="prezi_player_ufnrer-swszq"; pp.innerHTML="var player = new PreziPlayer('"+d.id+"', {preziId: '" + preziId + "', width: '800', height: '450', controls: true});"; document.body.appendChild(d); document.body.appendChild(pp); }; if (!window.PreziPlayer){ p.src="http://prezi.github.io/prezi-player/lib/prezi_player.js"; document.body.appendChild(p); p.onload = incl; } else { incl(); }</script> | |
<div id="message">Waiting for gesture</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment