def animation_blink(led: LEDObject, speed: int, hexcolor: str): if speed == None: speed = 16 if hexcolor == None: hexcolor = 'ffffff' sleepsec = 0.2 if hexcolor == 'rainbow': animation_rainbow(led) color_list = led.get_now_color() while True: # set rainbow for i, color in enumerate(color_list): led.color(color, position=i) # change brightness for brightness in range(0, 256, 17 - speed): led.brightbess(brightness) time.sleep(0.01) for brightness in list(range(0, 256, 17 - speed))[::-1]: led.brightbess(brightness) time.sleep(0.001) else: while True: led.color(hexcolor) # change brightness for brightness in range(0, 256, 17 - speed): led.brightbess(brightness) time.sleep(0.001) for brightness in list(range(0, 256, 17 - speed))[::-1]: led.brightbess(brightness) time.sleep(0.0001)
def animation_rainbow_flow(led: LEDObject, speed: int, circle_width=60): if speed == None: speed = 1 """Draw rainbow that uniformly distributes itself across all pixels.""" # set rainbow for i in range(0, led.num_pixels, circle_width): for j in range(0, circle_width): if i + j >= led.num_pixels: break h = 1 / circle_width * j r, g, b = colorsys.hsv_to_rgb(h, 1.0, 1.0) hex_rgb = [ hex(int(r * 255)).split('0x')[-1], hex(int(g * 255)).split('0x')[-1], hex(int(b * 255)).split('0x')[-1] ] hexcolor = '' for color in hex_rgb: if len(color) == 1: color = '0' + color hexcolor += color led.color(hexcolor, i + j) while True: led.show() led.pixel_shift(pixel_num=speed)
def string(led: LEDObject, hexcolor: str, char: str): """ set color only single char warning: this method does not clear other pixel """ if len(char) != 1: raise ValueError if hexcolor == None: hexcolor = 'ffffff' for i in led.painter[char]: led.color(hexcolor, position=i)
def animation_flow(led: LEDObject, speed: int, hexcolor: str, block=2): if speed == None: speed = 1 if hexcolor == None: hexcolor = 'ffffff' sleepsec = 0.1 while True: for i in range(0, led.num_pixels, block): led.color('000000') # clear for j in range(block): led.color(hexcolor, position=i + j) led.show() time.sleep(sleepsec / speed)
def animation_round(led: LEDObject, char: str, speed: int, hexcolor: str): if len(char) != 1: raise ValueError # Init led.off() if speed == None: speed = 1 if hexcolor == None: hexcolor = 'ffffff' for count, line in enumerate(led.round_painter[char]): for pixel in line: led.color(hexcolor, pixel) if count % speed == 0: led.show() time.sleep(0.001 / speed) led.show()
def animation_rainbow(led: LEDObject, circle_width=60): # set rainbow for i in range(0, led.num_pixels, circle_width): for j in range(0, circle_width): if i + j >= led.num_pixels: break h = 1 / circle_width * j r, g, b = colorsys.hsv_to_rgb(h, 1.0, 1.0) hex_rgb = [ hex(int(r * 255)).split('0x')[-1], hex(int(g * 255)).split('0x')[-1], hex(int(b * 255)).split('0x')[-1] ] hexcolor = '' for color in hex_rgb: if len(color) == 1: color = '0' + color hexcolor += color led.color(hexcolor, i + j) led.show()
def animation_alternating_flashing(led: LEDObject, speed: int, hexcolor: str, dist=6): if speed == None: speed = 1 if hexcolor == None: hexcolor = 'ffffff' sleepsec = 0.2 while True: led.color('000000') for i in range(0, led.num_pixels, dist * 2): for j in range(0, dist): if i + j >= led.num_pixels: break led.color(hexcolor, position=i + j) for j in range(dist, dist * 2): if i + j >= led.num_pixels: break led.color('000000', position=i + j) led.show() time.sleep(sleepsec / speed) led.color('000000') for i in range(0, led.num_pixels, dist * 2): for j in range(0, dist): if i + j >= led.num_pixels: break led.color('000000', position=i + j) for j in range(dist, dist * 2): if i + j >= led.num_pixels: break led.color(hexcolor, position=i + j) led.show() time.sleep(sleepsec / speed)
def static(led: LEDObject, hexcolor): led.color(hexcolor) led.show()