Optimized draw.
This commit is contained in:
parent
2e525a59da
commit
2bbf6166c0
26
gol.py
26
gol.py
|
@ -3,29 +3,10 @@ from random import randint
|
|||
|
||||
C_BLACK = (0, 0, 0)
|
||||
C_WHITE = (255, 255, 255)
|
||||
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()
|
||||
|
||||
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:
|
||||
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):
|
||||
|
@ -43,6 +24,7 @@ while True:
|
|||
p_y = 0
|
||||
count += mat_rem[p_y][p_x]
|
||||
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))
|
||||
if state != was_state:
|
||||
mat[y][x] = state
|
||||
set_pixel(x, y, (C_BLACK if state else C_WHITE))
|
||||
show_screen()
|
||||
|
|
Loading…
Reference in New Issue