Close
Sign in to view the code!
Sign in to send to cube!
Conways Game of Life 5755
Created by michi on September 05, 2016
Twitter
Facebook
Conways Game of Life using a 5755 ruleset. Self-repeating.
Comments:
Sign up, to be the first!
Up next
Snake 3D
Update Demo
Sign up, make your own!
#define LifeW 4 #define LifeX 5 #define LifeY 5 #define LifeZ 5 Cube cube = Cube(); boolean health[9][9][9], newHealth[9][9][9]; int color = 0, count; int neighbours(int i, int j, int k) { int x=0; if (health[i][j][k+1] == true) { x++;} if (health[i][j][k-1] == true) { x++;} if (health[i][j+1][k] == true) { x++;} if (health[i][j+1][k+1] == true) { x++;} if (health[i][j+1][k-1] == true) { x++;} if (health[i][j-1][k] == true) { x++;} if (health[i][j-1][k+1] == true) { x++;} if (health[i][j-1][k-1] == true) { x++;} if (health[i+1][j][k] == true) { x++;} if (health[i+1][j][k+1] == true) { x++;} if (health[i+1][j][k-1] == true) { x++;} if (health[i+1][j+1][k] == true) { x++;} if (health[i+1][j+1][k+1] == true) { x++;} if (health[i+1][j+1][k-1] == true) { x++;} if (health[i+1][j-1][k] == true) { x++;} if (health[i+1][j-1][k+1] == true) { x++;} if (health[i+1][j-1][k-1] == true) { x++;} if (health[i-1][j][k] == true) { x++;} if (health[i-1][j][k+1] == true) { x++;} if (health[i-1][j][k-1] == true) { x++;} if (health[i-1][j+1][k] == true) { x++;} if (health[i-1][j+1][k+1] == true) { x++;} if (health[i-1][j+1][k-1] == true) { x++;} if (health[i-1][j-1][k] == true) { x++;} if (health[i-1][j-1][k+1] == true) { x++;} if (health[i-1][j-1][k-1] == true) { x++;} return x; } void setup() { cube.begin(); randomSeed(analogRead(0)); for(int i=0;i<cube.size;i++) { for(int j=0;j<cube.size;j++) { for (int k=0;k<cube.size;k++) { health[i][j][k] = false; } } } do{ count = 0; health[random(0,8)][random(0,8)][random(0,8)] = true; for(int i=0;i<cube.size;i++) { for(int j=0;j<cube.size;j++) { for (int k=0;k<cube.size;k++) { if (health[i][j][k] == true) { count++; } } } } }while (count < 161); for(int i=0;i<cube.size;i++) { for(int j=0;j<cube.size;j++) { for (int k=0;k<cube.size;k++) { if (health[i][j][k] == true) { cube.setVoxel(i,j,k,red); }else { cube.setVoxel(i,j,k,black); } } } } cube.show(); delay(100); } void loop() { randomSeed(analogRead(0)); for(int i=1;i<9;i++) { for(int j=1;j<9;j++) { for (int k=1;k<9;k++) { if (health[i][j][k] == false) { if (neighbours(i,j,k) == 5) { newHealth[i][j][k] = true; } else newHealth[i][j][k] = false; } if (health[i][j][k] == true) { if (neighbours(i,j,k) == 6 || neighbours(i,j,k) == 5 || neighbours(i,j,k) == 7 ) { newHealth[i][j][k] = true; } else newHealth[i][j][k] = false; } } } } if(color == 50) { do{ count = 0; newHealth[random(1,8)][random(1,8)][random(1,8)] = true; for(int i=0;i<cube.size;i++) { for(int j=0;j<cube.size;j++) { for (int k=0;k<cube.size;k++) { if (newHealth[i][j][k] == true) { count++; } } } } }while (count < 80); color=color%30;} for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { for (int k=0;k<9;k++) { health[i][j][k] = newHealth[i][j][k]; if (health[i][j][k] == true) { cube.setVoxel(i-1,j-1,k-1,cube.colorMap(color%30,0,29)); }else { cube.setVoxel(i-1,j-1,k-1,black); } } } } cube.show(); color++; delay(100); }