Skip to content

Commit

Permalink
fixes for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
thearn committed Feb 28, 2014
1 parent ea96f39 commit fd7ebc6
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def conway(state, k):
plt.figure()
img_plot = plt.imshow(A, interpolation="nearest", cmap = plt.cm.gray)
plt.show()
for i in xrange(1,5000):
while True:
A = conway(A, k)
img_plot.set_data(A)
plt.draw()
Expand Down
2 changes: 1 addition & 1 deletion lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from lib import fft_convolve2d
from .lib import fft_convolve2d
4 changes: 2 additions & 2 deletions lib/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ def fft_convolve2d(x,y):
fr2 = fft2(np.flipud(np.fliplr(y)))
m,n = fr.shape
cc = np.real(ifft2(fr*fr2))
cc = np.roll(cc, -m/2+1,axis=0)
cc = np.roll(cc, -n/2+1,axis=1)
cc = np.roll(cc, - int(m / 2) + 1, axis=0)
cc = np.roll(cc, - int(n / 2) + 1, axis=1)
return cc
2 changes: 1 addition & 1 deletion replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def replicator(state, k):
plt.figure()
img_plot = plt.imshow(A, interpolation="nearest", cmap = plt.cm.gray)
plt.show()
for i in xrange(1,5000):
while True
A = replicator(A, k)
img_plot.set_data(A)
plt.draw()
Expand Down
6 changes: 3 additions & 3 deletions seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def seed(state, k):
b = fft_convolve2d(state,k).round()
c = np.zeros(b.shape)
# checks the values, and sets alive vs. dead state
c[np.where(b==2)] = 1
c[np.where(b == 2)] = 1

# return new state
return c
Expand All @@ -32,8 +32,8 @@ def seed(state, k):
plt.figure()
img_plot = plt.imshow(A, interpolation="nearest", cmap = plt.cm.gray)
plt.show()
for i in xrange(1,5000):
while True:
A = seed(A, k)
img_plot.set_data(A)
plt.draw()
time.sleep(0.05)
time.sleep(0.02)
43 changes: 43 additions & 0 deletions two_by_two.py
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)

0 comments on commit fd7ebc6

Please sign in to comment.