Mouse Proximity

HTML

<span id="stats"></span>

CSS

div {position:absolute;width:50px;height:50px;background-color:#CCC;}

#stats {width:300px;height:75px;position:fixed;bottom:0px;right:0px;z-index:1200;background-color:white;font-size:28px;padding:10px;}

JavaScript

/* TEMPORARY */
function DateDiff(date1,date2) {return date1.getTime() - date2.getTime();}
iterations = [];
/* END TEMPORARY */

cache = [];             // hash table of all elements
affected_tiles = [];    // tiles that have been within the hit area are added to this array
tiles = 500;            // # of tiles to render
columns = 15;           // # of columns
size = 50;              // width/height in px
radius = 300;           // Radius
padding = 10;           // Space between tiles
maxTileSize = 150       // Max tile size

/* Calculate distance based on element and mouse position */
function distance(x1, y1, x2, y2) { return Math.sqrt(Math.pow((x1 - y1), 2) + Math.pow((x2 - y2), 2)); }
/* Rand hex via Paul Irish - http://paulirish.com/2009/random-hex-color-code-snippets/ */
function hex() { return '#' + Math.floor(Math.random() * 16777215).toString(16); }
/* Mod it */
function mod(v,s) {var m = v-(v%s);return (m < 0) ? 0 : m;}
/* Original left/top */
function lt(t) {return {left:parseInt(t.attr("original_left")),top:parseInt(t.attr("original_top"))} }

$(document).ready(function() {
    var html = [];
    for(var x = 0; x < tiles; x++) {html.push("<div></div>");}
    $(document.body).append(html.join(""));
    
    var elms = $("div"), row = 0, col = 0;
    var spacing = size + padding;
    for (var x = 0; x < elms.length; x++) {
        $(elms[x]).css({ backgroundColor: hex(), left: (col * spacing), top: (row * spacing) }).attr("original_left", (col * spacing)).attr("original_top", (row * spacing));
        cache[(col * spacing)+","+(row * spacing)] = {x:(col * spacing),y:(row * spacing),"elm":elms[x]}
        if (col > columns) { col = 0; row++; } else { col++; }
    }
    
    // Mouse move, make magic happen
    $(window).bind("mousemove",function (e) {
        var beginning = new Date();
         // Mouse positions, current tiles array
        var _x = e.pageX, _y = e.pageY, current_tiles = [];
        // Mod the min/max of x/y for cache look up
       ...