Created
January 21, 2014 09:28
-
-
Save ondrek/8537022 to your computer and use it in GitHub Desktop.
Leap Motion Code to listing in my book TurnJs with it
This file contains hidden or 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
$(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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, i got some problem in this code ....
Uncaught ReferenceError: flipbook is not defined