Пример #1
0
    def comet(self, style):
        print('COMET')
        cycle_counter = 0
        colors = GRB_Parser().convert(style['comet_head'])
        speed = style['speed'] or random()
        offset = style['offset'] or 1
        iterations = style['iterations'] or 1
        direction = style['direction'] or 1
        trail_colors = GRB_Parser().convert(style['comet_tail'] *
                                            (self.LED_COUNT - len(colors)))

        comet = colors + trail_colors

        while iterations > 0:
            for i in range(self.LED_COUNT):
                color = comet[(i + offset) % len(comet)]
                # Set the LED color buffer value.
                ws.ws2811_led_set(self.channel, i, color)
            # Send the LED color data to the hardware.
            resp = ws.ws2811_render(self.leds)
            # shift things
            comet = deque(comet)
            comet.rotate(direction)
            if resp != 0:
                raise RuntimeError(
                    'ws2811_render failed with code {0}'.format(resp))
            # Delay for a small period of time.
            time.sleep(speed)
            cycle_counter += 1
            if cycle_counter % self.LED_COUNT == 0:
                iterations -= 1
Пример #2
0
    def fuse(self, style):
        """
        Perform a fuse burn, then explode!
        """
        explode = False
        cycle_counter = 1
        colors = GRB_Parser().convert(style['fuse_fire'])
        explode_colors = style['explosion'] or ['red', 'orange']
        speed = style['speed']
        offset = style['offset']
        iterations = style['iterations']
        direction = style['direction']
        trail_colors = GRB_Parser().convert(style['fuse_unlit'] *
                                            (self.LED_COUNT - len(colors)))

        afuse = colors + trail_colors

        while iterations > 0:
            if cycle_counter % self.LED_COUNT != 0:
                cycle_counter += 1
                # Set the LED color buffer value.
                for i in range(self.LED_COUNT):
                    color = afuse[(i + offset) % len(afuse)]
                    ws.ws2811_led_set(self.channel, i, color)

                # Send the LED color data to the hardware.
                resp = ws.ws2811_render(self.leds)
                time.sleep(speed)

                afuse = deque(afuse)
                afuse.rotate(direction)
                if resp != 0:
                    raise RuntimeError(
                        'ws2811_render failed with code {0}'.format(resp))
            else:
                explode = True
                cycle_counter += 1

            if explode:
                print('Exploding!')
                explode = False
                self.LED_BRIGHTNESS = style['explosion_brightness'],
                explosion = {
                    'style_name': style['style_name'],
                    'method_name': style['method_name'],
                    'css3_colors': explode_colors,
                    'speed': style['explosion_speed'],
                    'offset': 1,
                    'reverse_after': 500,
                    'iterations': 1,
                    'direction': 1,
                    'cleanup': 1,
                }
                self.LED_BRIGHTNESS = style['explosion_brightness']

                self.party(explosion, True)
                cycle_counter += 1
                iterations -= 1
Пример #3
0
    def fade(self, style):
        length = style['led_count']
        speed = style['speed']
        iterations = style['iterations'] or 1
        fade_out_brightness, fade_in_brightness = style['fade_dim'], style[
            'fade_bright']
        in_color, out_color = GRB_Parser().convert(
            style['fade_in']), GRB_Parser().convert(style['fade_out'])

        chain = []
        div = int((out_color[0] - in_color[0]) / length)

        if div < 0:
            div *= -1

        cnt = 0
        for n in range(length):
            cnt += 1
            chain.append(div * cnt)
            if n % length == 0:
                if n < 0:
                    n = n * -1

        brightness_direction = 1
        brightness = 0
        returns = 0

        while iterations > 0:
            brightness += brightness_direction
            if (brightness >= fade_in_brightness - 1 and brightness_direction
                    == 1) or (brightness <= fade_out_brightness + 1
                              and brightness_direction == -1):
                brightness_direction *= -1
                returns += 1

            for i in range(self.LED_COUNT):
                ws.ws2811_led_set(self.channel, i, chain[i])
            ws.ws2811_channel_t_brightness_set(self.channel, brightness)
            # print(brightness)
            resp = ws.ws2811_render(self.leds)
            if resp != 0:
                raise RuntimeError(
                    'ws2811_render failed with code {0}'.format(resp))

            time.sleep(speed)

            if returns == 1:
                iterations -= 1
                returns = 0
