TI/Skrypty z zajęć/6a

Z Brain-wiki
# -*- coding: utf-8 -*-
"""
Created on Wed Apr  1 12:13:20 2020

@author: Tomek
"""

#
import numpy as np
import pylab as py
N=50

def wolfram(r):
    rule = [int(char) for char in format(r, 'b').zfill(8)]
    p = np.zeros((N,N))
    p[0,N//2] = 1
    for t in range(1,N):
        for x in range(N):
            #sasiedztwo komórki x w chwili t-1
            nei = [p[t-1,N-1] if x==0 else p[t-1,x-1], p[t-1,x],p[t-1,0] if x==N-1 else p[t-1,x+1]]
            
            #przypisanie nowego stanu komórki x w chwili t na podstawie nei
            #przykład nei=[1,1,0] -> odpowiada temu liczba 6 -> rule[7-6]
            p[t,x]= rule[7-int(4*nei[0]+2*nei[1]+nei[2])]
            
    return p

#pusty obrazek
image=np.zeros((16*N,16*N))

#wypelnianie obrazka
for x in range(16):
    for y in range(16):
        image[N*x:N*x+N,N*y:N*y+N] = wolfram(y*16+x)
        
py.imshow(image, interpolation='nearest',cmap='Greys')