Skip to content

Instantly share code, notes, and snippets.

@janispritzkau
Last active August 21, 2019 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janispritzkau/d90a165a9da99f1fb224f8cf3d091b92 to your computer and use it in GitHub Desktop.
Save janispritzkau/d90a165a9da99f1fb224f8cf3d091b92 to your computer and use it in GitHub Desktop.
Code golf: Game of Life (286 bytes)
<canvas id="c"><script>t=c.getContext("2d"),s=150,a=[];for(i=s*s;i--;)a[i]=Math.random()<.1;setInterval(_=>{b=[],t.clearRect(0,0,s,s);for(i=s*s;i--;){n=0;for(j=9;j--;)n+=a[(~~(i/s)+s+j%3-1)%s*s+(i+s+~~(j/3)-1)%s];b[i]=n==3||n-a[i]==3,a[i]&&t.fillRect((i%s),~~(i/s),1,1)}a=b},s)</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment