Last active
June 8, 2022 23:47
-
-
Save companje/7990b460ae571e9954fff5847e73a927 to your computer and use it in GitHub Desktop.
Conway Game of Life - 321 bytes in Processing - Code Golf submission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Rick Companje, 2022-06-09, MIT | |
Code Golf submission: Shortest Game of Life | |
289 bytes in Processing/Java | |
https://codegolf.stackexchange.com/questions/3434/shortest-game-of-life | |
grid 100x100 | |
grid wraps around | |
draw custom pattern with mouse | |
*/ | |
void draw(){if(mousePressed){line(pmouseX,pmouseY,mouseX,mouseY);return;} | |
loadPixels();PImage p=get();for(int i=0,x=0,y=0,n=0,w=100,h=100;i<w*h;i++, | |
x=i%w,y=i/w,n=0){for(int j=0;j<9;j++)n+=p.get((x+j%3-1+w)%w,(y+j/3-1+h)%h) | |
/color(0);if(n==3|n!=4)pixels[i]=color(n==3?0:255);}updatePixels();} | |
//ungolfed: | |
void draw() { | |
if (mousePressed) { | |
line(pmouseX, pmouseY, mouseX, mouseY); | |
return; | |
} | |
loadPixels(); | |
PImage p=get(); | |
for (int i=0, x=0, y=0, n=0, w=100, h=100; i<w*h; i++, | |
x=i%w, y=i/w, n=0) { | |
for (int j=0; j<9; j++)n+=p.get((x+j%3-1+w)%w, (y+j/3-1+h)%h)/color(0); | |
if (n==3|n!=4)pixels[i]=color(n==3?0:255); | |
} | |
updatePixels(); | |
} |
Author
companje
commented
Jun 8, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment