In [6]:
# not needed numpy practice
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from math import *
%matplotlib inline

In [19]:
ymax = 101
xmax = 2 * ymax
ar = np.zeros((ymax, xmax))
ar[0][ceil(xmax / 2)] = 1

In [20]:
for y in range(ymax - 1):
    for x in range(xmax - 2):
        if ar[y][x] == 1 and ar[y][x + 1] == 1 and ar[y][x + 2] == 1:
            ar[y + 1][x + 1] = 0
        elif ar[y][x] == 1 and ar[y][x + 1] == 1 and ar[y][x + 2] == 0:
            ar[y + 1][x + 1] = 0
        elif ar[y][x] == 1 and ar[y][x + 1] == 0 and ar[y][x + 2] == 1:
            ar[y + 1][x + 1] = 0
        elif ar[y][x] == 1 and ar[y][x + 1] == 0 and ar[y][x + 2] == 0:
            ar[y + 1][x + 1] = 1
        elif ar[y][x] == 0 and ar[y][x + 1] == 1 and ar[y][x + 2] == 1:
            ar[y + 1][x + 1] = 1
        elif ar[y][x] == 0 and ar[y][x + 1] == 1 and ar[y][x + 2] == 0:
            ar[y + 1][x + 1] = 1
        elif ar[y][x] == 0 and ar[y][x + 1] == 0 and ar[y][x + 2] == 1:
            ar[y + 1][x + 1] = 1
        elif ar[y][x] == 0 and ar[y][x + 1] == 0 and ar[y][x + 2] == 0:
            ar[y + 1][x + 1] = 0

In [22]:
fig, ax = plt.subplots()

ax.set_title('rule 30')

# Move left and bottom spines outward by 10 points
ax.spines['left'].set_position(('outward', 10))
ax.spines['bottom'].set_position(('outward', 10))
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Only show ticks on the left and bottom spines
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')

ax.imshow(ar, cmap=plt.cm.gray, interpolation='nearest')
plt.show()



In [ ]: