def run(): """let's goooo""" mote = Mote() mote.configure_channel(1, 16, False) mote.configure_channel(2, 16, False) mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) rand_cols = ColorRandom() patterns = [ pattern_floodfill, pattern_scatter, pattern_race, pattern_horizflood, pattern_horizsnakeflood, pattern_snakeflood, ] black = lambda: ColorConstant([0, 0, 0]) colors = [ ColorRandom, lambda: ColorConstant(rand_cols.get(None)), lambda: ColorChannelConstant(rand_cols), lambda: ColorChannelFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorGlobalFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorPixelFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorHorizCenterFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorRadialFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorChequerboard(rand_cols), ] last_col_template = None last_pattern_template = None while True: pattern_template = choice(patterns) if pattern_template == last_pattern_template: continue pattern = pattern_template() if random() < 0.5 else pattern_reverse( pattern_template()) color_template = black if (random() < 0.33 and last_col_template is not None) \ else choice(colors) if color_template == last_col_template: continue color = color_template() for update in pattern: c = color.get(update) prev_c = mote.get_pixel(update[0], update[1]) for step in range(8): step_c = lerp_cols(step / 7.0, prev_c, c) mote.set_pixel(update[0], update[1], step_c[0], step_c[1], step_c[2]) mote.show() time.sleep(0.03) last_col_template = color_template last_pattern_template = pattern_template
for step in range(4): for channel in range(4): for pixel in range(mote.get_pixel_count(channel + 1)): r, g, b = colors[channel] mote.set_pixel(channel + 1, pixel, r, g, b) mote.show() time.sleep(0.01) colors.append(colors.pop(0)) # Fade out pixels from their last state for step in range(170): for channel in range(4): for pixel in range(mote.get_pixel_count(channel + 1)): r, g, b = [ int(c * 0.99) for c in mote.get_pixel(channel + 1, pixel) ] mote.set_pixel(channel + 1, pixel, r, g, b) time.sleep(0.001) mote.show() # Face back in to a rainbow brightness = 0 # for h in range(1000): # for channel in range(4): # for pixel in range(mote.get_pixel_count(channel + 1)): # hue = (h + (channel * num_pixels * 4) + (pixel * 4)) % 360 # r, g, b = [int(c * brightness) for c in hsv_to_rgb(hue/360.0, 1.0, 1.0)] # mote.set_pixel(channel + 1, pixel, r, g, b) # mote.show()
# Display solid colour test for step in range(4): for channel in range(4): for pixel in range(mote.get_pixel_count(channel + 1)): r, g, b = colors[channel] mote.set_pixel(channel + 1, pixel, r, g, b) mote.show() time.sleep(0.01) colors.append(colors.pop(0)) # Fade out pixels from their last state for step in range(170): for channel in range(4): for pixel in range(mote.get_pixel_count(channel + 1)): r, g, b = [int(c * 0.99) for c in mote.get_pixel(channel + 1, pixel)] mote.set_pixel(channel + 1, pixel, r, g, b) time.sleep(0.001) mote.show() # Face back in to a rainbow brightness = 0 for h in range(1000): for channel in range(4): for pixel in range(mote.get_pixel_count(channel + 1)): hue = (h + (channel * num_pixels * 4) + (pixel * 4)) % 360 r, g, b = [int(c * brightness) for c in hsv_to_rgb(hue/360.0, 1.0, 1.0)] mote.set_pixel(channel + 1, pixel, r, g, b) mote.show() time.sleep(0.01)