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 get_pixels(self, t): pixels = [] flow_color = None for y in range(10): for x in range(20): ii = y * 20 + x pct = ii / self.n_pixels # diagonal black stripes pct_jittered = (pct * 77) % 37 dist = math.sqrt((x - 10) * (x - 10) + (y - 5) * (y - 5)) # 3 sine waves for r, g, b which are out of sync with each other r = color_utils.remap( math.cos( (t / speed_r + 1.0 * dist * freq_r) * math.pi * 2), -1, 1, 10, 256) g = color_utils.remap( math.cos( (t / speed_g + 1.0 * dist * freq_g) * math.pi * 2), -1, 1, 10, 256) b = color_utils.remap( math.cos( (t / speed_b + 1.0 * dist * freq_b) * math.pi * 2), -1, 1, 10, 256) if flow[ii]: if flow_color is None: flow_color = (r, 0, 0) if flow_color[0] > 0.9 * g: pixels.append(flow_color) else: pixels.append((0.9 * g, 0.6 * g, 0)) else: pixels.append((0.9 * g, 0.6 * g, 0)) return pixels
def get_pixels(self, t): pixels = [] flow_color = None hc = self.cols / 2 hr = self.rows / 2 for y in range(self.rows): for x in range(self.cols): dist = math.sqrt((x - hc) * (x - hc) + (y - hr) * (y - hr)) # 3 sine waves for r, g, b which are out of sync with each other r = color_utils.remap( math.cos( (t / speed_r + 1.0 * dist * freq_r) * math.pi * 2), -1, 1, 10, 256) g = color_utils.remap( math.cos( (t / speed_g + 1.0 * dist * freq_g) * math.pi * 2), -1, 1, 10, 256) b = color_utils.remap( math.cos( (t / speed_b + 1.0 * dist * freq_b) * math.pi * 2), -1, 1, 10, 256) if self.pattern.get(x, y): if flow_color is None: flow_color = (r, 0, 0) if flow_color[0] > 0.9 * g: pixels.append(flow_color) else: pixels.append((0.9 * g, 0.6 * g, 0)) else: pixels.append((0.9 * g, 0.6 * g, 0)) return pixels
def moons_and_planets_blink( R_min, R_max, fps=100, in_aniIndex=5): #alternate blinking moons and planets global aniIndex, client, coordinates print("moons_and_planets_blink") while (aniIndex == in_aniIndex): pixels = [] t = time.time() for coord in coordinates: R = radius(coord) x, y, z = coord theta = find_theta(coord) R = color_utils.remap(R, R_min, R_max, 0, 6) if 2.5 < R < 5.5: # planets r = color_utils.cos(t, offset=1, period=10, minn=10, maxx=100) g = color_utils.cos(t, offset=1, period=10, minn=10, maxx=100) b = color_utils.cos(t, offset=1, period=10, minn=10, maxx=150) r, g, b = [ color_utils.remap(color, 0, 255, 0, 1) for color in (r, g, b) ] r, g, b = color_utils.gamma((r, g, b), 0.8) r, g, b = [ color_utils.remap(color, 0, 1, 0, 255) for color in (r, g, b) ] elif R > 5.5 or R < 2.5: r = color_utils.cos(t, offset=0.5, period=10, minn=0, maxx=0.6) g = 0.2 b = color_utils.cos(t, offset=0.5, period=10, minn=0.3, maxx=0.45) r_pattern = color_utils.cos(theta, offset=t / 5, period=10, minn=0, maxx=1) # r,g,b = [r_pattern*item for item in (r,g,b)] ###uncomment this line to add the spiral effect r, g, b = [ color_utils.remap(color, 0, 1, 0, 255) for color in (r, g, b) ] pixels.append((r, g, b)) #send to HW for ii in range(len(pixels)): all_nodes.setNodeColor(int(ii), int(pixels[ii][0]), int(pixels[ii][1]), int(pixels[ii][2])) #Send to sim if (run_sim == True): client.put_pixels(pixels) time.sleep(1 / fps)
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 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 moons_spiral( R_min, R_max, in_aniIndex=8, fps=100 ): ##this has the effect of just the outward moon spiraling slowly global aniIndex, client, coordinates print("moons_spiral") while (aniIndex == in_aniIndex): pixels = [] t = time.time() for coord in coordinates: R = radius(coord) x, y, z = coord theta = find_theta(coord) R = color_utils.remap(R, R_min, R_max, 0, 6) if R > 5.5: r = color_utils.cos(theta, offset=t / 10, period=12, minn=0, maxx=1) g = color_utils.cos(theta, offset=t / 10, period=12, minn=0, maxx=1) b = color_utils.cos(theta, offset=t / 10, period=12, minn=0, maxx=1) r, g, b = [ color_utils.remap(color, 0, 1, 0, 255) for color in (r, g, b) ] else: r, g, b = (20, 20, 10) pixels.append((r, g, b)) #send to HW for ii in range(len(pixels)): all_nodes.setNodeColor(int(ii), int(pixels[ii][0]), int(pixels[ii][1]), int(pixels[ii][2])) #Send to sim if (run_sim == True): client.put_pixels(pixels)
def outward_swell(fps=100, in_aniIndex=0): global aniIndex, client, coordinates print("outward_swell") while (aniIndex == in_aniIndex): pixels = [] t = time.time() for coord in coordinates: R = radius(coord) g = 0.2 b = color_utils.cos(R, offset=t / 8, period=10, minn=0.3, maxx=0.45) r = color_utils.cos(R, offset=t / 8, period=10, minn=0, maxx=0.50) r, g, b = color_utils.gamma((r, g, b), 0.7) r, g, b = [ color_utils.remap(color, 0, 1, 0, 255) for color in (r, g, b) ] pixels.append((r, g, b)) #send to HW for ii in range(len(pixels)): all_nodes.setNodeColor(int(ii), int(pixels[ii][0]), int(pixels[ii][1]), int(pixels[ii][2])) #Send to sim if (run_sim == True): client.put_pixels(pixels) time.sleep(1 / fps)
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 rainbow_wave(in_aniIndex=6, fps=100): global aniIndex, client, coordinates print("rainbow_wave") while (aniIndex == in_aniIndex): pixels = [] t = time.time() for coord in coordinates: x = coord[0] y = coord[1] z = coord[2] r = color_utils.cos(x, offset=t / 8, period=10, minn=0, maxx=0.8) g = color_utils.cos(y, offset=t / 8, period=10, minn=0, maxx=0.8) b = color_utils.cos(z, offset=t / 8, period=10, minn=0, maxx=0.8) r, g, b = [ color_utils.remap(color, 0, 1, 0, 255) for color in (r, g, b) ] pixels.append((r, g, b)) #send to HW for ii in range(len(pixels)): all_nodes.setNodeColor(int(ii), int(pixels[ii][0]), int(pixels[ii][1]), int(pixels[ii][2])) #Send to sim if (run_sim == True): client.put_pixels(pixels) time.sleep(1 / fps)
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 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 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 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 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_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 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 y in range(10): for x in range(20): ii = y * 20 + x pct = ii / self.n_pixels # diagonal black stripes pct_jittered = (pct * 77) % 37 dist = math.sqrt((x - 10) * (x - 10) + (y - 5) * (y - 5)) # 3 sine waves for r, g, b which are out of sync with each other r = color_utils.remap(math.cos((t/speed_r + 1.0*dist*freq_r)*math.pi*2), -1, 1, 10, 256) g = color_utils.remap(math.cos((t/speed_g + 1.0*dist*freq_g)*math.pi*2), -1, 1, 10, 256) b = color_utils.remap(math.cos((t/speed_b + 1.0*dist*freq_b)*math.pi*2), -1, 1, 10, 256) if flow[ii]: if flow_color is None: flow_color = (r, 0, 0) if flow_color[0] > 0.9 * g: pixels.append(flow_color) else: pixels.append((0.9 * g, 0.6 * g, 0)) else: pixels.append((0.9 * g, 0.6 * g, 0)) 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 get_pixels(self, t): pixels = [] flow_color = None hc = self.cols / 2 hr = self.rows / 2 for y in range(self.rows): for x in range(self.cols): dist = math.sqrt((x - hc) * (x - hc) + (y - hr) * (y - hr)) # 3 sine waves for r, g, b which are out of sync with each other r = color_utils.remap(math.cos((t/speed_r + 1.0*dist*freq_r)*math.pi*2), -1, 1, 10, 256) g = color_utils.remap(math.cos((t/speed_g + 1.0*dist*freq_g)*math.pi*2), -1, 1, 10, 256) b = color_utils.remap(math.cos((t/speed_b + 1.0*dist*freq_b)*math.pi*2), -1, 1, 10, 256) if self.pattern.get(x, y): if flow_color is None: flow_color = (r, 0, 0) if flow_color[0] > 0.9 * g: pixels.append(flow_color) else: pixels.append((0.9 * g, 0.6 * g, 0)) else: pixels.append((0.9 * g, 0.6 * g, 0)) 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 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 white_blinking(in_aniIndex=7, fps=100): global aniIndex, client, coordinates print("white_blinking") while (aniIndex == in_aniIndex): pixels = [] t = time.time() for coord in coordinates: x, y, z = coord x = x + 0.1 # if t - start_time > interval / 2: # x_new=y # y_new=x # y=y_new # x=x_new r = color_utils.cos(x / y + y / z, offset=t / 10, period=6, minn=0, maxx=0.4) g = color_utils.cos(x / y + y / z, offset=t / 10, period=6, minn=0, maxx=0.4) b = color_utils.cos(x / y + y / z, offset=t / 10, period=6, minn=0, maxx=0.4) color = (r, g, b) r, g, b = color_utils.gamma(color, 0.5) r, g, b = [ color_utils.remap(color, 0, 1, 0, 255) for color in (r, g, b) ] pixels.append((r, g, b)) #send to HW for ii in range(len(pixels)): all_nodes.setNodeColor(int(ii), int(pixels[ii][0]), int(pixels[ii][1]), int(pixels[ii][2])) #Send to sim if (run_sim == True): client.put_pixels(pixels) 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 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 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 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 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 color_stripe(params): return blackstripes * color_utils.remap( math.cos(( frame_time/params[0] + pct*params[1])*math.pi*2), -1, 1, 0, 255)
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)
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 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)
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 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)
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))
# 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 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])