def _color_wheel_generator(self): period = int(self._period * MS_PER_SECOND) num_pixels = len(self.pixel_object) last_update = monotonic_ms() cycle_position = 0 last_pos = 0 while True: cycle_completed = False now = monotonic_ms() time_since_last_draw = now - last_update last_update = now pos = cycle_position = (cycle_position + time_since_last_draw) % period if pos < last_pos: cycle_completed = True last_pos = pos wheel_index = int((pos / period) * len(self.colors)) if self.colors: self._draw_precomputed(num_pixels, wheel_index) else: wheel_index = int((pos / period) * 256) self.pixel_object[:] = [ colorwheel((i + wheel_index) % 255) for i in range(num_pixels) ] self._wheel_index = wheel_index if cycle_completed: self.cycle_complete = True yield
def __init__( self, pixel_object, speed, size=2, spacing=3, reverse=False, name=None, step=8, ): self._num_colors = 256 // step self._colors = [colorwheel(n % 256) for n in range(0, 512, step)] self._color_idx = 0 super().__init__(pixel_object, speed, 0, size, spacing, reverse, name)
def generate_rainbow(self): """Generates the rainbow.""" self.colors = [] i = 0 while i < 256: self.colors.append(colorwheel(int(i))) i += self._step
def _set_color(self, color): self._comet_colors = [BLACK] for n in range(self._tail_length): invert = self._tail_length - n - 1 self._comet_colors.append( calculate_intensity( colorwheel( int((invert * self._colorwheel_step) + self._colorwheel_offset) % 256), n * self._color_step + 0.05, )) self._computed_color = color
AnimationGroup( sparkle2, rainbow_comet3, ), auto_clear=True, auto_reset=True, ) MODE = 0 LASTMODE = 1 # start up in sound reactive mode i = 0 # Main loop while True: i = (i + 0.5) % 256 # run from 0 to 255 TILT_COLOR = colorwheel(i) if MODE == 0: # If currently off... enable.value = True power_on(POWER_ON_DURATION) # Power up! MODE = LASTMODE elif MODE >= 1: # If not OFF MODE... mic.record(samples_bit, len(samples_bit)) samples = np.array(samples_bit[3:]) spectrum = extras.spectrogram(samples) spectrum = spectrum[:128] spectrum[0] = 0 spectrum[1] = 0 peak_idx = numerical.argmax(spectrum) peak_freq = peak_idx * 16000 / 256 # print((peak_idx, peak_freq, spectrum[peak_idx]))
def switch_colors(anim): anim.color = colorwheel(random.randint(0, 255))
# colors default to RAINBOW as defined in color.py custom_color_chase_rainbow = CustomColorChase(pixels, speed=0.1, size=2, spacing=3) custom_color_chase_rainbow_r = CustomColorChase(pixels, speed=0.1, size=3, spacing=3, reverse=True) # Example with same colors as RainbowChase steps = 30 # This was taken from rainbowchase.py rainbow_colors = [colorwheel(n % 256) for n in range(0, 512, steps)] # Now use rainbow_colors with CustomColorChase custom_color_chase_rainbowchase = CustomColorChase(pixels, speed=0.1, colors=rainbow_colors, size=2, spacing=3) custom_color_chase_bgp = CustomColorChase(pixels, speed=0.1, colors=[BLUE, GREEN, PINK], size=3, spacing=2) # Can use integer values for color, 0 is black custom_color_chase_br = CustomColorChase(pixels,
def _generate_droplet(self, x, length): color = colorwheel(random.randint(0, 255)) return [ [n, calculate_intensity(color, 1.0 - -((n + 1) / (length + 1)))] for n in range(-length, 0) ]
def draw(self): self.color = colorwheel(self._color_index) self._color_index = (self._color_index + 1) % 256 self.fill(self.color)
# Animation Setup rainbow = Rainbow(pixels, speed=speeds[current_speed], period=2, name="rainbow", step=3) sparkle = Sparkle(pixels, speed=speeds[current_speed], color=WHITE, name="sparkle") rainbowfade = RainbowFade(pixels, speed=speeds[current_speed], name="rainbowfade") solid = Solid(pixels, color=colorwheel(0), name="solid") # Animation Sequence Playlist -- rearrange to change the order of animations animations = AnimationSequence( rainbow, rainbowfade, solid, sparkle, auto_clear=True, auto_reset=True, ) solid.speed = 0.01 solid_color = 0
def draw(self): # draw the animation ''' fades the entire strip through the whole spectrum ''' self.color = colorwheel(self._color_index + 1) self._color_index = (self._color_index + 1) % 256 self.fill(self.color)
def random_animation_color(anims): if random_color_mode: anims.color = colorwheel(random.randint(0, 255))