Created
February 23, 2021 15:36
-
-
Save jepler/6cb7e23a1ea96521cd240bbb38315671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from adafruit_led_animation.animation.rainbowcomet import RainbowComet | |
from adafruit_led_animation.animation.comet import Comet | |
from adafruit_led_animation.sequence import AnimationSequence | |
from adafruit_led_animation.helper import PixelMap | |
from adafruit_led_animation.group import AnimationGroup | |
from adafruit_led_animation.color import colorwheel | |
from neopio import NeoPIO | |
import board | |
import random | |
import neopixel | |
import time | |
import gc | |
# Customize for your strands here | |
num_strands = 8 | |
strand_length = 30 | |
# Make the object to control the pixels | |
pixels = NeoPIO(board.GP0, board.GP1, board.GP2, num_strands*strand_length, num_strands=num_strands, auto_write=False, brightness=0.07) | |
# Make a virtual PixelMap so that each strip can be controlled independently | |
strips = [PixelMap(pixels, range(i*30, (i+1)*30), individual_pixels=True) for i in range(num_strands)] | |
class AnimationFactorySequence(AnimationSequence): | |
def __init__(self, factory, advance_interval=None, auto_clear=True, advance_on_cycle_complete=False, name=None): | |
self._factory = factory | |
super().__init__(factory(), advance_interval=advance_interval, auto_clear=auto_clear, advance_on_cycle_complete=advance_on_cycle_complete, name=name) | |
def _advance(self): | |
if self.auto_reset: | |
self.current_animation.reset() | |
if self.auto_clear: | |
self.current_animation.fill(self.clear_color) | |
self._members = [self._factory()] | |
self._members[0].add_cycle_complete_receiver(self._sequence_complete) | |
if self._color is not None: | |
self.current_animation.color = self._color | |
# This function makes a comet animation with slightly random settings | |
def make_animation(strip): | |
speed = random.uniform(.02, .05) | |
length = random.randrange(18, 22) | |
reverse = random.random() > .5 | |
if reverse: | |
strip = PixelMap(pixels, strip._ranges[::-1], individual_pixels=True) | |
offset = random.randint(0, 255) | |
step = random.uniform(-20,20) | |
result = RainbowComet(strip, speed=speed, tail_length=length, colorwheel_offset=offset, step=step) | |
return result | |
# Make an animation for each virtual strip | |
animations = [AnimationFactorySequence(lambda strip=strip: make_animation(strip), advance_on_cycle_complete=True) for strip in strips] | |
# Put the animations into a group so that we can animate them together | |
group = AnimationGroup(*animations, ) | |
group.animate() | |
# Show the animations forever | |
while True: | |
group.animate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment