def sparks(c): pixel = random.randint(0, neopixel_len - 1) neopixel[pixel] = randRGB() neopixel.show() # Unset, so the pixel is blank in the next round neopixel[pixel] = 0 time.sleep(0.025)
def blue(c): if (time.monotonic() > c['timer']): c['timer'] = time.monotonic() + 0.75 pixel = random.randint(0, neopixel_len - 1) c['current'][pixel] = c['next'][pixel] c['next'][pixel] = nextBlue(c) for j in range(0, neopixel_len): c['current'][j] = fancy.mix(c['current'][j], c['next'][j], 1 / 25) neopixel[j] = c['current'][j].pack() neopixel.show()
def chase(color): scaled = fancy.CHSV(color.hue, color.saturation, color.value * scale()) for i in range(0, neopixel_len): neopixel[i] = color.pack() for j in range(0, FADE): v = scaled.value / (j + 1) c = fancy.CHSV(scaled.hue, scaled.saturation, v) neopixel[i - j] = c.pack() neopixel[i - FADE] = 0 neopixel.show()
def starburst(c): # 0.0-1.0, bigger numbers decay slower fade_rate = 0.96 ramp_rate = 0.80 # Total steps in the fade/ramp ramp_steps = 10 fade_steps = 90 side_delay = int(ramp_steps * 0.75) # Pick a ring pixel other than center pixel = None while (pixel == None or pixel % ring_len == 0): pixel = random.randint(0, neopixel_len - 1) pl = ring_move(pixel, -1) pr = ring_move(pixel, 1) pc = ring_center(pixel) # Pick a related set of colors, always full brightness color = fancy.CHSV(random.uniform(hue_min, hue_max), 1.0, 1.0) color_l = fancy.CHSV(color.hue - 0.08, 0.85, color.value) color_r = fancy.CHSV(color.hue + 0.08, color_l.saturation, color_l.value) color_c = fancy.CHSV(color.hue, color_l.saturation, color_l.value) for i in range(0, (ramp_steps + fade_steps)): # Allow mode switches if (mode_switch()): return # Primary pixel if (i <= (ramp_steps + 1)): v = decay(color.value, (ramp_steps - i), ramp_rate) f = fancy.CHSV(color.hue, color.saturation, v) neopixel[pixel] = f.pack() elif (i == ((ramp_steps + fade_steps) - 1)): neopixel[pixel] = 0 else: v = decay(color.value, i - ramp_steps, fade_rate) f = fancy.CHSV(color.hue, color.saturation, v) neopixel[pixel] = f.pack() # All pixels are primary if the button is pushed (and the mode is locked) if (touch.value and locked): c['bright'] = True set_all(neopixel[pixel]) elif (c['bright']): c['bright'] = False set_all(0) # Side pixels elif (i >= side_delay and i < (ramp_steps + side_delay)): v = decay(color.value * 0.25, ramp_steps + side_delay - i, ramp_rate * 0.975) cm = fancy.CHSV(color_l.hue, color_l.saturation, v) neopixel[pl] = cm.pack() cm.hue = color_r.hue neopixel[pr] = cm.pack() cm.hue = color_c.hue neopixel[pc] = cm.pack() elif (i < side_delay or i == ((ramp_steps + fade_steps) - 1)): neopixel[pl] = 0 neopixel[pr] = 0 neopixel[pc] = 0 else: v = decay(color.value * 0.25, i - side_delay, fade_rate * 0.975) cm = fancy.CHSV(color_l.hue, color_l.saturation, v) neopixel[pl] = cm.pack() cm.hue = color_r.hue neopixel[pr] = cm.pack() cm.hue = color_c.hue neopixel[pc] = cm.pack() # Push to hardware neopixel.show() time.sleep(random.uniform(0.01125, 0.0225)) time.sleep(random.uniform(0.5, 1.0))
def set_all(color): for j in range(0, neopixel_len): neopixel[j] = color neopixel.show()
# Side pixels if (i >= side_delay and i < side_index): s = ramp_steps + side_delay - i v = decay(color.value * side_value_scale, s, ramp_rate * side_ramp_scale) c_l = fancy.CHSV(color_l.hue, color_l.saturation, v) c_r = fancy.CHSV(color_r.hue, color_r.saturation, v) c_c = fancy.CHSV(color_c.hue, color_c.saturation, v) neopixel[ring_move(pixel, -1)] = c_l.pack() neopixel[ring_move(pixel, 1)] = c_r.pack() neopixel[ring_center(pixel)] = c_c.pack() elif (i < side_delay or i == last_step): neopixel[ring_move(pixel, -1)] = 0 neopixel[ring_move(pixel, 1)] = 0 neopixel[ring_center(pixel)] = 0 else: s = i - side_delay v = decay(color.value * side_value_scale, s, fade_rate * side_ramp_scale) c_l = fancy.CHSV(color_l.hue, color_l.saturation, v) c_r = fancy.CHSV(color_r.hue, color_r.saturation, v) c_c = fancy.CHSV(color_c.hue, color_c.saturation, v) neopixel[ring_move(pixel, -1)] = c_l.pack() neopixel[ring_move(pixel, 1)] = c_r.pack() neopixel[ring_center(pixel)] = c_c.pack() # Push to hardware neopixel.show() time.sleep(delay) time.sleep(1.5)