-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from lib import fft_convolve2d | ||
from .lib import fft_convolve2d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import numpy as np | ||
import time | ||
from lib import fft_convolve2d | ||
import matplotlib.pyplot as plt | ||
plt.ion() | ||
|
||
def two_by_two(state, k): | ||
""" | ||
'2x2' automata state transition | ||
""" | ||
# computes sums around each pixel | ||
b = fft_convolve2d(state,k).round() | ||
c = np.zeros(b.shape) | ||
# checks the values, and sets alive vs. dead state | ||
|
||
c[np.where((b == 1) & (state == 1))] = 1 | ||
c[np.where((b == 2) & (state == 1))] = 1 | ||
c[np.where((b == 5) & (state == 1))] = 1 | ||
c[np.where((b == 3) & (state == 0))] = 1 | ||
c[np.where((b == 6) & (state == 0))] = 1 | ||
|
||
# return new state | ||
return c | ||
|
||
if __name__ == "__main__": | ||
# set up board | ||
m,n = 100,100 | ||
A = np.zeros((m,n)) | ||
A = np.random.random(m*n).reshape((m, n)).round() | ||
|
||
# construct convolution kernel | ||
k = np.zeros((m, n)) | ||
k[m/2-1 : m/2+2, n/2-1 : n/2+2] = np.array([[1,1,1],[1,0,1],[1,1,1]]) | ||
|
||
# plot each frame | ||
plt.figure() | ||
img_plot = plt.imshow(A, interpolation="nearest", cmap = plt.cm.gray) | ||
plt.show() | ||
while True: | ||
A = two_by_two(A, k) | ||
img_plot.set_data(A) | ||
plt.draw() | ||
time.sleep(0.1) |