Skip to content

Instantly share code, notes, and snippets.

@mdnestor
Last active February 21, 2023 07:24
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 mdnestor/a31cb0d2257de304424e09aecc3196d2 to your computer and use it in GitHub Desktop.
Save mdnestor/a31cb0d2257de304424e09aecc3196d2 to your computer and use it in GitHub Desktop.
import numpy as np
import pygame
from scipy.ndimage import convolve
def game_of_life(state):
kernel = np.array([[2,2,2],[2,1,2],[2,2,2]])
activation = np.vectorize(lambda x: int(5 <= x <= 7))
return activation(convolve(state, kernel, mode='wrap'))
pygame.init()
screen = pygame.display.set_mode((800, 600))
state = np.random.binomial(n=1, p=0.37, size=screen.get_size())
done = False
while not done:
surface = pygame.surfarray.make_surface((255*state))
screen.blit(surface, (0, 0))
state = game_of_life(state)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment