diff --git a/simulator/color.py b/simulator/color.py new file mode 100644 index 0000000..5e6abcd --- /dev/null +++ b/simulator/color.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +class Color: + def __init__(self, r: int, g: int, b: int) -> None: + self.r = r + self.g = g + self.b = b + diff --git a/simulator/matrix.py b/simulator/matrix.py new file mode 100644 index 0000000..9f448cc --- /dev/null +++ b/simulator/matrix.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +from color import Color +import time + +WIDTH = 64 +HEIGHT = 32 +PIXEL = '\033[38;2;{};{};{}m██' + +class Matrix: + def __init__(self) -> None: + self.buffer = [ [Color(0, 0, 0) for _ in range(WIDTH)] for __ in range(HEIGHT) ] + def drawPixel(self, x: int, y: int, c: Color): + self.buffer[y][x] = c + def clear(self) -> None: + self.__init__() + def show(self) -> None: + # clear + print("\033[H\033[J", end="") + for line in self.buffer: + output = ''.join(PIXEL.format(px.r, px.g, px.b) for px in line) + print(output) + + +def main() -> None: + m = Matrix() + for i in range(32): + m.drawPixel(i, i, Color(255, 0, 4*i)) + for i in range(32): + m.drawPixel(32 + i, 31 - i, Color(255, 0, (4*i))) + m.show() + +if __name__ == '__main__': + main()