Inspiration
The Conway's Game of Life is a simple zero player game that has four fundamental rules(from Wikipedia):
- Any live cell with fewer than two live neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The system itself is Turing complete and can simulate Turing machines. Our idea was to replicate a simple version this system by randomizing the initial values and visualize the output data produced.
What it does
This simple python code randomizes the initial position and plays the game using the rules as stated above.
def initialise(x):
previous=np.zeros(x*x,dtype='i')
current=np.zeros(x*x,dtype='i')
samp=np.random.randint(0,x*x,size=int((x*x)/2))
previous[samp]=1
return previous.reshape(x,x),current.reshape(x,x)
How we built it
The rules of the game can be converted to python code by referencing the state of 8 squares that surround it (3 for corner squares and 5 for edge squares). We can then predict the state of the current square in the next generation.
def neighbours(i,j,old,size):
s=0
for x in [i-1, i, i+1]:
for y in [j-1, j, j+1]:
if(x == i and y == j):
continue
if(x !=size and y !=size):
s += old[x][y]
elif(x == size and y !=size):
s += old[0][y]
elif(x != size and y == size):
s += old[x][0]
else:
s += old[0][0]
return s;
We can proceed by making a play() function that iterates through the number of generations and saves the image using the pylab library.
Leveraging OpenCV's VideoWriter function we can then make a .mp4 file using the generated images. This is a great way to visualise data in the form of 0's and 1's into video files.
What's next for Python Data Visualization
we would love to work on the same model by initializing the first generation instead of randomizing it. Try out different configurations and make "and" "or" gates using these simple rules!


Log in or sign up for Devpost to join the conversation.