PIT

final working version

by Tricia Seow

HTML

<script src="https://rawgit.com/eu81273/jsfiddle-console/master/console.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<div id="canvas"></div>

JavaScript

/**********************
* Domain general code , contains functions to use
**********************/

// Helper functions
function numberRange (start, end) {
  return new Array(end - start).fill().map((d, i) => i + start);
}


function insert_hidden_into_form(findex, name, value ) {
  var form = document.forms[findex];
  var hiddenField = document.createElement('input');
  hiddenField.setAttribute('type', 'hidden');
  hiddenField.setAttribute('name', name);
  hiddenField.setAttribute('value', value );
  form.appendChild( hiddenField );
}

function shuffle(o){
  for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  return o;
}

//function to calculate normal distribution
// Standard Normal variate using Box-Muller transform.
function randn() {
  var u = 0, v = 0;
  while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
    while(v === 0) v = Math.random();
    return Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
  }


  //summing numbers in arrays together
  Array.prototype.SumArray = function (arr) {
    var sum = this.map(function (num, idx) {
      return num + arr[idx];
    });

    return sum;
  }

  //modulus after division functions
  function mod(x,y){
    var mod = x - Math.floor(x/y)*y;
    return mod
  }

  //calucate frame per second - this is for the dot animation
  function calcFPS(a){
    function b(){
      if(f--)c(b);
      else{
        var e=3*Math.round(1E3*d/3/(performance.now()-g));
        "function"===typeof a.callback&&a.callback(e);
        return e}
      }
      var c=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame;
      if(!c)return!0;
      a||(a={});
      var d=a.count||60,f=d,g=performance.now();
      b()
    }


    // linspace function
    function linspace(a,b,n) {
      if(typeof n === "undefined") n = Math.max(Math.round(b-a)+1,1);
      if(n<2) { return n===1?[a]:[]; }
      var i,ret = Array(n);
     ...