2025-12-05 01:20:02 +01:00
|
|
|
#! /bin/python3
|
|
|
|
|
|
|
|
|
|
import math
|
|
|
|
|
import random
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
from Library.tree import RGBXmasTree
|
|
|
|
|
|
2025-12-30 16:52:24 +01:00
|
|
|
COLOURS = [
|
|
|
|
|
(0.800, 0.000, 0.000),
|
|
|
|
|
(0.000, 0.627, 0.000),
|
|
|
|
|
(0.800, 0.667, 0.000),
|
|
|
|
|
(0.000, 0.600, 0.800),
|
|
|
|
|
(0.800, 0.800, 0.800),
|
|
|
|
|
(0.600, 0.000, 0.800),
|
|
|
|
|
(0.800, 0.400, 0.000),
|
|
|
|
|
(0.600, 0.702, 0.733),
|
|
|
|
|
(0.800, 0.000, 0.267),
|
|
|
|
|
(0.000, 0.533, 0.267),
|
|
|
|
|
]
|
2025-12-05 01:20:02 +01:00
|
|
|
|
|
|
|
|
class Animation:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.animation_steps = 50
|
|
|
|
|
self.progress = [random.randint(0, self.animation_steps) for i in range(25)]
|
2025-12-30 16:52:24 +01:00
|
|
|
#self.colours = [(random.random(), random.random(), random.random()) for i in range(25)]
|
|
|
|
|
self.colours = [random.choice(COLOURS) for i in range(25)]
|
2025-12-05 01:20:02 +01:00
|
|
|
self.pixels = [(0, 0, 0) for i in range(25)]
|
|
|
|
|
|
|
|
|
|
def next(self):
|
|
|
|
|
for i in range(len(self.progress)):
|
|
|
|
|
self.progress[i] = (self.progress[i] + 1) % self.animation_steps
|
|
|
|
|
if self.progress[i] == 0:
|
2025-12-30 16:52:24 +01:00
|
|
|
#self.colours[i] = (random.random(), random.random(), random.random())
|
|
|
|
|
self.colours[i] = random.choice(COLOURS)
|
2025-12-05 01:20:02 +01:00
|
|
|
|
|
|
|
|
magnitude = math.sin(math.pi * (self.progress[i] / self.animation_steps))
|
|
|
|
|
colour = self.colours[i]
|
|
|
|
|
self.pixels[i] = (colour[0] * magnitude, colour[1] * magnitude, colour[2] * magnitude)
|
|
|
|
|
|
|
|
|
|
def set_colours(self, tree: RGBXmasTree):
|
|
|
|
|
for i in range(25):
|
|
|
|
|
tree[i].color = self.pixels[i]
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
tree = RGBXmasTree()
|
|
|
|
|
animation = Animation()
|
|
|
|
|
|
2025-12-30 16:52:24 +01:00
|
|
|
tree.brightness = 0.05
|
|
|
|
|
|
2025-12-05 01:20:02 +01:00
|
|
|
try:
|
|
|
|
|
while True:
|
|
|
|
|
animation.next()
|
|
|
|
|
animation.set_colours(tree)
|
2025-12-30 16:52:24 +01:00
|
|
|
#time.sleep(0.25)
|
2025-12-05 01:20:02 +01:00
|
|
|
finally:
|
|
|
|
|
tree.off()
|