initial commit

This commit is contained in:
Felix Pankratz 2024-12-16 16:08:38 +01:00
parent b87cedf88a
commit 357beae051
2 changed files with 42 additions and 0 deletions

8
simulator/color.py Normal file
View File

@ -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

34
simulator/matrix.py Normal file
View File

@ -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()