This commit is contained in:
KikooDX 2020-05-28 19:08:45 +02:00
parent fdb3c60f1e
commit 43981fc3af
1 changed files with 45 additions and 0 deletions

45
gol.py Normal file
View File

@ -0,0 +1,45 @@
from casioplot import *
from random import randint
C_BLACK = (0, 0, 0)
def draw_mat(mat):
clear_screen()
x = 0
y = 0
for line in mat:
for cell in line:
if cell:
set_pixel(x, y, C_BLACK)
x += 1
x = 0
y += 1
show_screen()
mat_height = 64
mat_width = 128
mat = [[0 for _ in range(mat_width)] for _ in range(mat_height)]
mat[0][0] = 1
mat[0][1] = 1
mat[0][2] = 1
mat[0][3] = 1
while True:
draw_mat(mat)
mat_rem = mat
for y in range(mat_height):
for x in range(mat_width):
state = mat_rem[y][x]
count = -state
for i in range(-1, 2):
for j in range(-1, 2):
p_x, p_y = x + i, y + j
if p_x == mat_width:
p_x = 0
if p_y == mat_height:
p_y = 0
count += mat_rem[p_y][p_x]
if (state and count in (2, 3)) or ((not state) and count == 3):
state = 1
else:
state = 0
mat[y][x] = state