SIMPLE RULES – ANKS plots

plot_000_127plot_128_255

To generate the plots above, I used the following python script:

# Script to generate simple Cellular Automata
# from the book ANKS S Wolfram 2002 pg 55-56
# PL 13.VI.2015

import numpy as np
import matplotlib.pyplot as plt

# Aux Functions
########################################

def rule_creator_256(rule):

    a = map(int,bin(rule)[2:].zfill(8)) # rule creator

    return a


def CA(rule,cells3):

    a = (-cells3[0]+1) * 4 + (-cells3[1]+1) *2 + (-cells3[2]+1);
 
    return rule[a]   
    
# Main program
########################################

N=30 # Number of Cellular Automata Steps

# memory matrix init

dat=np.zeros([N,N*4+1],np.int)

dat[0,2*N]=1;

cells3=[0,0,0];

plt.figure(figsize=(20, 20))

# do the job 

for rule in range(256):

    print "Rule Number -->", rule

    plt.subplot(16,8,(rule)%128+1)

    res=rule_creator_256(rule)

    for stp in np.arange(1,N):
        for i in np.arange(1,4*N):

            cells3[0]  = dat[stp-1,i-1];
            cells3[1]  = dat[stp-1,i];
            cells3[2]  = dat[stp-1,i+1];

            dat[stp,i] = CA(res,cells3);                 # apply the Cellular Automata with rule --> res

#   completed one realization ...

    dat_to_plot=dat[:,N+1:3*N].copy()                    # plot only the central window

    plt.gca().xaxis.set_major_locator(plt.NullLocator()) # remove ticks and labels
    plt.gca().yaxis.set_major_locator(plt.NullLocator())

    plt.pcolor(dat_to_plot[::-1], cmap='Greys')

    rulenm='rule ' + str(rule); plt.xlabel(rulenm,fontsize='xx-small')

    if rule == 127: #plot first page
       plt.savefig('plot_000_127.png', format='png',dpi=900)
       plt.clf()
       plt.figure(figsize=(20, 20))

    if rule == 255: #plot second page
       plt.savefig('plot_128_255.png', format='png',dpi=900)
       plt.clf()

print 'EOB'
Annunci

One thought on “SIMPLE RULES – ANKS plots

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...