From 2e525a59dab3a56a6075bfcf8bc04243554c0877 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Sat, 30 May 2020 16:52:54 +0200 Subject: [PATCH] Functionnal --- gol.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/gol.py b/gol.py index bb2e85d..abdcae3 100644 --- a/gol.py +++ b/gol.py @@ -2,6 +2,7 @@ from casioplot import * from random import randint C_BLACK = (0, 0, 0) +C_WHITE = (255, 255, 255) def draw_mat(mat): clear_screen() x = 0 @@ -15,31 +16,33 @@ def draw_mat(mat): 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 +frameskip = 1 +framecount = 0 +mat_height = 32 +mat_width = 32 +mat = [[randint(0, 1) for _ in range(mat_width)] for _ in range(mat_height)] while True: - draw_mat(mat) - mat_rem = mat + framecount += 1 + if framecount == frameskip: + framecount = 0 + draw_mat(mat) + mat_rem = [list(e) for e in mat] for y in range(mat_height): for x in range(mat_width): state = mat_rem[y][x] - count = -state + was_state = state + count = 0 for i in range(-1, 2): for j in range(-1, 2): + if not (i or j): + continue 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 + state = int((count == 3) or (state and count == 2)) mat[y][x] = state + #if state != was_state: + # set_pixel(x, y, (C_BLACK if state else C_WHITE))