def default(led: LEDObject): painter_color = [ 'ff0505', '#ff9400', 'ffe800', '0505ff', '#00d6ff', '0505ff', 'd800ff' ] for hexcolor, char in zip(painter_color, 'Painter'): string(led, hexcolor, char) led.show()
def rainbow_long(led: LEDObject, iterations=10, speed=1): """Draw rainbow that uniformly distributes itself across all pixels.""" for j in range(256 * iterations): for i in range(led.num_pixels): led.strip.setPixelColor( i, wheel((int(i * 256 / led.num_pixels) + j) & 255)) led.show() time.sleep(0.0001 / speed**2)
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 pain(led: LEDObject, hexcolor: str): if hexcolor == None: hexcolor = 'ff0000' if hexcolor == 'rainbow': animation_rainbow(led) for char in 'ter': string(led, '000000', char) led.show() else: for char in 'Pain': string(led, hexcolor, char) for char in 'ter': string(led, '000000', char) led.show()
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 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_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_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)
app = Flask(__name__, static_folder='./templates/assets') pattern_list = ['Blink', 'Alternately Blink', 'Rainbow', 'Rainbow Animation', 'Rainbow Long', 'Advance', 'Pain', 'P', 'a', 'i', 'n', 't', 'e', 'r'] speed_list = ['1x', '2x', '4x', '8x', '16x'] color_list = ['white', 'red', 'green', 'blue', 'yellow', 'hotpink', 'aqua', 'darkorange', 'lime', 'rainbow'] now_color_button = 'white' now_pattern = ' ' now_brightness = 255 led = LEDObject() @app.route('/') def index(): return render_template('index.html', now_pattern=now_pattern, now_brightness=str(now_brightness), now_color=now_color_button, pattern_list=pattern_list, pattern_length_div_by_3_int=int(len(pattern_list) / 3), color_list=color_list, color_length_div_by_3_int=int(len(color_list)/3)) @app.route('/set', methods=['POST']) def set_pattern(): global now_pattern global now_color_button global led global now_brightness
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 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 static(led: LEDObject, hexcolor): led.color(hexcolor) led.show()
pos -= 85 return Color(255 - pos * 3, 0, pos * 3) else: pos -= 170 return Color(0, pos * 3, 255 - pos * 3) def Color(red, green, blue, white=0): """Convert the provided red, green, blue color to a 24-bit color value. Each color component should be a value 0-255 where 0 is the lowest intensity and 255 is the highest intensity. """ return (white << 24) | (red << 16) | (green << 8) | blue led = LEDObject() argc = len(sys.argv) if argc == 1: print('Error: 引数が足りません') exit(-1) pattern = sys.argv[1] option1 = None option2 = None if argc >= 3: # オプションが存在 for i in range(2, argc): if 'option1=' in sys.argv[i]: option1 = int(sys.argv[i][8:][:-1])