lumagrid/simulator/sine_grid.py

35 lines
816 B
Python
Raw Normal View History

2024-12-16 16:36:42 +01:00
#!/usr/bin/env python3
import math
from color import Color
from matrix import Matrix
2024-12-17 10:29:03 +01:00
import time
2024-12-16 16:36:42 +01:00
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)]
2024-12-17 10:29:03 +01:00
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)
2024-12-16 16:36:42 +01:00
if __name__ == '__main__':
main()