def rainbowSparklesGetPixelColour(rgb0, rgb1, rgb2, waveOffset, random_values, ii): t = time.time()*0.6 if random_values[ii] < 0.5: r, g, b = tuple(rgb0[channel] / 128.0 for channel in range(3)) elif random_values[ii] < 0.85: r, g, b = tuple(rgb1[channel] / 128.0 for channel in range(3)) else: r, g, b = tuple(rgb2[channel] / 128.0 for channel in range(3)) stringIndex = ii % pixels_per_string # twinkle occasional LEDs twinkle_speed = 0.03 twinkle_density = 0.8 twinkle = (random_values[ii]*7 + time.time()*twinkle_speed) % 1 twinkle = abs(twinkle*2 - 1) twinkle = color_utils.remap(twinkle, 0, 1, -1/twinkle_density, 1.1) twinkle = color_utils.clamp(twinkle, -0.5, 1.1) twinkle **= 5 twinkle *= color_utils.cos(t - stringIndex/float(pixels_per_string), offset=waveOffset, period=7, minn=0.1, maxx=1.0) ** 20 twinkle = color_utils.clamp(twinkle, -0.3, 1) r *= twinkle g *= twinkle b *= twinkle # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (g*256, r*256, b*256)
def miami_color(t, item, random_values, accum): coord = item['coord'] # make moving stripes for x, y, and z x, y, z, theta, r, xr, yr = coord y += color_utils.cos(x - 0.2*z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y - z, offset=0, period=1.5, minn=0, maxx=0.2) # make x, y, z -> r, g, b sine waves r = color_utils.cos(y, offset=t / 16, period=2.5, minn=0, maxx=1) g = color_utils.cos(z, offset=t / 16, period=2.5, minn=0, maxx=1) b = color_utils.cos(-x, offset=t / 16, period=2.5, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.4) clampdown = (r + g + b)/2 clampdown = color_utils.remap(clampdown, 0.4, 0.5, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) clampdown *= 0.8 r *= clampdown g *= clampdown b *= clampdown g = g * 0.1 + 0.8 * (b + 0.2 * r) / 2 return (r*256, g*256, b*256)
def circles(cycle_secs): if cycle_secs == 0: cycle_secs = 4 start_time = time.time() t_change_pos = -10000 center_x, center_y = 0.5, 0.5 r_rand, g_rand, b_rand = 1, 1, 1 stroke_width = 0.125 last_t_step = start_time + 100000 r_max = 0 while True: t = time.time() - start_time t_step = t % cycle_secs t_norm = t_step / cycle_secs rad = t_norm * r_max # ease_out_quartic(t_step, 0, 1, cycle_secs) if last_t_step > t_step:#- t_change_pos > cycle_secs: # every cycle_secs... t_change_pos = t center_x, center_y = random.random(), random.random() # change circle center r_rand, g_rand, b_rand = random.random(), random.random(), random.random() # adjust color stroke_width = 0.0625 + random.random() * 0.25 # change circle stroke width r_max = max(center_x, center_y, 1 - center_x, 1 - center_y) + stroke_width * 2 # max radius required to get cirlce + stroke beyond visible edges of pixel grid pixels = [] for ii in range(n_pixels): x = int(ii / n_pixels_strut) # calc x and y coords (x is strut to strut, y is each pixel along strut) y = ii % n_pixels_strut xnorm = x / n_struts # normalize pixel coordinates ynorm = y / n_pixels_strut dist = math.sqrt(math.pow(center_x - xnorm, 2) + math.pow(center_y - ynorm, 2)) # distance between pixel and circle center intens = 1 - (math.fabs(rad - dist) / stroke_width) # bright pixels near circle radius, dimmer further away and toward center intens = color_utils.remap(color_utils.clamp(intens, 0, 1), 0, 1, 0, 256) r, g, b = intens * r_rand, intens * g_rand, intens * b_rand pixels.append((r, g, b)) client.put_pixels(pixels, channel=0) time.sleep(1 / fps) last_t_step = t_step
def next_frame(self, octopus, data): current_time = np.float16((time.time() - self.start_time) % 1000) speed = data.level self.pattern_time = self.pattern_time + ( self.time_warp_speed * speed + 1) * (self.real_time - current_time) self.real_time = current_time t = self.pattern_time blackstripes = color_utils.cos_lookup(self.pct_jittered, offset=t * 0.05, period=1, minn=-1.5, maxx=1.5) blackstripes_offset = color_utils.cos_lookup(t, offset=0.9, period=60, minn=-0.5, maxx=3) clamp = color_utils.clamp(blackstripes + blackstripes_offset, 0, 1) r = clamp * np.float16(127) * (np.float16(1) + color_utils.cos_lookup( two_pi * (t / self.speed_r + self.pct * self.freq_r))) g = clamp * np.float16(127) * (np.float16(1) + color_utils.cos_lookup( two_pi * (t / self.speed_g + self.pct * self.freq_g))) b = clamp * np.float16(127) * (np.float16(1) + color_utils.cos_lookup( two_pi * (t / self.speed_b + self.pct * self.freq_b))) for i in range(len(self.pixels)): self.pixels[i].color = (r[i], g[i], b[i])
def mesmerize_color(t, coord, ii, n_pixels, random_value, accum): if regions[ii] == "off": return (0, 0, 0) s = color_utils.clamp( math.sin(1.8 * math.sqrt(coord[0]**2 + coord[1]**2 + 2 * (coord[2]**2)) - t * 6.0) * 0.75 + 0.5, 0, 1) return HSLColor(0, 0, s).convert_to('rgb').get_value_tuple()
def rain(coordinates, nextDrop, avgInterval, fadeStep): global largeDrops if (random.random() < 0.05 and len(largeDrops) < 3): fadeSpeed = random.uniform(0.5, 0.95) largeDrops.append(largeDrop((random.uniform(-5, 5), random.uniform(-5, 5), 0.0), tuple(random.uniform(128, 255) for i in range(3)), random.uniform(1, 2), tuple(color_utils.clamp(random.gauss(fadeSpeed, fadeSpeed/8), 0.5, 0.95) for i in range(3)), coordinates)) for drop in largeDrops: drop.tick() largeDrops = [x for x in largeDrops if not x.expired] for ii in range(n_pixels): bgColour = [0.0, 0.0, 0.0] for drop in largeDrops: influence = drop.getInfluence(ii) for colour in range(3): bgColour[colour] = min(bgColour[colour] + influence[colour], 255) if bgColour[colour] < softWarmWhite[colour]: bgColour[colour] = softWarmWhite[colour] stringPosition = ii % pixels_per_string cosFactor = 2*3.14/pixels_per_string timeFactor = 0.07 colourOffset = (0.05, 0.1, 0.0) # slowWaveVal = color_utils.remap(math.cos(-time.time() + stringPosition*cosFactor + offset) pixels[ii] = fadeDownTo(pixels[ii], bgColour, fadeStep) if (time.time() > nextDrop): pixels[random.randrange(n_pixels)] = tuple(color_utils.clamp(random.gauss(x, stdDev*255.0/x), pixels[ii][i], 255) for i, x in enumerate(warmWhite)) nextDrop = time.time() + random.gauss(avgInterval, avgInterval/2) return nextDrop
def miami_color(t, pixel, random_values, accum): # hue-restricted, faster version of miami.py from OPC samples # make moving stripes for x, y, and z x, y, z, theta, r, xr, yr = pixel['coord'] y += color_utils.scaled_cos(x - 0.2*z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.scaled_cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.scaled_cos(y - z, offset=0, period=1.5, minn=0, maxx=0.2) # make x, y, z -> r, g, b sine waves r = color_utils.scaled_cos(y, offset=t / 16, period=2.5, minn=0, maxx=1) g = color_utils.scaled_cos(z, offset=t / 16, period=2.5, minn=0, maxx=1) b = color_utils.scaled_cos(-x, offset=t / 16, period=2.5, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.4) clampdown = (r + g + b)/2 clampdown = color_utils.remap(clampdown, 0.4, 0.5, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) clampdown *= 0.8 r *= clampdown g *= clampdown b *= clampdown g = g * 0.1 + 0.8 * (b + 0.2 * r) / 2 return (r, g, b)
def miami_color(t, pixel, random_values, accum): # hue-restricted, faster version of miami.py from OPC samples # make moving stripes for x, y, and z x, y, z, theta, r, xr, yr = pixel['coord'] y += color_utils.scaled_cos(x - 0.2 * z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.scaled_cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.scaled_cos(y - z, offset=0, period=1.5, minn=0, maxx=0.2) # make x, y, z -> r, g, b sine waves r = color_utils.scaled_cos(y, offset=t / 16, period=2.5, minn=0, maxx=1) g = color_utils.scaled_cos(z, offset=t / 16, period=2.5, minn=0, maxx=1) b = color_utils.scaled_cos(-x, offset=t / 16, period=2.5, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.4) clampdown = (r + g + b) / 2 clampdown = color_utils.remap(clampdown, 0.4, 0.5, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) clampdown *= 0.8 r *= clampdown g *= clampdown b *= clampdown g = g * 0.1 + 0.8 * (b + 0.2 * r) / 2 return (r, g, b)
def next_frame(self, octopus, data): t = time.time() - self.start_time pixels = octopus.pixels() num_pixels = len(pixels) for ii in range(num_pixels): pct = ii / num_pixels # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t * 0.05, period=1, minn=-1.5, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap( math.cos((t / self.speed_r + pct * self.freq_r) * math.pi * 2), -1, 1, 0, 256) g = blackstripes * color_utils.remap( math.cos((t / self.speed_g + pct * self.freq_g) * math.pi * 2), -1, 1, 0, 256) b = blackstripes * color_utils.remap( math.cos((t / self.speed_b + pct * self.freq_b) * math.pi * 2), -1, 1, 0, 256) pixels[ii].color = (r, g, b)
def pixel_color(t, coord, ii, n_pixels, random_values): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple Returns an (r, g, b) tuple in the range 0-255 """ # # random persistant color per pixel # r = color_utils.remap(random_values[(ii+0)%n_pixels], 0, 1, 0.2, 1) # g = color_utils.remap(random_values[(ii+3)%n_pixels], 0, 1, 0.2, 1) # b = color_utils.remap(random_values[(ii+6)%n_pixels], 0, 1, 0.2, 1) # random assortment of a few colors per pixel: pink, cyan, white if random_values[ii] < 0.5: r, g, b = (1, 0.3, 0.8) elif random_values[ii] < 0.85: r, g, b = (0.4, 0.7, 1) else: r, g, b = (2, 0.6, 1.6) # twinkle occasional LEDs twinkle_speed = 0.07 twinkle_density = 0.1 twinkle = (random_values[ii] * 7 + time.time() * twinkle_speed) % 1 twinkle = abs(twinkle * 2 - 1) twinkle = color_utils.remap(twinkle, 0, 1, -1 / twinkle_density, 1.1) twinkle = color_utils.clamp(twinkle, -0.5, 1.1) twinkle **= 5 twinkle *= color_utils.cos(t - ii / n_pixels, offset=0, period=7, minn=0.1, maxx=1.0)**20 twinkle = color_utils.clamp(twinkle, -0.3, 1) r *= twinkle g *= twinkle b *= twinkle # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (r * 256, g * 256, b * 256)
def pixel_color(t, coord, ii, n_pixels, random_values): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple n_pixels: the total number of pixels random_values: a list containing a constant random value for each pixel Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord y += color_utils.cos(x + 0.2*z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y + z, offset=0, period=1.5, minn=0, maxx=0.2) # rotate x, y, z = y, z, x # # shift some of the pixels to a new xyz location # if ii % 17 == 0: # x += ((ii*123)%5) / n_pixels * 32.12 + 0.1 # y += ((ii*137)%5) / n_pixels * 22.23 + 0.1 # z += ((ii*147)%7) / n_pixels * 44.34 + 0.1 # make x, y, z -> r, g, b sine waves r = color_utils.cos(x, offset=t / 4, period=2, minn=0, maxx=1) g = color_utils.cos(y, offset=t / 4, period=2, minn=0, maxx=1) b = color_utils.cos(z, offset=t / 4, period=2, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.5) # r, g, b = color_utils.clip_black_by_luminance((r, g, b), 0.5) # # shift the color of a few outliers # if random_values[ii] < 0.03: # r, g, b = b, g, r # black out regions r2 = color_utils.cos(x, offset=t / 10 + 12.345, period=3, minn=0, maxx=1) g2 = color_utils.cos(y, offset=t / 10 + 24.536, period=3, minn=0, maxx=1) b2 = color_utils.cos(z, offset=t / 10 + 34.675, period=3, minn=0, maxx=1) clampdown = (r2 + g2 + b2)/2 clampdown = color_utils.remap(clampdown, 0.8, 0.9, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) r *= clampdown g *= clampdown b *= clampdown # color scheme: fade towards blue-and-orange # g = (r+b) / 2 g = g * 0.6 + ((r+b) / 2) * 0.4 # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (r*256, g*256, b*256)
def get_color(self, x, y, t): dx = x - self.cx dy = y - self.cy if dx == dy == 0: r = 1 else: a = math.atan2(dx, dy) r = color_utils.cos(a + t, period=0.3 * math.pi, minn=-0.5, maxx=1.5) return (color_utils.clamp(r, 0, 1) * 255, 0, 0)
def pixel_color(t, coord, ii, n_pixels, random_values): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple Returns an (r, g, b) tuple in the range 0-255 """ # # random persistant color per pixel # r = color_utils.remap(random_values[(ii+0)%n_pixels], 0, 1, 0.2, 1) # g = color_utils.remap(random_values[(ii+3)%n_pixels], 0, 1, 0.2, 1) # b = color_utils.remap(random_values[(ii+6)%n_pixels], 0, 1, 0.2, 1) # random assortment of a few colors per pixel: pink, cyan, white if random_values[ii] < 0.5: r, g, b = (1, 0.3, 0.8) elif random_values[ii] < 0.85: r, g, b = (0.4, 0.7, 1) else: r, g, b = (2, 0.6, 1.6) # twinkle occasional LEDs twinkle_speed = 0.06 twinkle_density = 0.1 twinkle = (random_values[ii]*7 + time.time()*twinkle_speed) % 1 twinkle = abs(twinkle*2 - 1) twinkle = color_utils.remap(twinkle, 0, 1, -1/twinkle_density, 1.1) twinkle = color_utils.clamp(twinkle, -0.5, 1.1) twinkle **= 5 #twinkle *= color_utils.cos(t - ii/n_pixels, offset=0, period=10, minn=0.1, maxx=1.0) ** 20 twinkle *= color_utils.cos(t - ii/n_pixels, offset=0, period=10, minn=0.1, maxx=1.0) ** 10 twinkle = color_utils.clamp(twinkle, -0.3, 1) r *= twinkle g *= twinkle b *= twinkle # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (r*256, g*256, b*256)
def draw(self, coord): """returns an rgb tuple to add to the current coordinates color""" color = self.color distance = math_utils.dist(coord, self.pos) (r, g, b) = (0.0, 0.0, 0.0) if distance < self.size + 0.1: dot = (1 / (distance + 0.0001) ) # + (time.time()*twinkle_speed % 1) # dot = abs(dot * 2 - 1) dot = color_utils.remap(dot, 0, 10, 0.1, 1.1) dot = color_utils.clamp(dot, -0.5, 1.1) # dot **=2 dot = color_utils.clamp(dot, 0.2, 1) r = color[0] * dot g = color[1] * dot b = color[2] * dot new_color = (r, g, b) return new_color
def raver_plaid_tree(): # how many sine wave cycles are squeezed into our n_pixels # 24 happens to create nice diagonal stripes on the wall layout freq_r = 5 freq_g = 5 freq_b = 5 # how many seconds the color sine waves take to shift through a complete cycle speed_r = 7 speed_g = -13 speed_b = 19 start_time = time.time() sub_lights_num = num_lights_per_vine*num_vines_per_branch*2 while True: t = time.time() - start_time fade_factor = 1.0 if t > pattern_runtime: break elif t < fade_in_time: fade_factor = t/fade_in_time elif t > fade_out_time: fade_factor = (pattern_runtime-t)/fade_in_time pixels = [] for index in range(4): sub_pixels = [] for ii in range(sub_lights_num): pct = ii / sub_lights_num # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t*0.05, period=1, minn=-1.5, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) blackstripes = color_utils.clamp(blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = max(0.1, blackstripes * color_utils.remap(math.cos((t/speed_r + pct*freq_r)*math.pi*2), -1, 1, 0, 256)*fade_factor) g = max(0.1, blackstripes * color_utils.remap(math.cos((t/speed_g + pct*freq_g)*math.pi*2), -1, 1, 0, 256)*fade_factor) b = max(0.1, blackstripes * color_utils.remap(math.cos((t/speed_b + pct*freq_b)*math.pi*2), -1, 1, 0, 256)*fade_factor) sub_pixels.append((r, g, b)) current_pixels_size = len(pixels) current_sub_pixel_size = len(sub_pixels) sub_first_half = sub_pixels[:int(current_sub_pixel_size/2)] sub_second_half = sub_pixels[int(current_sub_pixel_size/2):] for x in sub_first_half: pixels.insert(int(current_pixels_size/2), x) pixels.extend(sub_second_half) client.put_pixels(pixels, channel=0) time.sleep(1 / frames_per_second)
def render_pixels(n_pixels, frame_time, osc_inputs, control_dict): pixels = [] black_params = control_dict["/LeftBlack/1"], control_dict["/LeftBlack/2"], control_dict["/LeftBlack/3"], control_dict["/LeftBlack/4"] red_params = control_dict["/LeftRed/1"], control_dict["/LeftRed/2"] green_params = control_dict["/LeftGreen/1"], control_dict["/LeftGreen/2"] blue_params = control_dict["/LeftBlue/1"], control_dict["/LeftBlue/2"] rgb_params = control_dict["/RedLevel"], control_dict["/GreenLevel"], control_dict["/BlueLevel"] saturation = control_dict["/Saturation"] brightness = control_dict["/LeftBright"] for i in range(n_pixels): pct = i / n_pixels # diagonal black stripes pct_jittered = (pct * 33 ) % 33 blackstripes = color_utils.cos( pct_jittered, #frame_time * pct_jittered, offset = frame_time * black_params[0], period = black_params[1], minn = -1.0, maxx = 2.5) blackstripes_offset = color_utils.cos( frame_time * 0.1, offset = black_params[2], period = black_params[3], minn = -1.5, maxx = 3) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) # sinewave function for colors def color_stripe(params): return blackstripes * color_utils.remap( math.cos(( frame_time/params[0] + pct*params[1])*math.pi*2), -1, 1, 0, 255) # 3 sine waves for r, g, b which are out of sync with each other r = num_clamp(color_stripe(red_params) * control_dict["/RedLevel"] * brightness, 0.0001, 255.0) g = num_clamp(color_stripe(green_params) * control_dict["/GreenLevel"] * brightness, 0.0001, 255.0) b = num_clamp(color_stripe(blue_params) * control_dict["/BlueLevel"] * brightness, 0.0001, 255.0) # allow for HSV modifications try: h, s, v = colorutils.rgb_to_hsv((r, g, b)) s = num_clamp(s * saturation, 0.00001, 1.0) r, g, b = colorutils.hsv_to_rgb((h, s, v)) except: pass #print((r, g, b), (h, s, v)) pixels.append((r, g, b)) return pixels
def raver_palid(fps=100, n_pixels=25): global aniIndex, client print("Raver") start_time = time.time() # how many sine wave cycles are squeezed into our n_pixels # 24 happens to create nice diagonal stripes on the wall layout freq_r = 24 freq_g = 24 freq_b = 24 # how many seconds the color sine waves take to shift through a complete cycle speed_r = 7 speed_g = -13 speed_b = 19 while aniIndex == 1: t = (time.time() - start_time) * 5 pixels = [] for ii in range(n_pixels): pct = (ii / n_pixels) # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t * 0.05, period=1, minn=-1.5, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap( math.cos( (t / speed_r + pct * freq_r) * math.pi * 2), -1, 1, 0, 255) g = blackstripes * color_utils.remap( math.cos( (t / speed_g + pct * freq_g) * math.pi * 2), -1, 1, 0, 255) b = blackstripes * color_utils.remap( math.cos( (t / speed_b + pct * freq_b) * math.pi * 2), -1, 1, 0, 255) pixels.append((r, g, b)) all_nodes.setNodeColor(int(ii), int(r), int(g), int(b)) if (run_sim == True): client.put_pixels(pixels, channel=0) time.sleep(1 / fps)
def draw(self, coord): """returns an rgb tuple to add to the current coordinates color""" color = self.color (r, g, b) = (0, 0, 0) dist_line = math_utils.dist_line_point(self.pos, self.p2, coord) # only compute further if we are very close to the line already if dist_line < 0.08: distance = math_utils.dist_line_seg_point(self.pos, self.p2, coord) if distance < self.size: dot = (1 / (distance + 0.0001) ) # + (time.time()*twinkle_speed % 1) # dot = abs(dot * 2 - 1) dot = color_utils.remap(dot, 0, 10, 0.1, 1.1) dot = color_utils.clamp(dot, -0.5, 1.1) # dot **=2 dot = color_utils.clamp(dot, 0.2, 1) r = color[0] * dot g = color[1] * dot b = color[2] * dot new_color = (r, g, b) return new_color
def render_pixels(queue_r, queue_g, queue_b): start_time = time.time() while True: t = time.time() - start_time pixels = [] for ii in range(n_pixels): pct = ii / n_pixels # diagonal black stripes pct_jittered = (pct * 77 ) % 77 blackstripes = color_utils.cos( pct_jittered, offset=t*0.05, period=20, minn=-1.0, maxx=2.5) blackstripes_offset = color_utils.cos( t, offset=-0.9, period=60, minn=-1.5, maxx=3) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r_name, speed_r, freq_r = queue_r.get() g_name, speed_g, freq_g = queue_g.get() b_name, speed_b, freq_b = queue_b.get() print(("%.2f" %t, speed_r, freq_r)) print(("%.2f" %t, speed_g, freq_g)) print(("%.2f" %t, speed_b, freq_b)) r = blackstripes * color_utils.remap( math.cos(( t/speed_r + pct*freq_r)*math.pi*2), -1, 1, 0, 256) g = blackstripes * color_utils.remap( math.cos(( t/speed_g + pct*freq_g)*math.pi*2), -1, 1, 0, 256) b = blackstripes * color_utils.remap( math.cos((t/speed_b + pct*freq_b)*math.pi*2), -1, 1, 0, 256) pixels.append((r, g, b)) client.put_pixels(pixels, channel=0) time.sleep(1 / fps)
def rainbowWaves(speed_r, speed_g, speed_b): # how many sine wave cycles are squeezed into our n_pixels # 24 happens to create nice diagonal stripes on the wall layout freq_r = 24 freq_g = 24 freq_b = 24 t = (time.time() - start_time) * 5 for ii in range(n_pixels): pct = (ii / n_pixels) # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t*0.05, period=1, minn=-1.5, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) blackstripes = color_utils.clamp(blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap(math.cos((t/speed_r + pct*freq_r)*math.pi*2), -1, 1, 0, 256) g = blackstripes * color_utils.remap(math.cos((t/speed_g + pct*freq_g)*math.pi*2), -1, 1, 0, 256) b = blackstripes * color_utils.remap(math.cos((t/speed_b + pct*freq_b)*math.pi*2), -1, 1, 0, 256) pixels[ii] = fadeDownTo(pixels[ii], (r, g, b), 0.5)
def get_pixels(self, t): pixels = [] flow_color = None for ii in range(self.n_pixels): pct = ii / self.n_pixels # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t*0.05, period=1, minn=0, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) blackstripes = color_utils.clamp(blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap(math.cos((t/speed_r + pct*freq_r)*math.pi*2), -1, 1, 10, 256) g = blackstripes * color_utils.remap(math.cos((t/speed_g + pct*freq_g)*math.pi*2), -1, 1, 10, 256) b = blackstripes * color_utils.remap(math.cos((t/speed_b + pct*freq_b)*math.pi*2), -1, 1, 10, 256) if flow[ii]: if flow_color is None: flow_color = (r, 0, 0) pixels.append(flow_color) else: pixels.append((0, g, b)) return pixels
def lavaLamp(coordinates): t = time.time() * 0.6 for ii in range(n_pixels): # make moving stripes for x, y, and z x, y, z = coordinates[ii] y += color_utils.cos(x + 0.2*z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y + z, offset=0, period=1.5, minn=0, maxx=0.2) # rotate x, y, z = y, z, x # make x, y, z -> r, g, b sine waves r = color_utils.cos(x, offset=t / 4, period=2, minn=0, maxx=1) g = color_utils.cos(y, offset=t / 4, period=2, minn=0, maxx=1) b = color_utils.cos(z, offset=t / 4, period=2, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.5) # black out regions r2 = color_utils.cos(x, offset=t / 10 + 12.345, period=3, minn=0, maxx=1) g2 = color_utils.cos(y, offset=t / 10 + 24.536, period=3, minn=0, maxx=1) b2 = color_utils.cos(z, offset=t / 10 + 34.675, period=3, minn=0, maxx=1) clampdown = (r2 + g2 + b2)/2 clampdown = color_utils.remap(clampdown, 0.8, 0.9, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) r *= clampdown g *= clampdown b *= clampdown # color scheme: fade towards blue-and-orange g = g * 0.6 + ((r+b) / 2) * 0.4 # apply gamma curve # only do this on live leds, not in the simulator r, g, b = color_utils.gamma((r, g, b), 2.2) pixels[ii] = fadeDownTo(pixels[ii], (r*256, g*256, b*256), 0.25)
def miami_color(t, coord, ii, n_pixels, random_values, accum): # make moving stripes for x, y, and z x, y, z, theta, r, xr, yr = coord y += color_utils.cos(x - 0.2*z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y - z, offset=0, period=1.5, minn=0, maxx=0.2) # make x, y, z -> r, g, b sine waves r = color_utils.cos(y, offset=t / 16, period=2.5, minn=0, maxx=1) g = color_utils.cos(z, offset=t / 16, period=2.5, minn=0, maxx=1) b = color_utils.cos(-x, offset=t / 16, period=2.5, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.4) clampdown = (r + g + b)/2 clampdown = color_utils.remap(clampdown, 0.4, 0.5, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) clampdown *= 0.8 r *= clampdown g *= clampdown b *= clampdown g = g * 0.1 + 0.8 * (b + 0.2 * r) / 2 return (r*256, g*256, b*256)
def raver_plaid(n_pixels, params, frame_time): print(params) red_params, green_params, blue_params = params pixels = [] for i in range(n_pixels): pct = i / n_pixels # diagonal black stripes pct_jittered = (pct * 77 ) % 77 blackstripes = color_utils.cos( pct_jittered, offset=frame_time*0.05, period=20, minn=-1.0, maxx=2.5) blackstripes_offset = color_utils.cos( frame_time, offset=-0.9, period=60, minn=-1.5, maxx=3) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) def color_stripe(params): return blackstripes * color_utils.remap( math.cos(( frame_time/params.speed + pct*params.freq)*math.pi*2), -1, 1, 0, 256) # 3 sine waves for r, g, b which are out of sync with each other r = color_stripe(red_params) g = color_stripe(green_params) b = color_stripe(blue_params) pixels.append((r, g, b)) return pixels
def get_pixels(self, t): pixels = [] flow_color = None for ii in range(self.n_pixels): pct = ii / self.n_pixels # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t * 0.05, period=1, minn=0, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap( math.cos((t / speed_r + pct * freq_r) * math.pi * 2), -1, 1, 10, 256) g = blackstripes * color_utils.remap( math.cos((t / speed_g + pct * freq_g) * math.pi * 2), -1, 1, 10, 256) b = blackstripes * color_utils.remap( math.cos((t / speed_b + pct * freq_b) * math.pi * 2), -1, 1, 10, 256) if flow[ii]: if flow_color is None: flow_color = (r, 0, 0) pixels.append(flow_color) else: pixels.append((0, g, b)) return pixels
def pixel_color(t, coord, ii, n_pixels, random_values): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple n_pixels: the total number of pixels random_values: a list containing a constant random value for each pixel Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord y += color_utils.cos(x + 0.2 * z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y + z, offset=0, period=1.5, minn=0, maxx=0.2) # rotate x, y, z = y, z, x # shift some of the pixels to a new xyz location if ii % 7 == 0: x += ((ii * 123) % 5) / n_pixels * 32.12 y += ((ii * 137) % 5) / n_pixels * 22.23 z += ((ii * 147) % 7) / n_pixels * 44.34 # make x, y, z -> r, g, b sine waves r = color_utils.cos(x, offset=t / 4, period=2, minn=0, maxx=1) g = color_utils.cos(y, offset=t / 4, period=2, minn=0, maxx=1) b = color_utils.cos(z, offset=t / 4, period=2, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.5) # a moving wave across the pixels, usually dark. # lines up with the wave of twinkles fade = color_utils.cos(t - ii / n_pixels, offset=0, period=7, minn=0, maxx=1)**20 r *= fade g *= fade b *= fade # # stretched vertical smears # v = color_utils.cos(ii / n_pixels, offset=t*0.1, period = 0.07, minn=0, maxx=1) ** 5 * 0.3 # r += v # g += v # b += v # twinkle occasional LEDs twinkle_speed = 0.07 twinkle_density = 0.1 twinkle = (random_values[ii] * 7 + time.time() * twinkle_speed) % 1 twinkle = abs(twinkle * 2 - 1) twinkle = color_utils.remap(twinkle, 0, 1, -1 / twinkle_density, 1.1) twinkle = color_utils.clamp(twinkle, -0.5, 1.1) twinkle **= 5 twinkle *= color_utils.cos(t - ii / n_pixels, offset=0, period=7, minn=0, maxx=1)**20 twinkle = color_utils.clamp(twinkle, -0.3, 1) r += twinkle g += twinkle b += twinkle # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (r * 256, g * 256, b * 256)
def render_pixels(n_pixels, client, start_time): t = time.time() - start_time queue = command_queue.__weakref__() global speed_r global speed_g global speed_b global freq_r global freq_g global freq_b global black_offset_1 global black_offset_2 global black_period_1 global black_period_2 name = "" if queue.empty(): queue.put(('/red', speed_r, freq_r)) queue.put(('/green', speed_g, freq_g)) queue.put(('/blue', speed_b, freq_b)) queue.put(('/black_offset', black_offset_1, black_offset_2)) queue.put(('/black_period', black_period_1, black_period_2)) else: name, speed, freq = queue.get_nowait() #print(name, speed, freq) if name is not None: if name == '/red': speed_r, freq_r = speed, freq if name == '/green': speed_g, freq_g = speed, freq if name == '/blue': speed_b, freq_b = speed, freq if name == '/black_offset': black_offset_1, black_offset_2 = speed, freq if name == '/black_period': black_period_1, black_period_2 = speed, freq else: speed_r = speed_r speed_g = speed_g speed_b = speed_b freq_r = freq_r freq_g = freq_g freq_b = freq_b black_offset_1 = black_offset_1 black_offset_2 = black_offset_2 black_period_1 = black_period_1 black_period_2 = black_period_2 #print(("%.2f" % t, speed_r, freq_r)) #print(("%.2f" % t, speed_g, freq_g)) #print(("%.2f" % t, speed_b, freq_b)) pixels = [] for ii in range(n_pixels): pct = ii / n_pixels # diagonal black stripes pct_jittered = (pct * 77 ) % 77 blackstripes = color_utils.cos( pct_jittered, offset = t*black_offset_1, period = black_period_1, minn = -1.0, maxx = 2.5) blackstripes_offset = color_utils.cos( t, offset = black_offset_2, period = black_period_2, minn = -1.5, maxx = 3) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap( math.cos(( t/speed_r + pct*freq_r)*math.pi*2), -1, 1, 0, 256) g = blackstripes * color_utils.remap( math.cos(( t/speed_g + pct*freq_g)*math.pi*2), -1, 1, 0, 256) b = blackstripes * color_utils.remap( math.cos((t/speed_b + pct*freq_b)*math.pi*2), -1, 1, 0, 256) pixels.append((r, g, b)) return pixels
def mesmerize_color(t, coord, ii, n_pixels, random_value, accum): if regions[ii] == "off": return (0, 0, 0) s = color_utils.clamp(math.sin(1.8 * math.sqrt(coord[0] ** 2 + coord[1] ** 2 + 2 * (coord[2] ** 2)) - t * 6.0) * 0.75 + 0.5, 0, 1) return HSLColor(0, 0, s).convert_to('rgb').get_value_tuple()
def pixel_color(t, coord, ii, n_pixels, random_values): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple n_pixels: the total number of pixels random_values: a list containing a constant random value for each pixel Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord y += color_utils.cos(x + 0.2*z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y + z, offset=0, period=1.5, minn=0, maxx=0.2) # rotate x, y, z = y, z, x # shift some of the pixels to a new xyz location if ii % 7 == 0: x += ((ii*123)%5) / n_pixels * 32.12 y += ((ii*137)%5) / n_pixels * 22.23 z += ((ii*147)%7) / n_pixels * 44.34 # make x, y, z -> r, g, b sine waves r = color_utils.cos(x, offset=t / 4, period=2, minn=0, maxx=1) g = color_utils.cos(y, offset=t / 4, period=2, minn=0, maxx=1) b = color_utils.cos(z, offset=t / 4, period=2, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.5) # a moving wave across the pixels, usually dark. # lines up with the wave of twinkles fade = color_utils.cos(t - ii/n_pixels, offset=0, period=7, minn=0, maxx=1) ** 20 r *= fade g *= fade b *= fade # # stretched vertical smears # v = color_utils.cos(ii / n_pixels, offset=t*0.1, period = 0.07, minn=0, maxx=1) ** 5 * 0.3 # r += v # g += v # b += v # twinkle occasional LEDs twinkle_speed = 0.07 twinkle_density = 0.1 twinkle = (random_values[ii]*7 + time.time()*twinkle_speed) % 1 twinkle = abs(twinkle*2 - 1) twinkle = color_utils.remap(twinkle, 0, 1, -1/twinkle_density, 1.1) twinkle = color_utils.clamp(twinkle, -0.5, 1.1) twinkle **= 5 twinkle *= color_utils.cos(t - ii/n_pixels, offset=0, period=7, minn=0, maxx=1) ** 20 twinkle = color_utils.clamp(twinkle, -0.3, 1) r += twinkle g += twinkle b += twinkle # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (r*256, g*256, b*256)
def set_pixels(pixel_buff, pixels_per_string, elapsed_time, speed_r, speed_g, speed_b, palette, audio_level, audio_respond, colour_mash): # how many sine wave cycles are squeezed into our n_pixels # 24 happens to create nice diagonal stripes on the wall layout freq_r = 24 freq_g = 24 freq_b = 24 t = elapsed_time * 5 n_pixels = len(pixel_buff) audio_factor = 1.0 if audio_respond: audio_factor = 1.0 for ii in range(n_pixels): pct = (ii / n_pixels) # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t * 0.05, period=1, minn=-1.5, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) if audio_respond: root_lev = math.sqrt(audio_level) blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0 + root_lev / 2, 0.5 + root_lev / 2) else: blackstripes = color_utils.clamp( blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap( math.cos( (t / speed_r + pct * freq_r) * math.pi * 2), -1, 1, 0, 256) g = blackstripes * color_utils.remap( math.cos( (t / speed_g + pct * freq_g) * math.pi * 2), -1, 1, 0, 256) b = blackstripes * color_utils.remap( math.cos( (t / speed_b + pct * freq_b) * math.pi * 2), -1, 1, 0, 256) # pixel_buff[ii] = pattern_utils.fadeDownTo(pixel_buff[ii], (r, g, b), 0.5) palette_val = palette_utils.get_value(elapsed_time, ii, pixels_per_string, palette, colour_mash) r *= palette_val[0] / 255.0 g *= palette_val[1] / 255.0 b *= palette_val[2] / 255.0 pixel_buff[ii] = tuple( min(channel * audio_factor, 255) for channel in (r, g, b))
def update(self): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple n_pixels: the total number of pixels random_values: a list containing a constant random value for each pixel Returns an (r, g, b) tuple in the range 0-255 """ pixels = self.pixels coordinates = [pixel.location for pixel in pixels] n_pixels = len(pixels) blob_speed = self.params["blob_speed"].value blob_size = self.params["blob_size"].value warp_speed = self.params["warp_speed"].value color_speed = self.params["color_speed"].value #Warp speed current_time = (time.time() - self.start_time) speed = np.mean(self.fft) self.pattern_time = self.pattern_time + (warp_speed * speed + 1) * ( self.real_time - current_time) self.real_time = current_time #TODO: param for this, or swallow it with warp speed t = self.pattern_time * np.float16(0.6) r = color_utils.cos_lookup(self.x, offset=t * color_speed, period=2, minn=0, maxx=1) g = color_utils.cos_lookup(self.y, offset=t * color_speed, period=2, minn=0, maxx=1) b = color_utils.cos_lookup(self.z, offset=t * color_speed, period=2, minn=0, maxx=1) r = color_utils.contrast_np(r, 0.5, 1.5) g = color_utils.contrast_np(g, 0.5, 1.5) b = color_utils.contrast_np(b, 0.5, 1.5) # # shift the color of a few outliers # if random_values[ii] < 0.03: # r, g, b = b, g, r # black out regions r2 = color_utils.cos_lookup(self.x, offset=t * blob_speed + 12.345, period=3, minn=0, maxx=1) g2 = color_utils.cos_lookup(self.y, offset=t * blob_speed + 24.536, period=3, minn=0, maxx=1) b2 = color_utils.cos_lookup(self.z, offset=t * blob_speed + 34.675, period=3, minn=0, maxx=1) clampdown = (r2 + g2 + b2) / 2 #Only things 0.8+ get color clampdown = color_utils.remap(clampdown, 0.8, 0.9, 0, 1) clampdown = color_utils.clamp(clampdown, -blob_size, 1) r *= clampdown g *= clampdown b *= clampdown # color scheme: fade towards blue-and-orange # g = (r+b) / 2 g = g * 0.6 + ((r + b) / 2) * 0.4 # r *= 256 # g *= 256 # b *= 256 # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = ccolor_utils.gamma((r, g, b), 2.2) for i in range(len(pixels)): pixels[i].color = (r[i], g[i], b[i])
def pixel_color(t, coord, ii, n_pixels, random_values): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple n_pixels: the total number of pixels random_values: a list containing a constant random value for each pixel Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord y += color_utils.cos(x + 0.2*z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y + z, offset=0, period=1.5, minn=0, maxx=0.2) # rotate x, y, z = y, z, x # # shift some of the pixels to a new xyz location # if ii % 17 == 0: # x += ((ii*123)%5) / n_pixels * 32.12 + 0.1 # y += ((ii*137)%5) / n_pixels * 22.23 + 0.1 # z += ((ii*147)%7) / n_pixels * 44.34 + 0.1 # make x, y, z -> r, g, b sine waves r = color_utils.cos(x, offset=t / 4, period=2.5, minn=0, maxx=1) g = color_utils.cos(y, offset=t / 4, period=2.5, minn=0, maxx=1) b = color_utils.cos(z, offset=t / 4, period=2.5, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.4) clampdown = (r + g + b)/2 clampdown = color_utils.remap(clampdown, 0.4, 0.5, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) clampdown *= 0.9 r *= clampdown g *= clampdown b *= clampdown # # shift the color of a few outliers # if random_values[ii] < 0.03: # r, g, b = b, g, r # black out regions r2 = color_utils.cos(x, offset=t / 10 + 12.345, period=4, minn=0, maxx=1) g2 = color_utils.cos(y, offset=t / 10 + 24.536, period=4, minn=0, maxx=1) b2 = color_utils.cos(z, offset=t / 10 + 34.675, period=4, minn=0, maxx=1) clampdown = (r2 + g2 + b2)/2 clampdown = color_utils.remap(clampdown, 0.2, 0.3, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) r *= clampdown g *= clampdown b *= clampdown # color scheme: fade towards blue-and-orange # g = (r+b) / 2 g = g * 0.6 + ((r+b) / 2) * 0.4 # # stretched vertical smears # v = color_utils.cos(ii / n_pixels, offset=t*0.1, period = 0.07, minn=0, maxx=1) ** 5 * 0.3 # r += v # g += v # b += v # fade behind twinkle fade = color_utils.cos(t - ii/n_pixels, offset=0, period=7, minn=0, maxx=1) ** 20 fade = 1 - fade*0.2 r *= fade g *= fade b *= fade # twinkle occasional LEDs twinkle_speed = 0.07 twinkle_density = 0.1 twinkle = (random_values[ii]*7 + time.time()*twinkle_speed) % 1 twinkle = abs(twinkle*2 - 1) twinkle = color_utils.remap(twinkle, 0, 1, -1/twinkle_density, 1.1) twinkle = color_utils.clamp(twinkle, -0.5, 1.1) twinkle **= 5 twinkle *= color_utils.cos(t - ii/n_pixels, offset=0, period=7, minn=0, maxx=1) ** 20 twinkle = color_utils.clamp(twinkle, -0.3, 1) r += twinkle g += twinkle b += twinkle # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (r*256, g*256, b*256)
# how many sine wave cycles are squeezed into our n_pixels # 24 happens to create nice diagonal stripes on the wall layout freq_r = 24 freq_g = 24 freq_b = 24 # how many seconds the color sine waves take to shift through a complete cycle speed_r = 7 speed_g = -13 speed_b = 19 start_time = time.time() while True: t = (time.time() - start_time) * 5 pixels = [] for ii in range(n_pixels): pct = (ii / n_pixels) # diagonal black stripes pct_jittered = (pct * 77) % 37 blackstripes = color_utils.cos(pct_jittered, offset=t*0.05, period=1, minn=-1.5, maxx=1.5) blackstripes_offset = color_utils.cos(t, offset=0.9, period=60, minn=-0.5, maxx=3) blackstripes = color_utils.clamp(blackstripes + blackstripes_offset, 0, 1) # 3 sine waves for r, g, b which are out of sync with each other r = blackstripes * color_utils.remap(math.cos((t/speed_r + pct*freq_r)*math.pi*2), -1, 1, 0, 256) g = blackstripes * color_utils.remap(math.cos((t/speed_g + pct*freq_g)*math.pi*2), -1, 1, 0, 256) b = blackstripes * color_utils.remap(math.cos((t/speed_b + pct*freq_b)*math.pi*2), -1, 1, 0, 256) pixels.append((r, g, b)) client.put_pixels(pixels, channel=0) time.sleep(1 / fps)
def pixel_color(t, coord, ii, n_pixels, random_values): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple n_pixels: the total number of pixels random_values: a list containing a constant random value for each pixel Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord y += color_utils.cos(x + 0.2 * z, offset=0, period=1, minn=0, maxx=0.6) z += color_utils.cos(x, offset=0, period=1, minn=0, maxx=0.3) x += color_utils.cos(y + z, offset=0, period=1.5, minn=0, maxx=0.2) # rotate x, y, z = y, z, x # # shift some of the pixels to a new xyz location # if ii % 17 == 0: # x += ((ii*123)%5) / n_pixels * 32.12 + 0.1 # y += ((ii*137)%5) / n_pixels * 22.23 + 0.1 # z += ((ii*147)%7) / n_pixels * 44.34 + 0.1 # make x, y, z -> r, g, b sine waves r = color_utils.cos(x, offset=t / 4, period=2.5, minn=0, maxx=1) g = color_utils.cos(y, offset=t / 4, period=2.5, minn=0, maxx=1) b = color_utils.cos(z, offset=t / 4, period=2.5, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.4) clampdown = (r + g + b) / 2 clampdown = color_utils.remap(clampdown, 0.4, 0.5, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) clampdown *= 0.9 r *= clampdown g *= clampdown b *= clampdown # # shift the color of a few outliers # if random_values[ii] < 0.03: # r, g, b = b, g, r # black out regions r2 = color_utils.cos(x, offset=t / 10 + 12.345, period=4, minn=0, maxx=1) g2 = color_utils.cos(y, offset=t / 10 + 24.536, period=4, minn=0, maxx=1) b2 = color_utils.cos(z, offset=t / 10 + 34.675, period=4, minn=0, maxx=1) clampdown = (r2 + g2 + b2) / 2 clampdown = color_utils.remap(clampdown, 0.2, 0.3, 0, 1) clampdown = color_utils.clamp(clampdown, 0, 1) r *= clampdown g *= clampdown b *= clampdown # color scheme: fade towards blue-and-orange # g = (r+b) / 2 g = g * 0.6 + ((r + b) / 2) * 0.4 # # stretched vertical smears # v = color_utils.cos(ii / n_pixels, offset=t*0.1, period = 0.07, minn=0, maxx=1) ** 5 * 0.3 # r += v # g += v # b += v # fade behind twinkle fade = color_utils.cos(t - ii / n_pixels, offset=0, period=7, minn=0, maxx=1)**20 fade = 1 - fade * 0.2 r *= fade g *= fade b *= fade # twinkle occasional LEDs twinkle_speed = 0.07 twinkle_density = 0.1 twinkle = (random_values[ii] * 7 + time.time() * twinkle_speed) % 1 twinkle = abs(twinkle * 2 - 1) twinkle = color_utils.remap(twinkle, 0, 1, -1 / twinkle_density, 1.1) twinkle = color_utils.clamp(twinkle, -0.5, 1.1) twinkle **= 5 twinkle *= color_utils.cos(t - ii / n_pixels, offset=0, period=7, minn=0, maxx=1)**20 twinkle = color_utils.clamp(twinkle, -0.3, 1) r += twinkle g += twinkle b += twinkle # apply gamma curve # only do this on live leds, not in the simulator #r, g, b = color_utils.gamma((r, g, b), 2.2) return (r * 256, g * 256, b * 256)