diff --git a/code.py b/code.py index b7df65e..8db5e9d 100644 --- a/code.py +++ b/code.py @@ -9,7 +9,9 @@ import adafruit_adxl34x import conway # Some functions are in an .mpy module for performance # Starting point: -universe = conway.RANDOM_UNIVERSE(30) +# * VOID, GLIDER, BEATING_HEART, BLOOM, FROG +# * RANDOM_UNIVERSE(percentage) +universe = conway.GLIDER # Create the i2c object for the trellis diff --git a/lib/conway.mpy b/lib/conway.mpy index e69f0ac..6645fd7 100644 Binary files a/lib/conway.mpy and b/lib/conway.mpy differ diff --git a/src/conway.py b/src/conway.py index a0fcfbb..bed9cde 100644 --- a/src/conway.py +++ b/src/conway.py @@ -9,13 +9,13 @@ ON = (80, 80, 50) # Some presets : VOID = [[False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False]] + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False]] GLIDER = [[False, False, False, False, False, False, False, False], [False, False, False, False, True, False, False, False], @@ -35,6 +35,25 @@ BEATING_HEART = [[False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False]] +BLOOM = [[False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, True, True, True, False, False, False], + [False, True, False, True, False, True, False, False], + [False, False, True, True, True, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False]] + +FROG = [[False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, True, True, True, False, False], + [False, False, True, True, True, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False]] + +_EXT_UNIVERSE = [[False for x_ext in range(10)] for y_ext in range(10)] def RANDOM_UNIVERSE(rate): return [[randrange(0,100) < rate for i in range(8) ] for j in range(8)] @@ -52,7 +71,7 @@ def draw_universe(trellis, universe): def extend_universe(universe): """Extend an 8x8 universe to 10x10 with first and last columns and rows as in an donut-shaped universe""" - ext_universe = [[False for x_ext in range(10)] for y_ext in range(10)] + ext_universe = _EXT_UNIVERSE.copy() # Copy universe in an extended donut-shaped universe for x_ext in range(10): @@ -77,15 +96,9 @@ def extend_universe(universe): def living_neighbour_count(xcoord, ycoord, ext_universe): """Count living cells around xcoord, ycoord""" - living_neighbours = [] - living_neighbours.append(ext_universe[xcoord][ycoord]) - living_neighbours.append(ext_universe[xcoord][ycoord+1]) - living_neighbours.append(ext_universe[xcoord][ycoord+2]) - living_neighbours.append(ext_universe[xcoord+1][ycoord]) - living_neighbours.append(ext_universe[xcoord+1][ycoord+2]) - living_neighbours.append(ext_universe[xcoord+2][ycoord]) - living_neighbours.append(ext_universe[xcoord+2][ycoord+1]) - living_neighbours.append(ext_universe[xcoord+2][ycoord+2]) + living_neighbours = ext_universe[xcoord][ycoord:ycoord+3] + living_neighbours += ext_universe[xcoord+1][ycoord:ycoord+3:2] + living_neighbours += ext_universe[xcoord+2][ycoord:ycoord+3] return living_neighbours.count(True)