Compare commits

...

3 Commits

Author SHA1 Message Date
fc9171da08 draw some more frames 2024-12-17 10:29:03 +01:00
Felix Pankratz
f1036a67f3 basic sine grid 2024-12-16 16:36:42 +01:00
Felix Pankratz
357beae051 initial commit 2024-12-16 16:08:38 +01:00
3 changed files with 76 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()

34
simulator/sine_grid.py Normal file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import math
from color import Color
from matrix import Matrix
import time
import random
class Cell:
def __init__(self) -> None:
self.state: float = random.uniform(0, 10)
self.increment: float = random.uniform(0.1, 0.5)
self.factor: float = random.uniform(0.9, 1.1)
def get_value(self) -> float:
return 1 + (math.sin(self.state) * self.factor)
def main():
m = Matrix()
cells = [Cell() for _ in range(2048)]
for i in range(255):
for index, cell in enumerate(cells):
cell.state += 0.2
m.drawPixel(index % 64, index // 64, Color(
round(cell.get_value()*255),
0,
0
))
m.show()
time.sleep(0.3)
if __name__ == '__main__':
main()