from light_show.talent import register from light_show.color import HSV __all__ = ("HueChange", ) class HueChange: def __init__(self, period=50): self.period = period def __call__(self, tree): color = HSV(0.0, 1.0, 1.0) hueShift = 1.0 / self.period while True: tree.fill(color) color.hue += hueShift if color.hue > 1.0: color.hue -= 0.0 yield register(HueChange, period=50)
from light_show.talent import register from light_show.color import randomColor __all__ = ("Sprinkle", ) class Sprinkle: """Colors sprinkle down on all strings""" def __call__(self, tree): while True: tree.down() for string in tree: string["TOP"] = randomColor() yield register(Sprinkle)
from light_show.talent import register from light_show.color import randomColor __all__ = ("Spiral", ) class Spiral: """Lights spiral around""" def __init__(self, gap=5): self.gap = gap def __call__(self, tree): index = 0 while True: tree.down() tree[index]["TOP"] = randomColor() index += 1 if index >= len(tree): index = 0 yield register(Spiral, gap=5)
__all__ = ("Trails", ) class Trails: """Trails fall from the top""" def __init__(self, length=3): self.length = length def __call__(self, tree): numStrings = len(tree) length = tree.length trailEnd = 2 * self.length probThreshold = 1.0 / numStrings location = np.ones(numStrings, dtype=int) * length # Location of trail colors = [None] * numStrings # Color of trail while True: tree.down() location += 1 for ii, string in enumerate(tree): if location[ii] <= self.length: # Propagate a trail string["TOP"] = colors[ii] elif location[ii] > trailEnd and randFloat() < probThreshold: # Start a trail location[ii] = 0 colors[ii] = randomColor() yield register(Trails, length=3)
colors = [HSV(hh, 1.0, 1.0).toRgb() for hh in hue] red = np.array([cc.red for cc in colors]) green = np.array([cc.green for cc in colors]) blue = np.array([cc.blue for cc in colors]) stringEnd = length - self.length location = [ int((0.5 * np.cos(ii / numStrings * np.pi) + 0.5) * stringEnd) for ii in range(numStrings) ] tree.clear() while True: for ii, string in enumerate(tree): loc = location[ii] string[loc:loc + self.length] = (red, green, blue) if goingUp[ii] and loc == stringEnd: goingUp[ii] = False elif not goingUp[ii] and loc == 0: goingUp[ii] = True if goingUp[ii]: string.right() location[ii] += 1 else: string.left() location[ii] -= 1 yield register(BouncingRainbow, length=5)
satStep = 1.0 / self.fade color = randomColor() hue = color.hue tree.fill(color) while True: # Increase saturation of everything that's on deleteMe = [] for ss, ii in active: color = tree[ss][ii].toHsv() sat = color.sat + satStep if sat > 1.0: deleteMe.append((ss, ii)) else: tree[ss][ii] = HSV(hue, sat, 1.0) for key in deleteMe: active.remove(key) gc.collect() # Add a new one string = int(randFloat() * len(tree)) index = int(randFloat() * len(tree[string])) key = (string, index) if key in active: continue active.add(key) tree[string][index] = HSV(hue, 0.0, 1.0) yield register(Sparkle, fade=50) register(SingleSparkle, fade=50)
__all__ = ("RandomFill", ) class RandomFill: """Pixel by pixel, fill the tree with color""" def __call__(self, tree): num = sum(len(ss) for ss in tree) indices = np.zeros((num, 2), dtype=int) start = 0 for ii in range(len(tree)): length = len(tree[ii]) ss = slice(start, start + length) indices[ss, 0] = ii indices[ss, 1] = np.arange(length) start += length while True: tree.clear() order = sorted([(randFloat(), ii) for ii in range(num)]) for _, ii in order: ss, tt = indices[ii] tree[ss][tt] = randomColor() yield for _, ii in order: ss, tt = indices[ii] tree[ss][tt] = BLACK yield register(RandomFill)
for ii in range(1, ring + 1): tree.set(ring - ii, color) yield tree.set(ring - ii, BLACK) class RainbowRingBuild: """Rainbow rings fall down, building up from the bottom, then fall off""" def __call__(self, tree): while True: tree.fill(BLACK) for ring in range(tree.length): color = HSV(ring/tree.length, 1.0, 1.0).toRgb() for ii in range(tree.length - ring - 1): tree.set(tree.length - 1 - ii, color) yield tree.set(tree.length - 1 - ii, BLACK) tree.set(ring, color) yield for ring in range(tree.length): color = HSV(ring/tree.length, 1.0, 1.0).toRgb() for ii in range(1, ring + 1): tree.set(ring - ii, color) yield tree.set(ring - ii, BLACK) register(Ring) register(DoubleRing, num=7) register(SolidRingBuild) register(RainbowRingBuild)