led_count = 256 server = sys.argv[1] if len(sys.argv) > 1 else '127.0.0.1:7890' colors = { 128: (255,0,0), # red 64: (205, 140, 0), # orange 32: (255,255,0), # yellow 16: (0,255,0), # green 8: (0,0,255), # blue 4: (111, 0, 255), # "indigo" 2: (128, 0, 128), # purple 1: (255,255,255), # white } socket = opc_client.get_socket(server) while True: for x in reversed(range(8)): pixels = [(0,0,0)] * led_count bit = 2 ** x print(bit) color = colors[bit] for i in range(led_count): if i & bit: pixels[i] = color opc_client.put_pixels(socket, 0, pixels) time.sleep(3)
g = opc_client.cos(y, offset=t / 4, period=1, minn=0, maxx=0.7) b = opc_client.cos(z, offset=t / 4, period=1, minn=0, maxx=0.7) r, g, b = opc_client.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 - opc_client.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 return (r*256, g*256, b*256) #------------------------------------------------------------------------------- # send pixels print ' sending pixels forever (control-c to exit)...' print n_pixels = len(coordinates) start_time = time.time() while True: t = time.time() - start_time pixels = [pixel_color(t, coord, ii, n_pixels) for ii, coord in enumerate(coordinates)] opc_client.put_pixels(SOCK, 0, pixels) time.sleep(1 / options.fps)
#------------------------------------------------------------------------------- # connect to server print print ' connecting to server at %s' % IP_PORT print SOCK = opc_client.get_socket(IP_PORT) #------------------------------------------------------------------------------- # send pixels print ' sending pixels forever (control-c to exit)...' print n_pixels = 1250 # number of pixels in the included "wall" layout fps = 2 # frames per second (color switches every frame) while True: for c in range(4): pixels = [] rgb = [0, 0, 0] if c < 3: rgb[c % 3] = 255 rgb = tuple(rgb) for ii in range(n_pixels): pixels.append(rgb) opc_client.put_pixels(SOCK, 0, pixels) time.sleep(1 / fps)