Skip to content

Instantly share code, notes, and snippets.

Last active February 21, 2023 07:24
What would you like to do?
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'))
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment