Loading poolpay/display/get_test_picture.py +18 −1 Original line number Diff line number Diff line Loading @@ -18,17 +18,34 @@ def _append_pixel(red: int, green: int, blue: int, pixels: list[int]) -> None: pixels.append(low_byte) pixels.append(high_byte) # Alternative implementation I: # # color = red << 11 | green << 5 | blue # return struct.pack("<H", color) # # instead of appending to a list of pixels. # Alternative implementation II: # # return bytes([low_bytes, high_byte]) # # instead of appending to a list of pixels. def get_test_picture(width: int, height: int) -> bytes: """ Generate a test picture with a color gradient and return it. """ picture = [] picture: list[int] = [] for y in range(height): for x in range(width): b = 10 g = int(x * 31.0 / 480.0) r = int(x * 31.0 / 480) _append_pixel(red=r, green=g, blue=b, pixels=picture) # Alternative implementation: # # Have _append_pixel return a bytes object, store it in a list[bytes], # and then return b"".join(picture) return bytes(picture) Loading
poolpay/display/get_test_picture.py +18 −1 Original line number Diff line number Diff line Loading @@ -18,17 +18,34 @@ def _append_pixel(red: int, green: int, blue: int, pixels: list[int]) -> None: pixels.append(low_byte) pixels.append(high_byte) # Alternative implementation I: # # color = red << 11 | green << 5 | blue # return struct.pack("<H", color) # # instead of appending to a list of pixels. # Alternative implementation II: # # return bytes([low_bytes, high_byte]) # # instead of appending to a list of pixels. def get_test_picture(width: int, height: int) -> bytes: """ Generate a test picture with a color gradient and return it. """ picture = [] picture: list[int] = [] for y in range(height): for x in range(width): b = 10 g = int(x * 31.0 / 480.0) r = int(x * 31.0 / 480) _append_pixel(red=r, green=g, blue=b, pixels=picture) # Alternative implementation: # # Have _append_pixel return a bytes object, store it in a list[bytes], # and then return b"".join(picture) return bytes(picture)