Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2, numpy as np
- from scipy.ndimage import correlate
- img = (cv2.cvtColor(cv2.imread("start.png"),cv2.COLOR_BGR2GRAY)/255+.5).astype("uint8")
- mask = np.array([[1,1,1],[1,0,1],[1,1,1]])
- while True: # main loop
- summed = correlate(img,mask,mode="constant") # neighbor count of each cell
- img = (np.logical_and((summed == 2) + (summed == 3), img) + np.logical_and(summed == 3, 1-img)).astype("uint8") # game of life rules
- cv2.imshow("Conway's Game of Life", img*255) # show image
- if cv2.waitKey(1) == 27: # stop sim if esc key is pressed
- break
Advertisement
Add Comment
Please, Sign In to add comment