#MonthOfCode - Day 29: golf

My entry for the 29th day of the month of code. The theme for today is: golf.

Code golf is like real golf: use the fewest number of strokes. Here’s yesterday’s code, reduced by hand from 2170 characters to 772.

Code after the break.

golf.jsview raw
1
document.addEventListener('DOMContentLoaded',function(q,d,c,l,g,s,y,w,P,R,N){y='equestAnimationFrame';w=window;q=w['r'+y]||w['webkitR'+y]||w['mozR'+y]||function(b){setTimeout(b,15)};d=$('#moc-29');c=d[0].getContext('2d');R=Math.random;N=Date.now;d.on('click',function(){s?P[0].x+=2:s=1,l=N(),z();g&&r()});function r(i){g=s=0;i=5;P=[];y=['orange','gray','blue','green','red'];while(i--)P.push({x:0,y:50*(5-i),f:y[i],s:.8+.4*R()});a()}function a(){with(c){clearRect(0,0,500,300);strokeStyle='#333';lineWidth=2;P.forEach(function(p){beginPath();moveTo(0,p.y);lineTo(500,p.y);stroke();fillStyle=p.f;fillRect(p.x,p.y-5,10,10)})}}function z(){P.forEach(function(p,i){if(i)p.x+=(p.s+R())*.01*(N()-l);p.x>490&&!g&&(alert('The '+p.f+ ' player wins!'),g=1)});a();l=N();g||q(z)}r()})