public

I recently got one of those 8x8 LED matrices and I was playing with some Game of Life patterns when I found this pretty repeating pattern. I found it by starting with some random patterns. If you look closely you can see the pattern becoming a mirrored version of itself halfway through. Apparently the pattern doesn't repeat like this on an infinite grid but on this wrapping 8x8 grid it does ;-) FYI, the LED matrix is a bicolor one (green/red) and has an I2C interface (http://www.adafruit.com/products/902). I'm using the colors as follows: - newly created cells are green - cells that are at least 10 generations old are red - other living cells are yellow (simultaneously green+red) It's hookup up to my Arduino Uno r3. here's a video: http://www.youtube.com/watch?v=Ee2hOaQ2RDI

  • Download Gist
game of life with 8x8 bicolor led matrix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
/*
I recently got one of those 8x8 LED matrices and I was playing with some Game of Life patterns when I found this pretty repeating pattern. I found it by starting with some random patterns. If you look closely you can see the pattern becoming a mirrored version of itself halfway through. Apparently the pattern doesn't repeat like this on an infinite grid but on this wrapping 8x8 grid it does ;-)
 
FYI, the LED matrix is a bicolor one (green/red) and has an I2C interface (http://www.adafruit.com/products/902). I'm using the colors as follows:
- newly created cells are green
- cells that are at least 10 generations old are red
- other living cells are yellow (simultaneously green+red)
 
It's hookup up to my Arduino Uno r3.
 
here's a video: http://www.youtube.com/watch?v=Ee2hOaQ2RDI
 
*/
 
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
 
boolean cells[8][8];
 
Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
 
// game of life
int next[8][8];
 
void setup() {
Serial.begin(9600);
Serial.write("hello");
 
randomSeed(analogRead(0));
for (int r=0 ; r<8 ; r++) {
for (int c=0 ; c<8 ; c++) {
if (random(2) >0)
next[r][c] = 1;
}
}
matrix.begin(0x70); // pass in the address
}
 
void loop() {
 
game_of_life();
}
 
int current[8][8] =
{ {0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,1,1,1,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0} };
int mod(int a) { return (a+8)%8; }
 
void game_of_life() {
matrix.clear();
// draw
for (int r=0 ; r<8 ; r++) {
for (int c=0 ; c<8 ; c++) {
int color;
if (next[r][c] == 0)
color = 0;
else if (next[r][c] == 1)
color = LED_GREEN;
else if (next[r][c] > 10)
color = LED_RED;
else
color = LED_YELLOW;
matrix.drawPixel(c,r,color);
}
}
matrix.writeDisplay();
// calc next state
for (int r=0 ; r<8 ; r++) {
for (int c=0 ; c<8 ; c++) {
// count alive neighbors
int alive = 0;
alive += current[mod(r+1)][mod(c) ] != 0;
alive += current[mod(r) ][mod(c+1)] != 0;
alive += current[mod(r-1)][mod(c) ] != 0;
alive += current[mod(r) ][mod(c-1)] != 0;
alive += current[mod(r+1)][mod(c+1)] != 0;
alive += current[mod(r-1)][mod(c-1)] != 0;
alive += current[mod(r+1)][mod(c-1)] != 0;
alive += current[mod(r-1)][mod(c+1)] != 0;
if (current[r][c])
if (alive < 2 || alive > 3)
next[r][c] = 0;
else
next[r][c] = current[r][c] + 1;
else
if (alive == 3)
next[r][c] = 1;
}
}
for (int r=0 ; r<8 ; r++) {
for (int c=0 ; c<8 ; c++) {
current[r][c] = next[r][c];
}
}
delay(100);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.