From 43981fc3af83632dd7e98bcf077e9d58b63a5a1b Mon Sep 17 00:00:00 2001 From: KikooDX Date: Thu, 28 May 2020 19:08:45 +0200 Subject: [PATCH] WIP --- gol.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 gol.py diff --git a/gol.py b/gol.py new file mode 100644 index 0000000..bb2e85d --- /dev/null +++ b/gol.py @@ -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