<s> import numpy as np <EOL> import time <EOL> from lib import fft_convolve2d <EOL> import matplotlib . pyplot as plt <EOL> plt . ion ( ) <EOL> def two_by_two ( state , k = None ) : <EOL> """<STR_LIT>""" <EOL> if k == None : <EOL> m , n = state . shape <EOL> k = np . zeros ( ( m , n ) ) <EOL> k [ m / <NUM_LIT:2> - <NUM_LIT:1> : m / <NUM_LIT:2> + <NUM_LIT:2> , n / <NUM_LIT:2> - <NUM_LIT:1> : n / <NUM_LIT:2> + <NUM_LIT:2> ] = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ] ) <EOL> b = fft_convolve2d ( state , k ) . round ( ) <EOL> c = np . zeros ( b . shape ) <EOL> c [ np . where ( ( b == <NUM_LIT:1> ) & ( state == <NUM_LIT:1> ) ) ] = <NUM_LIT:1> <EOL> c [ np . where ( ( b == <NUM_LIT:2> ) & ( state == <NUM_LIT:1> ) ) ] = <NUM_LIT:1> <EOL> c [ np . where ( ( b == <NUM_LIT:5> ) & ( state == <NUM_LIT:1> ) ) ] = <NUM_LIT:1> <EOL> c [ np . where ( ( b == <NUM_LIT:3> ) & ( state == <NUM_LIT:0> ) ) ] = <NUM_LIT:1> <EOL> c [ np . where ( ( b == <NUM_LIT:6> ) & ( state == <NUM_LIT:0> ) ) ] = <NUM_LIT:1> <EOL> return c <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> m , n = <NUM_LIT:100> , <NUM_LIT:100> <EOL> A = np . zeros ( ( m , n ) ) <EOL> A = <NUM_LIT> * np . random . random ( m * n ) . reshape ( ( m , n ) ) <EOL> A = A . round ( ) <EOL> plt . figure ( ) <EOL> img_plot = plt . imshow ( A , interpolation = "<STR_LIT>" , cmap = plt . cm . gray ) <EOL> plt . show ( block = False ) <EOL> while True : <EOL> A = two_by_two ( A ) <EOL> img_plot . set_data ( A ) <EOL> plt . draw ( ) <EOL> time . sleep ( <NUM_LIT> ) </s>