Пример #4
0
    def typewriter(self, style):
        head = GRB_Parser().convert(style['head'] or ['red'])
        empty = GRB_Parser().convert(style['empty'] or ['black'])
        base = GRB_Parser().convert(style['base'] or ['blue'])
        length = style['led_count'] or 630
        speed = style['speed'] or 0.05
        iterations = style['iterations'] or 1
        chain = head + (empty * (length - len(head)))
        head_pos = len(head)
        base_color = 0
        direction = style['direction'] or 1
        offset = style['offset'] or 1
        cycle_counter = 1

        while iterations > 0:
            for i in range(self.LED_COUNT):
                color = chain[(i + offset) % len(list(chain))]
                ws.ws2811_led_set(self.channel, i, color)
            base_trail = [base[base_color]] * \
                (length - len(list(chain)[0:head_pos]))
            chain = empty * \
                (length - (len(head) + len(base_trail) - 2)) + \
                head + base_trail
            time.sleep(speed)
            # print(list(chain))
            resp = ws.ws2811_render(self.leds)
            if resp != 0:
                raise RuntimeError(
                    'ws2811_render failed with code {0}'.format(resp))
            # print('  Head: ', head_pos, '  ', chain, end="\r", flush=True)
            chain = deque(chain)
            chain.rotate(direction)
            if head_pos == length - 1:
                head_pos = 0
                head.reverse()
                direction *= -1
                if base_color == len(base) - 1:
                    base_color = 0
                else:
                    base_color += 1
            else:
                head_pos += 1
            if cycle_counter % length == 0:
                iterations -= 1
Пример #5
0
def simulate_3(style):
    length = style['led_count']
    speed = style['speed']
    iterations = style['iterations'] or 1

    fade_out_brightness, fade_in_brightness = 0, 255
    in_color, out_color = GRB_Parser().convert(
        ['red']), GRB_Parser().convert(['blue'])

    chain = []
    div = (out_color[0] - in_color[0]) / length

    if div < 0:
        div *= -1

    cnt = 0
    for n in range(length):
        cnt += 1
        chain.append(div * cnt)
        if n % length == 0:
            if n < 0:
                n = n * -1

    brightness_direction = 1
    brightness = 0
    returns = 0

    while iterations > 0:
        brightness += brightness_direction * 10
        if (brightness >= fade_in_brightness - 1 and brightness_direction == 1) or (brightness <= fade_out_brightness + 1 and brightness_direction == -1):
            brightness_direction *= -1
            returns += 1
            print(returns, iterations)

        print("Brightness: {0}".format(brightness),
              list(chain), end="\r", flush=True)
        time.sleep(speed)

        if returns == 1:
            iterations -= 1
            returns = 0
Пример #6
0
 def room_lighting_on(self, style):
     colors = GRB_Parser().convert(style['color'])
     # self.LED_BRIGHTNESS = style['brightness']
     print('brightness: ', self.LED_BRIGHTNESS)
     print('senselight: ', style['senselight'])
     print('color: ', style['color'])
     for i in range(self.LED_COUNT):
         ws.ws2811_led_set(self.channel, i, colors[0])
         # Send the LED color data to the hardware.
     resp = ws.ws2811_render(self.leds)
     if resp != 0:
         raise RuntimeError(
             'ws2811_render failed with code {0}'.format(resp))
Пример #7
0
def gradient(style):
    chain = []
    length = style['length']
    crange = style['color_range']  # ['blue', 'yellow']
    speed = style['speed']
    crange = GRB_Parser().convert(crange)
    div = crange[1] - crange[0]
    cnt = 0

    for n in range(length):
        time.sleep(speed)
        cnt += 1
        chain.append(div * cnt)
        if n % length == 0:
            if n < 0:
                n = n * -1
    print(chain)
