JS1K

#2: the original

Source for demo by Tom Boshoven.

d=document,l=Math.floor,g=[],r=0,z=50,i=[],v=500,y="option",$=[[],[200,251,299,300,301],[0,49,50,51,99,101,150]];eval('~o(e,f){f.appendChild(k=d.createElement(e));return k}~m(t,x,y){o(y?y:"button",x);k.appendChild(d.createTextNode(t));return k}onload=~(){b=d.body;b.style.margin=0;x=(c=b.children[0]).getContext("2d");o("br",b);c.width=c.height=v;c.onclick=~(e){n=l(e.clientX/10)+l(e.clientY/10)*z;f(g[n],n)};c=o("select",b);m("Empty",c,y);m("Glider",c,y);m("Small Exploder",c,y);(c.onchange=~(){for(a=0;a<z*z;a++)f(0,a,1),f(1,a);for(a in y=$[c.selectedIndex])f(0,y[a]+1075)})();m("Play/Pause",b).onclick=~(){if(r++)r=0,clearTimeout(t);else u()};(j=m("Faster",b)).onclick=m("Slower",b).onclick=~(){v*=this==j?.8:1.25}};~f(b,n,w){s=w?1:2;h=w?8:6;x.fillStyle=(g[n]=!b)?"#000":"#fff";x.fillRect((n%z)*10+s,l(n/z)*10+s,h,h)}~u(){i=g.slice();for(a=0;a<z*z;a++){s=0;for(h=-1;h<2;h++)for(y=-1;y<2;y++)n=y*z+a,b=(a+h)%z,s+=(h|y)&n<z*z&0<n&b<z+h&b>=h&i[n+h];f(i[a]?s&6^2:s!=3,a)}t=setTimeout("u()",v)}'.replace(/~/g,'function '))