Skip to content

Instantly share code, notes, and snippets.

@ondrek
Created January 21, 2014 09:28
Show Gist options
  • Save ondrek/8537022 to your computer and use it in GitHub Desktop.
Save ondrek/8537022 to your computer and use it in GitHub Desktop.
Leap Motion Code to listing in my book TurnJs with it
$(document).ready(function() {
var ctl = new Leap.Controller({enableGestures: true});
var swiper = ctl.gesture('swipe');
var totalDistance = 0;
var tolerance = 50;
var cooloff = 300;
var x = 2, y = 2;
var turnLock = false;
function turn( direction )
{
if ( turnLock )
return;
console.log( "flip to > " + direction );
flipbook.turn( direction );
// prevents flipping all through the book at once
turnLock = true;
setTimeout( function()
{
turnLock = false;
}, 400 );
}
swiper.update(function(g) {
if (Math.abs(g.translation()[0]) > tolerance || Math.abs(g.translation()[1]) > tolerance) {
var xDir = Math.abs(g.translation()[0]) > tolerance ? (g.translation()[0] > 0 ? -1 : 1) : 0;
var yDir = Math.abs(g.translation()[1]) > tolerance ? (g.translation()[1] < 0 ? -1 : 1) : 0;
if (xDir===1 && yDir===0) { turn('previous'); }
else if (xDir===-1 && yDir===0) { turn('next'); }
}
});
ctl.connect();
});
@alan19031216
Copy link

Hello, i got some problem in this code ....
Uncaught ReferenceError: flipbook is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment