0

Excuse me for being a green one in using mathplotlib but I got a problem with implementing it in my Game of Life code. I think, that the thing is in printing the array. However I do not know how to solve it.

`


import numpy as np
import matplotlib.pyplot as plt 
import matplotlib.animation as animation
frule = [0,1,1,0,1,1,1,0]


def rules(a,b,c):
    if (a==0 and b==0 and c==0):
        return frule[0]
    if (a==0 and b==0 and c==1):
        return frule[1]
    if (a==0 and b==1 and c==0):
        return frule[2]
    if (a==0 and b==1 and c==1):
        return frule[3]
    if (a==1 and b==0 and c==0):
        return frule[4]
    if (a==1 and b==0 and c==1):
        return frule[5]
    if (a==1 and b==1 and c==0):
        return frule[6]
    if (a==1 and b==1 and c==1):
        return frule[7]

initial = np.random.randint(0,2,300)

gen = 0
for j in range(0,150):
    nextgen = []
    initial =  np.append(initial,[0])
    initial =  np.insert(initial,0,[0])

    for i in range(1,len(initial)-1):
            first = initial[i-1]
            mid = initial[i]
            last = initial[i+1]
            nextgen.append(rules(first, mid, last))
    initial = nextgen
   
    gen = gen+1

plt.rcParams['image.cmap'] = 'binary'

fig, ax = plt.subplots(figsize=(16, 9))
ax.matshow(nextgen) #i am trying to print out nextgen, however I haven't still made a function for this
ax.axis(False)



` So basically how to make it work (how to make a visual model) I think the problem is in outputting the result, but idk, I tried different ways and it still didn't work

  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 26 '22 at 21:13

0 Answers0