Adafruit_CircuitPython_Bitm.../test/displayio.py
2020-03-15 16:17:54 -04:00

20 lines
654 B
Python

class Bitmap:
def __init__(self, width, height, color_count):
self.width = width
self.height = height
if color_count > 255:
raise ValueError("Cannot support that many colors")
self.values = bytearray(width * height)
def __setitem__(self, index, value):
if isinstance(index, tuple):
index = index[0] + index[1] * self.width
self.values[index] = value
def __getitem__(self, index):
if isinstance(index, tuple):
index = index[0] + index[1] * self.width
return self.values[index]
def __len__(self):
return self.width * self.height