Пример #8
0
    def party(self, style, internal=False):
        temp_led_count = 480
        if internal:
            temp_led_count = int(self.LED_COUNT / 15)
        cycle_counter = 0
        colors = GRB_Parser().convert(style['css3_colors'])
        speed = style['speed'] or random()
        offset = style['offset'] or 1
        reverse_after = style['reverse_after'] or 0
        iterations = style['iterations'] or 1
        direction = style['direction'] or 1

        while iterations > 0:
            # Update each LED color in the buffer.
            for i in range(self.LED_COUNT):
                # Pick a color based on LED position and an offset for
                # animation.
                color = colors[(i + offset) % len(colors)]

                # Set the LED color buffer value.
                ws.ws2811_led_set(self.channel, i, color)

            # Send the LED color data to the hardware.
            resp = ws.ws2811_render(self.leds)
            if resp != 0:
                raise RuntimeError(
                    'ws2811_render failed with code {0}'.format(resp))

            # Delay for a small period of time.
            time.sleep(speed)

            # Increase offset to animate colors moving.  Will eventually overflow, which
            # is fine.
            if offset > reverse_after or offset < (reverse_after * -1):
                direction *= -1
            offset += direction

            # used to determine end of a task
            cycle_counter += 1
            if not internal:
                if cycle_counter % self.LED_COUNT == 0:
                    iterations -= 1
            else:
                if cycle_counter % temp_led_count == 0:
                    iterations -= 1
Пример #9
0
    def gradient(self, style):
        cycle_counter = 1
        iterations = style['iterations']
        length = style['led_count']
        speed = style['speed']
        direction = style['direction']
        crange = style['color_range']
        crange = GRB_Parser().convert(crange)
        div = (crange[1] - crange[0]) / self.LED_COUNT
        offset = 0

        cnt = 0
        chain = []

        for n in range(length):
            cnt += 1
            chain.append(int(div * cnt))
            if n % length == 0:
                if n < 0:
                    n = n * -1

        while iterations > 0:
            cycle_counter += 1
            chain = deque(chain)
            for i in range(self.LED_COUNT):
                color = chain[(i + offset) % len(list(chain))]
                ws.ws2811_led_set(self.channel, i, color)

            resp = ws.ws2811_render(self.leds)
            if resp != 0:
                raise RuntimeError(
                    'ws2811_render failed with code {0}'.format(resp))
            chain.rotate(direction)
            # print(list(chain), end="\r", flush=True)
            time.sleep(speed)
            if cycle_counter % length == 0:
                iterations -= 1
Пример #10
0
def simulate_2(style):
    length = style['led_count']
    speed = style['speed']
    direction = style['direction']

    chain = []
    crange = ['blue', 'yellow']
    crange = GRB_Parser().convert(crange)

    div = crange[1] - crange[0]
    cnt = 0

    for n in range(length):
        cnt += 1
        chain.append(div * cnt)
        if n % length == 0:
            if n < 0:
                n = n * -1

    while True:
        chain = deque(chain)
        chain.rotate(direction)
        print(list(chain), end="\r", flush=True)
        time.sleep(speed)
Пример #11
0
trail_colors = ['silver']
LED_COUNT = 10

comet = colors + (trail_colors * (LED_COUNT - len(colors)))
# print(comet)
# while True:
#     comet = deque(comet)
#     comet.rotate(1)
#     print(comet)
# sleep(0.2)

l1 = ['joe']

#print(l1 * 7)

c1 = GRB_Parser().convert(['pink'])
c2 = GRB_Parser().convert(['orange'])

c3 = c1 + c1

# print(c3)

gradient_data = {'length': 50, 'color_range': ['orange', 'blue'], 'speed': 0.1}


def gradient(style):
    chain = []
    length = style['length']
    crange = style['color_range']  # ['blue', 'yellow']
    speed = style['speed']
    crange = GRB_Parser().convert(crange)