Time for Action – simulating life

The following code is an implementation of the Game of Life, with some modifications:

  • Clicking once with the mouse draws a cross until we click again
  • The r key resets the grid to a random state
  • Pressing b creates blocks based on the mouse position
  • g creates gliders

The most important data structure in the code is a two-dimensional array, holding the color values of the pixels on the game screen. This array is initialized with random values and then recalculated for each iteration of the game loop. Find more information about the involved functions in the next section.

  1. To evaluate the rules, use the convolution as follows:
    def get_pixar(arr, weights): states = ndimage.convolve(arr, weights, mode='wrap') bools = (states ...

Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.