Skip to content

Instantly share code, notes, and snippets.

@CamWiseOwl
Last active February 3, 2021 22:27
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 CamWiseOwl/0462869d4efa9f4a08a0bfd96e40ff49 to your computer and use it in GitHub Desktop.
Save CamWiseOwl/0462869d4efa9f4a08a0bfd96e40ff49 to your computer and use it in GitHub Desktop.
Conway's Game of Life, Code Golfed for JS / Canvas to 358 characters.
<canvas/><script>b=document.all[3].getContext("2d");s=50;z=s*s;m=[];n=[];g=(x,y)=>m[x*s+y%s];for(i=z;--i;m[i]=new Date&1);setInterval(()=>{for(i=z;--i;)x=i/s|0,x=g(x,i-1)+g(x+1,i-1)+g(x+1,i)+g(x+1,i+1)+g(x,i+1)+g(x-1,i+1)+g(x-1,i)+g(x-1,i-1),n[i]=3==x||m[i]&&2==x;for(i=z;--i;)b.fillStyle=(m[i]=n[i])?'red':'tan',b.fillRect(i/s*10,i%s*10,10,10)},s)</script>
@CamWiseOwl
Copy link
Author

Removed 80 characters to 358! Removed setting dimensions and cell wrapping code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment