Пример #1
0
def hsv_rainbow(strip: BaseStrip, delay: int):
    for i in range(1, 360):
        r, g, b = hsv2rgb(i / 360, 1, 1)
        strip.fill((r, g, b))
        strip.show()

        time.sleep(delay / 1000)
Пример #2
0
def strobe(strip: BaseStrip, color: ColorTuple, count: int, delay: int = 100):
    for i in range(count):
        strip.fill(color)
        strip.show()
        time.sleep(delay / 1000)
        strip.fill((0, 0, 0))
        strip.show()
        time.sleep(delay / 1000)
Пример #3
0
def scanner(strip: BaseStrip,
            color: ColorTuple,
            size: int,
            speed_delay: int = 10,
            return_delay: int = 50):
    for i in itertools.chain(range(strip.led_count - size - 2),
                             reversed(range(strip.led_count - size - 2))):
        strip.fill((0, 0, 0))
        strip[i] = int(color[0] / 10), int(color[1] / 10), int(color[2] / 10)

        for j in range(1, size + 1):
            strip[i + j] = color

        strip[i + size + 1] = int(color[0] / 10), int(color[1] / 10), int(
            color[2] / 10)
        strip.show()
        time.sleep(speed_delay / 1000)
Пример #4
0
def snake(strip: BaseStrip, snake_color: ColorTuple, food_color: ColorTuple,
          snake_speed: int):
    def generate_food():
        index = random.randint(0, strip.led_count - 1)

        while index in range(snake_head - snake_length, snake_head):
            index = random.randint(0, strip.led_count - 1)

        return index

    def draw_snake():
        for i in range(snake_head - snake_length, snake_head):
            if i in range(0, strip.led_count):
                strip[i] = snake_color

        strip.show()

    strip.fill((0, 0, 0))
    snake_length = 3
    snake_head = 0
    food_index = generate_food()

    strip[food_index] = food_color

    while True:
        if snake_head - snake_length - 1 in range(0, strip.led_count):
            strip[snake_head - snake_length - 1] = (0, 0, 0)

        draw_snake()

        if snake_head == food_index:
            food_index = generate_food()
            strip[food_index] = food_color
            snake_length += 1

        snake_head += 1

        if snake_head - snake_length - 1 > strip.led_count:
            snake_head = 0

        if snake_length >= strip.led_count - 2:
            snake_length = 3
            snake_head = 0
            strobe(strip, snake_color, 4, delay=400)
Пример #5
0
def meteor_rain(strip: BaseStrip,
                color: ColorTuple,
                size: int,
                decay: int,
                random_decay: bool = True,
                delay: int = 30):
    strip.fill((0, 0, 0))

    for i in range(strip.led_count * 2):
        for j in range(strip.led_count):
            if not random_decay or random.random() > 0.5:
                fade_to_black(strip, j, decay)

        for j in range(size):
            if strip.led_count > i - j >= 0:
                strip[i - j] = color

        strip.show()
        time.sleep(delay / 1000)
Пример #6
0
def fade_in_n_out(strip: BaseStrip, color: ColorTuple, delay: int):
    for i in itertools.chain(range(256), reversed(range(256))):
        c = calculate_color_percent(color, i / 256)
        strip.fill(c)
        strip.show()
        time.sleep(delay / 1000)