User:Svip/brains.js

/* Brain cursor chaser, version [0.0.4] Originally from: Splarka

Notes:
 * Full of constants that can be tweaked.
 * Doesn't /have/ to be brains, but that was the design.
 * Movement is random, a smoother circular movement system might be cooler.



var ismsie = (navigator.appName.toLowerCase.indexOf('internet explorer') != -1); var scrW, scrH, mouseX, mouseY, brainX = [0], brainY = [0], brainTimer; var brainR = 'http://img505.imageshack.us/img505/4064/brainr.png'; var brainL = 'http://img505.imageshack.us/img505/7910/brainl.png';

function initBrains { var docobj = document.getElementById('globalWrapper') || document.body; appendCSS('.brain {position:absolute;z-index:3;}'); for(var i=0;i<5;i++) { var img = document.createElement('img'); img.src = 'file:///c:/goldrush/js/wiki/brain-r.png'; img.id = 'brain-' + i;   brainX[i] = rand(10,150); brainY[i] = rand(10,150); img.style.left = (brainX[i] - 24) + 'px'; img.style.top = (brainY[i] - 20) + 'px'; img.style.zIndex = rand(2,4); img.className = 'brain'; docobj.appendChild(img); } screenResizeBrains; if(!ismsie) document.captureEvents(Event.MOUSEMOVE) addHandler(document,'mousemove',mousemoveBrains); addHandler(window,'resize',screenResizeBrains); brainTimer = setTimeout('moveBrains',1000); } addOnloadHook(initBrains);

function moveBrains { try { if(brainTimer != null) { clearTimeout(brainTimer); brainTimer = null; } } catch (e) { return; } if(!mouseX || !mouseY) return mx = mouseX; my = mouseY; var brains = getElementsByClassName(document.body,'img','brain'); for(var i=0;i 1) { dr = 1 / parseFloat(dr); dx = (1 - dr / 2); dy = dr / 2; } else { dx = dr / 2; dy = (1 - dr / 2); }   if(bx > mx) { b.src = brainL; dx = -dx; } else { b.src = brainR; }   if(by > my) dy = -dy brainX[i] += dx*15 + rand(-8,8); brainY[i] += dy*15 + rand(-8,8); b.style.left = (brainX[i] - 24) + 'px'; b.style.top = (brainY[i] - 20) + 'px'; } brainTimer = setTimeout('moveBrains',100); }

window.onresize = screenResizeBrains; function mousemoveBrains(e) { try { var debug = document.getElementById('debug'); if(ismsie) { var mx = event.clientX + document.body.scrollLeft; var my = event.clientY + document.body.scrollTop; } else { var mx = e.pageX; var my = e.pageY; }   if (mx < 0) mx = 0 if (my < 0) my = 0 mouseX = mx; mouseY = my; if(brainTimer == null) brainTimer = setTimeout('moveBrains',100) } catch (e) { return; } }

function screenResizeBrains { var docElement = (document.compatMode=='CSS1Compat') ? document.documentElement : document.body scrW = docElement.clientWidth; scrH = docElement.clientHeight; }

function rand(n,z) { var s = (!z) ? 0 : z  return Math.floor(Math.random * (n - s) + s); }