Limit selection to fitting colours, use builtin brightness
This commit is contained in:
parent
9c9bb872ab
commit
4882855173
1 changed files with 19 additions and 5 deletions
24
dynamic.py
24
dynamic.py
|
|
@ -6,23 +6,35 @@ import time
|
||||||
|
|
||||||
from Library.tree import RGBXmasTree
|
from Library.tree import RGBXmasTree
|
||||||
|
|
||||||
BRIGHTNESS_MULTIPLIER = 0.15
|
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),
|
||||||
|
]
|
||||||
|
|
||||||
class Animation:
|
class Animation:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.animation_steps = 50
|
self.animation_steps = 50
|
||||||
self.progress = [random.randint(0, self.animation_steps) for i in range(25)]
|
self.progress = [random.randint(0, self.animation_steps) for i in range(25)]
|
||||||
self.colours = [(random.random(), random.random(), random.random()) for i in range(25)]
|
#self.colours = [(random.random(), random.random(), random.random()) for i in range(25)]
|
||||||
|
self.colours = [random.choice(COLOURS) for i in range(25)]
|
||||||
self.pixels = [(0, 0, 0) for i in range(25)]
|
self.pixels = [(0, 0, 0) for i in range(25)]
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
for i in range(len(self.progress)):
|
for i in range(len(self.progress)):
|
||||||
self.progress[i] = (self.progress[i] + 1) % self.animation_steps
|
self.progress[i] = (self.progress[i] + 1) % self.animation_steps
|
||||||
if self.progress[i] == 0:
|
if self.progress[i] == 0:
|
||||||
self.colours[i] = (random.random(), random.random(), random.random())
|
#self.colours[i] = (random.random(), random.random(), random.random())
|
||||||
|
self.colours[i] = random.choice(COLOURS)
|
||||||
|
|
||||||
magnitude = math.sin(math.pi * (self.progress[i] / self.animation_steps))
|
magnitude = math.sin(math.pi * (self.progress[i] / self.animation_steps))
|
||||||
magnitude *= BRIGHTNESS_MULTIPLIER
|
|
||||||
colour = self.colours[i]
|
colour = self.colours[i]
|
||||||
self.pixels[i] = (colour[0] * magnitude, colour[1] * magnitude, colour[2] * magnitude)
|
self.pixels[i] = (colour[0] * magnitude, colour[1] * magnitude, colour[2] * magnitude)
|
||||||
|
|
||||||
|
|
@ -34,10 +46,12 @@ if __name__ == "__main__":
|
||||||
tree = RGBXmasTree()
|
tree = RGBXmasTree()
|
||||||
animation = Animation()
|
animation = Animation()
|
||||||
|
|
||||||
|
tree.brightness = 0.05
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
animation.next()
|
animation.next()
|
||||||
animation.set_colours(tree)
|
animation.set_colours(tree)
|
||||||
time.sleep(0.5)
|
#time.sleep(0.25)
|
||||||
finally:
|
finally:
|
||||||
tree.off()
|
tree.off()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue