tree = [
[255, 255, 255, 255, 0, 255, 255, 255, 255],
[255, 255, 255, 0, 0, 0, 255, 255, 255],
[255, 255, 0, 0, 0, 0, 0, 255, 255],
[255, 255, 255, 0, 0, 0, 255, 255, 255],
[255, 0, 0, 0, 0, 0, 0, 0, 255],
[255, 255, 255, 255, 120, 255, 255, 255, 255],
]
SHADES = "@%#*+=-:. " # darkest (0) ... lightest (255)
def show(img):
for row in img:
line = ""
for v in row:
line += SHADES[v * (len(SHADES) - 1) // 255]
print(line)
def inverted(img):
return [[255 - v for v in row] for row in img]
def brightened(img, amount):
return [[min(255, v + amount) for v in row] for row in img]
show(tree)
print("---------")
show(inverted(tree))
print("---------")
show(brightened(tree, 100))
Its checked output is shown in the next box. The show function prints a character for each pixel, from @ (darkest) to a space (lightest), so you can "see" an image without any graphics library. brightened clamps with min(255, ...): without it, white pixels would become 355, which is not a valid brightness.