import Image
import ImageDraw

generations_count = 20
cell_size = 10

grid = # ...
height = len(grid)
width = len(grid[0])

# Definition of functions (get_next_state, ...)

for i in range(generations_count):
    # Create a new image
    img = Image.new(
        'RGBA',
        (cell_size * width, cell_size * height),
        '#000000'
    )
    draw = ImageDraw.Draw(img)

    # ... For each cell in (x, y),
    # draw it on the image
    if grid[y][x]:
        color = '#ffffff'
    else:
        color = '#000000'
    draw.rectangle((
        x * cell_size, y * cell_size,
        (x + 1) * cell_size, (y + 1) * cell_size
    ))

    # ... then save the image and go to the next step
    img.save('grid-%d.png' % i)
    grid = get_next_grid(grid)