MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / generate_image

Function generate_image

cellular_automata/one_dimensional.py:44–63  ·  view source on GitHub ↗

Convert the cells into a greyscale PIL.Image.Image and return it to the caller. >>> from random import random >>> cells = [[random() for w in range(31)] for h in range(16)] >>> img = generate_image(cells) >>> isinstance(img, Image.Image) True >>> img.width, img.height

(cells: list[list[int]])

Source from the content-addressed store, hash-verified

42
43
44def generate_image(cells: list[list[int]]) -> Image.Image:
45 """
46 Convert the cells into a greyscale PIL.Image.Image and return it to the caller.
47 >>> from random import random
48 >>> cells = [[random() for w in range(31)] for h in range(16)]
49 >>> img = generate_image(cells)
50 >>> isinstance(img, Image.Image)
51 True
52 >>> img.width, img.height
53 (31, 16)
54 """
55 # Create the output image
56 img = Image.new("RGB", (len(cells[0]), len(cells)))
57 pixels = img.load()
58 # Generates image
59 for w in range(img.width):
60 for h in range(img.height):
61 color = 255 - int(255 * cells[h][w])
62 pixels[w, h] = (color, color, color)
63 return img
64
65
66if __name__ == "__main__":

Callers 1

one_dimensional.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected