2020-05-28 19:08:45 +02:00
|
|
|
from casioplot import *
|
|
|
|
from random import randint
|
|
|
|
|
|
|
|
C_BLACK = (0, 0, 0)
|
2020-05-30 16:52:54 +02:00
|
|
|
C_WHITE = (255, 255, 255)
|
|
|
|
mat_height = 32
|
|
|
|
mat_width = 32
|
|
|
|
mat = [[randint(0, 1) for _ in range(mat_width)] for _ in range(mat_height)]
|
2020-05-30 17:07:01 +02:00
|
|
|
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
|
2020-05-28 19:08:45 +02:00
|
|
|
while True:
|
2020-05-30 17:07:01 +02:00
|
|
|
show_screen()
|
2020-05-30 16:52:54 +02:00
|
|
|
mat_rem = [list(e) for e in mat]
|
2020-05-28 19:08:45 +02:00
|
|
|
for y in range(mat_height):
|
|
|
|
for x in range(mat_width):
|
|
|
|
state = mat_rem[y][x]
|
2020-05-30 16:52:54 +02:00
|
|
|
was_state = state
|
|
|
|
count = 0
|
2020-05-28 19:08:45 +02:00
|
|
|
for i in range(-1, 2):
|
|
|
|
for j in range(-1, 2):
|
2020-05-30 16:52:54 +02:00
|
|
|
if not (i or j):
|
|
|
|
continue
|
2020-05-28 19:08:45 +02:00
|
|
|
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]
|
2020-05-30 16:52:54 +02:00
|
|
|
state = int((count == 3) or (state and count == 2))
|
2020-05-30 16:56:28 +02:00
|
|
|
if state != was_state:
|
|
|
|
mat[y][x] = state
|
|
|
|
set_pixel(x, y, (C_BLACK if state else C_WHITE))
|