-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexpapster
committed
Aug 3, 2016
1 parent
e0954b3
commit a1ce14d
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | ||
<HTML> | ||
<HEAD> | ||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> | ||
<TITLE>Simple Demonstration of how WebGazer.js works</TITLE> | ||
</HEAD> | ||
<BODY LANG="en-US" LINK="#0000ff" DIR="LTR"> | ||
<div id="mydiv"> | ||
<h1 style="color:#C0C0C0" align="right"> | ||
Click on a few locations within the screen<br> | ||
while looking purposefully at the cursor.<br> | ||
Both clicks and cursor movements<br> | ||
make the predictions more accurate. | ||
</h1> | ||
</div> | ||
|
||
|
||
<script src="build/webgazer.js"></script> | ||
<script> | ||
window.onload = function() { | ||
webgazer.setRegression('ridge') /* currently must set regression and tracker */ | ||
.setTracker('clmtrackr') | ||
.setGazeListener(function(data, clock) { | ||
// console.log(data); /* data is an object containing an x and y key which are the x and y prediction coordinates (no bounds limiting) */ | ||
// console.log(clock); /* elapsed time in milliseconds since webgazer.begin() was called */ | ||
}) | ||
.begin() | ||
.showPredictionPoints(true); /* shows a square every 100 milliseconds where current prediction is */ | ||
|
||
var width = 320; | ||
var height = 240; | ||
var topDist = '0px'; | ||
var leftDist = '0px'; | ||
|
||
var setup = function() { | ||
var video = document.getElementById('webgazerVideoFeed'); | ||
video.style.display = 'block'; | ||
video.style.position = 'absolute'; | ||
video.style.top = topDist; | ||
video.style.left = leftDist; | ||
video.width = width; | ||
video.height = height; | ||
video.style.margin = '0px'; | ||
|
||
webgazer.params.imgWidth = width; | ||
webgazer.params.imgHeight = height; | ||
|
||
var overlay = document.createElement('canvas'); | ||
overlay.id = 'overlay'; | ||
overlay.style.position = 'absolute'; | ||
overlay.width = width; | ||
overlay.height = height; | ||
overlay.style.top = topDist; | ||
overlay.style.left = leftDist; | ||
overlay.style.margin = '0px'; | ||
|
||
document.body.appendChild(overlay); | ||
|
||
var cl = webgazer.getTracker().clm; | ||
|
||
function drawLoop() { | ||
requestAnimFrame(drawLoop); | ||
overlay.getContext('2d').clearRect(0,0,width,height); | ||
if (cl.getCurrentPosition()) { | ||
cl.draw(overlay); | ||
} | ||
} | ||
drawLoop(); | ||
}; | ||
|
||
function checkIfReady() { | ||
if (webgazer.isReady()) { | ||
setup(); | ||
} else { | ||
setTimeout(checkIfReady, 100); | ||
} | ||
} | ||
setTimeout(checkIfReady,100); | ||
}; | ||
|
||
|
||
window.onbeforeunload = function() { | ||
//webgazer.end(); //Uncomment if you want to save the data even if you reload the page. | ||
window.localStorage.clear(); //Comment out if you want to save data across different sessions | ||
} | ||
</script> | ||
|
||
</BODY> | ||
</HTML> |