Skip to content

Instantly share code, notes, and snippets.

@javisantana
Created May 8, 2011 11:21
Show Gist options
  • Save javisantana/961312 to your computer and use it in GitHub Desktop.
Save javisantana/961312 to your computer and use it in GitHub Desktop.
game of life in javascript < 512b
<body bgcolor=0><canvas id=R width=64 height=64 style=width:2in;height:2in;background:#fff><script>K=R.getContext('2d');c=q2=(q=256)*q;t=[];t2=[];while(c--)t2[c]=t[c]=Math.random()<.1?1:0;ar=[[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1],[1,0],[1, 1]];setInterval("for(s=0,I=K.getImageData(0,0,q,q),c=q2;c--;tt=t2,t2=t,t=tt){for(s=0,a=8;a--;s+=(u=t[c+(x=ar[a])[0]+q*x[1]])==undefined?0:u);I.data[(p=4*c)+1]=q*(t2[c]=((t[c]&&(s>1&&s<4))||s==3)?1:0); I.data[p+3]=q;K.putImageData(I,0,0);}",q);</script></body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment