def pixel_color(t, coord, ii, n_pixels): """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 Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord r = color_utils.cos(x, offset=t / 4, period=1, minn=0, maxx=0.7) g = color_utils.cos(y, offset=t / 4, period=1, minn=0, maxx=0.7) b = color_utils.cos(z, offset=t / 4, period=1, minn=0, maxx=0.7) r, g, b = color_utils.contrast((r, g, b), 0.5, 2) # make a moving white dot showing the order of the pixels in the layout file spark_ii = (t * 80) % n_pixels spark_rad = 8 spark_val = max( 0, (spark_rad - color_utils.mod_dist(ii, spark_ii, n_pixels)) / spark_rad) spark_val = min(1, spark_val * 2) r += spark_val g += spark_val b += spark_val # 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 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 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 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 pixel_color(t, coord, ii, n_pixels): """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 Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord r = color_utils.cos(x, offset=t / 4, period=1, minn=0, maxx=0.7) g = color_utils.cos(y, offset=t / 4, period=1, minn=0, maxx=0.7) b = color_utils.cos(z, offset=t / 4, period=1, minn=0, maxx=0.7) r, g, b = color_utils.contrast((r, g, b), 0.5, 2) # make a moving white dot showing the order of the pixels in the layout file spark_ii = (t * 80) % n_pixels spark_rad = 8 spark_val = max(0, (spark_rad - color_utils.mod_dist(ii, spark_ii, n_pixels)) / spark_rad) spark_val = min(1, spark_val * 2) r += spark_val g += spark_val b += spark_val # 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(time, coord, ii, n_pixels): """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 Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord r = color_utils.cos(z, offset=time * 0.1, period=5, minn=0, maxx=0.7) g = color_utils.cos(z, offset=time * 0.2, period=2.5, minn=0, maxx=0.7) b = color_utils.cos(x, offset=time * 0.1, period=10, minn=0, maxx=0.7) r, g, b = color_utils.contrast((r, g, b), 0.1, 2) # make a moving white dot showing the order of the pixels in the layout file spark_ii = (time*60) % n_pixels spark_rad = 10 spark_val = max(0, (spark_rad - color_utils.mod_dist(ii, spark_ii, n_pixels)) / spark_rad) spark_val = min(1, spark_val*64) #r += spark_val g += spark_val b += spark_val if ii % 10: if g > 0.3: b += spark_val else: g += spark_val else: if g < 0.3: b += spark_val r -= spark_val else: b = 0 #print ii # if ii > 60 and ii < 120: r, g, b = 100 # 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(time, coord, ii, n_pixels): """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 Returns an (r, g, b) tuple in the range 0-255 """ # make moving stripes for x, y, and z x, y, z = coord r = color_utils.cos(z, offset=time * 0.1, period=5, minn=0, maxx=0.7) g = color_utils.cos(z, offset=time * 0.2, period=2.5, minn=0, maxx=0.7) b = color_utils.cos(x, offset=time * 0.1, period=10, minn=0, maxx=0.7) r, g, b = color_utils.contrast((r, g, b), 0.1, 2) # make a moving white dot showing the order of the pixels in the layout file spark_ii = (time * 60) % n_pixels spark_rad = 10 spark_val = max( 0, (spark_rad - color_utils.mod_dist(ii, spark_ii, n_pixels)) / spark_rad) spark_val = min(1, spark_val * 64) #r += spark_val g += spark_val b += spark_val if ii % 10: if g > 0.3: b += spark_val else: g += spark_val else: if g < 0.3: b += spark_val r -= spark_val else: b = 0 #print ii # if ii > 60 and ii < 120: r, g, b = 100 # 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 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 get_pixels(self, t): pixels = [] for y in range(self.rows): for x in range(self.cols): period = 1 + color_utils.cos(t, period=4, minn=10, maxx=40) shift = color_utils.cos(x + t * 10, period=period, minn=-2, maxx=2) lvl = color_utils.cos(y + shift, period=10, minn=1, maxx=0.4) if self.pattern.get(x, y): pixels.append((255, 255, 255)) else: pixels.append((lvl * 255, 0, 0)) return pixels
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 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 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 get_pixels(self, t): pixels = [] for y in range(10): for x in range(20): period = color_utils.cos(t, period=4, minn=10, maxx=40) shift = color_utils.cos(x + t * 10, period=period, minn=-2, maxx=2) lvl = color_utils.cos(y + shift, period=10, minn=1, maxx=0.4) ii = y * 20 + x f = flow[ii] if f: pixels.append((0, 0, 0)) else: pixels.append((lvl * 255, 0, 0)) return pixels
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 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 gentle_glow(t, coord, ii, n_pixels): x, y, z = coord g = 0 b = 0 r = min(1, (1 - z) + color_utils.cos(x, offset=t / 5, period=2, minn=0, maxx=0.3)) 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 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 get_pixels(self, t): pixels = [] lvl = color_utils.cos(math.pi * t * 0.8, minn=-1, maxx=1) for y in range(self.rows): for x in range(self.cols): if self.pattern.get(x, y) == (lvl > 0): pixels.append((abs(lvl) * 256, 0, 0)) else: pixels.append((0, 0, 0)) return pixels
def get_pixels(self, t): pixels = [] lvl = color_utils.cos(math.pi * t * 0.8, minn=-1, maxx=1) for y in range(10): for x in range(20): ii = y * 20 + x f = flow[ii] if f == (lvl > 0): pixels.append((abs(lvl) * 256, 0, 0)) else: pixels.append((0, 0, 0)) 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 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 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 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 pixel_color(t, coord, ii): """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 """ x, y, z = coord # 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) # apply gamma curve # only do this on live leds, not in the simulator if live: 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 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 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 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 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 pixel_color(t, id, coord, n_pixels): """ Compute the color of a given pixel. Returns an (r, g, b) tuple in the range 0-255 """ 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) r = color_utils.cos(x, offset=t / 8, period=2.5, minn=0, maxx=1) g = color_utils.cos(y, offset=t / 8, period=2.5, minn=0, maxx=1) b = color_utils.cos(z, offset=t / 8, period=2.5, minn=0, maxx=1) r, g, b = color_utils.contrast((r, g, b), 0.5, 1.4) return (r * 256, g * 256, b * 256)
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 test_pixel_color(t, coord, ii, n_pixels, random_values, accum): return ((ii % 30) / 30.0 * 125 + color_utils.cos(t) * 130, (1 - ii / n_pixels) * 180, color_utils.cos(t * 0.1) * 255)
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 test_pixel_color(t, coord, ii, n_pixels, random_values, accum): return ((ii % 30) / 30.0 * 125 + color_utils.cos(t) * 130, (1 - ii / n_pixels) * 180, color_utils.cos(t*0.1) * 255)
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 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 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