MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / generate_images

Function generate_images

cellular_automata/conways_game_of_life.py:72–91  ·  view source on GitHub ↗

Generates a list of images of subsequent Game of Life states.

(cells: list[list[int]], frames: int)

Source from the content-addressed store, hash-verified

70
71
72def generate_images(cells: list[list[int]], frames: int) -> list[Image.Image]:
73 """
74 Generates a list of images of subsequent Game of Life states.
75 """
76 images = []
77 for _ in range(frames):
78 # Create output image
79 img = Image.new("RGB", (len(cells[0]), len(cells)))
80 pixels = img.load()
81
82 # Save cells to image
83 for x in range(len(cells)):
84 for y in range(len(cells[0])):
85 colour = 255 - cells[y][x] * 255
86 pixels[x, y] = (colour, colour, colour)
87
88 # Save image
89 images.append(img)
90 cells = new_generation(cells)
91 return images
92
93
94if __name__ == "__main__":

Callers 1

Calls 2

new_generationFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected