bgneal@47: """Chapter 7, exercise 2 in Allen Downey's Think Complexity book. bgneal@47: bgneal@47: Start with an r-pentomino as an initial condition and confirm that the results bgneal@47: are consistent with the description above. You might have to adjust the size of bgneal@47: the grid and the boundary behavior. bgneal@47: bgneal@47: """ bgneal@47: import Life bgneal@47: bgneal@47: bgneal@47: class RPentomino(Life.Life): bgneal@47: bgneal@47: def __init__(self, n): bgneal@47: super(RPentomino, self).__init__(n, mode='constant', cval=0, random=False) bgneal@47: bgneal@47: i, j = n / 2, n / 2 bgneal@47: self.array[i, j] = 1 bgneal@47: self.array[i, j - 1] = 1 bgneal@47: self.array[i, j + 1] = 1 bgneal@47: self.array[i - 1, j] = 1 bgneal@47: self.array[i + 1, j - 1] = 1 bgneal@47: bgneal@47: if __name__ == '__main__': bgneal@47: life = RPentomino(150) bgneal@47: viewer = Life.LifeViewer(life, delay=1) bgneal@47: viewer.animate(steps=1200)