Blind spot measuring tool

Just one click...

by John Doe

HTML

<p id="instruction">Press "Start Test"</p>
<ul>
<li><a id="toggle">pause &amp; show results</a></li>
<li><a id="prune">prune data</a></li>
<li><a id="download">Download as image</a></li>
<li><a id="">--</a></li>
</ul>
<p id="log">just some logging information</p>
<canvas width="1000" height="500" id="canvas">Sorry, no canvas available</canvas>
<br/>
<p id="datadump"></p>

CSS

body {
	background-color:#777;
	padding:0;
	margin:0;
	overflow:scroll;
  font-family:sans-serif;
  color:#fff;
}
canvas {
  border:1px solid #000;
  float:left;
  clear:both;
}
ul {
  padding:0;
  padding-left:20px;
  margin:0;
}
li {
  float:left;
  padding:0;
  padding-right:20px;
  margin:0;
}
a {
  cursor:pointer;
  color:#ccc;
}
a:hover {
  color:#fff;
}

JavaScript

/* TODO
* more intelligent poitn choice
  -idea: multiple phases: first a grid, then within the border triangles
  -idea: slowly increase triangleSelectionRatio in order to avoid eliminating too many unicoloured triangles
*/

var cnvs = document.getElementById('canvas'),
    ctx = cnvs.getContext('2d')

var testedPoints = []
//testedPoints = [[cnvs.width * 0.7, cnvs.height * 0.5, true],	[cnvs.width * 0.8, cnvs.height * 0.6, false]]
var triangulation =[]
var testRuns = true
var blinkDuration = 500
var triangleSelectionRatio = 3

function main(){
	printInstruction('Cover your left eye. Stare at the cross with your right eye.  Adjust your position such that your blind spot is in the right half of the black field below. To make a white testing spot appear, press space. After that press "y" if you have seen it. If you did not see the point just continue. If you accidentally presset "y" you can correct that by pressing "n".')
  eraseCanvas()
}
  
// "gameloop"
function dotOn(){
  log("dot on")
  var x = 0
  var y = 0
  if(testRuns){
    /*  Strategically determine new points
    * right now we only attack triangles that are multicoloroed, this is a bad idea as we get smaller and smaller triangles with large unicoloured triangles remaining.
    */
    switch(testedPoints.length){
      case 0:
        x = Math.floor(cnvs.width * 0.95)
        y = Math.floor(cnvs.height * 0.95)
        log('case 0')
        break
      case 1:
        x = Math.floor(cnvs.width * 0.95)
        y = Math.floor(cnvs.height * 0.05)
        log('case 1')
        break
      case 2:
        x = Math.floor(cnvs.width/3)
        y = Math.floor(cnvs.height * 0.05)
        log('case 2')
        break
      case 3:
        x = Math.floor(cnvs.width/3)
        y = Math.floor(cnvs.height * 0.95)
        log('case 3')
			  break
      default:
      	log('case default')
        if(triangulation.length>0){
        	var tind = getNextBestTriangle(triangulation,testedPoints)
          var t =...