comparison ch7ex2.py @ 47:2b0e229e163c

Chapter 7, exercise 2. R-Pentomino game of life.
author Brian Neal <bgneal@gmail.com>
date Thu, 25 Jul 2013 21:53:44 -0500
parents
children 98eb01502cf5
comparison
equal deleted inserted replaced
46:d83a72eec954 47:2b0e229e163c
1 """Chapter 7, exercise 2 in Allen Downey's Think Complexity book.
2
3 Start with an r-pentomino as an initial condition and confirm that the results
4 are consistent with the description above. You might have to adjust the size of
5 the grid and the boundary behavior.
6
7 """
8 import Life
9
10
11 class RPentomino(Life.Life):
12
13 def __init__(self, n):
14 super(RPentomino, self).__init__(n, mode='constant', cval=0, random=False)
15
16 i, j = n / 2, n / 2
17 self.array[i, j] = 1
18 self.array[i, j - 1] = 1
19 self.array[i, j + 1] = 1
20 self.array[i - 1, j] = 1
21 self.array[i + 1, j - 1] = 1
22
23 if __name__ == '__main__':
24 life = RPentomino(150)
25 viewer = Life.LifeViewer(life, delay=1)
26 viewer.animate(steps=1200)