Implement Hackertours effect

This commit is contained in:
Stefan Bethke 2024-12-16 16:15:56 +01:00
commit 93b409736f
6 changed files with 60 additions and 12 deletions

View file

@ -120,6 +120,7 @@ class TwoColor(Steady):
def name(self):
return str(self)
class Caramelldansen(Steady):
"""
by Max & Lightmoll (https://lght.ml)
@ -233,9 +234,36 @@ class Chase(Steady):
return "chase"
class ChaseRandom(Animation):
class Hackertours(Steady):
"""
Base color yellow, with green wandering back and forth
"""
def __init__(self, color, base=(255,255,0), looptime=2.0):
super(Hackertours, self).__init__(color)
self.looptime = looptime
self.base = base
def update(self, index, count):
# angle is the position of the highlight on a circle, range [0, 1]
angle = (time() / self.looptime + (index + 0.0) / count) % 1.0
# map 0->1, 0.5->0, 1->1 to convert from circle to cylon
angle = abs(angle * 2 - 1)
l = 1 - min(abs(angle - 1 / count) * .9, 1.0 / count) * count
return (
int(self.r * l + self.base[0] * (1-l)),
int(self.g * l + self.base[1] * (1-l)),
int(self.b * l + self.base[2] * (1-l)))
def __str__(self):
return f"{type(self).__name__}({self.r}, {self.g}, {self.b}, {self.looptime:.2f})"
def name(self):
return "hackertours"
class ChaseRandom(Steady):
def __init__(self, color, looptime=1.0):
super(Chase, self).__init__(color)
super(ChaseRandom, self).__init__(color)
self.looptime = looptime
def update(self, index, count):