Skip to content

Instantly share code, notes, and snippets.

@kejun
Last active December 23, 2015 19:29
Show Gist options
  • Save kejun/6682745 to your computer and use it in GitHub Desktop.
Save kejun/6682745 to your computer and use it in GitHub Desktop.
javascript:(function(){
var loader = function(url,cb) {
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', url);
script.onload = script.onreadystatechange = function() {
if (!this.readyState ||
this.readyState === 'loaded' ||
this.readyState === 'complete') {
setTimeout(function(){
cb();
},0);
script.onload = script.onreadystatechange = null;
}
};
document.body.insertBefore(script, document.body.childNodes[0]);
};
loader('http://hikejun.com/tmp/headtrackr.min.js',function(){var compare = document.createElement('canvas');
compare.style.cssText = 'position:absolute;left:-1000em;top:-1000em;';
compare.width = 320;
compare.height = 240;
document.body.appendChild(compare);
var video = document.createElement('video');
video.style.cssText = 'position:absolute;left:-1000em;top:-1000em;';
document.body.appendChild(video);
var ht = new headtrackr.Tracker({calcAngles: true, ui: false, headPosition: false});
ht.init(video, compare);
ht.start();
document.addEventListener('headtrackrStatus', function (e) {
console.log(e.status);
});
var ops=[];
document.addEventListener('facetrackingEvent', function (e) {
var angle = (Math.PI/2) - e.angle;
if (angle > 0.3) {
if(ops.length == 1) {
ops.push(1);
}
} else if(angle < -0.3) {
if(ops.length == 1) {
ops.push(2);
}
} else {
if (ops.length > 1 && ops.join('') == '01') {
window.scrollBy(0, window.innerHeight);
} else if(ops.length > 1 && ops.join('') == '02') {
window.scrollBy(0, -window.innerHeight);
}
ops = [0];
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment