Created
November 12, 2012 07:47
-
-
Save cagerton/4058037 to your computer and use it in GitHub Desktop.
Color fade test for PixelPusher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
from math import pi, sin | |
UDP_IP = '192.168.2.2' | |
UDP_PORT = 9897 | |
def Push(messages): | |
"""Stolen from: https://github.com/robot-head/PixelPusher-python""" | |
assert type(messages) == list | |
for message in messages: | |
#print message | |
message = "".join(map(chr, message)) | |
sock = socket.socket( | |
socket.AF_INET, # Internet | |
socket.SOCK_DGRAM) # UDP | |
bytes_sent = sock.sendto(message, (UDP_IP, UDP_PORT)) | |
def oscillator(freq, phaseStart, t): | |
return sin(2*pi*freq*t + phaseStart); | |
def rgb_osc(freq=0.5, off=0, scale=lambda x: x): | |
while True: | |
t = time.time() | |
yield [scale(oscillator(freq, phase+off, t)) for phase in (0,2*pi/3,4*pi/3)] | |
def sine_fade_test(on_pixels=20, off_pixels=30, freq=0.3): | |
scale_fx = lambda x: int(255 * (x+1) / 2) | |
oscs = [rgb_osc(off=(idx * (2*pi/on_pixels)), scale=scale_fx, freq=freq) for idx in xrange(on_pixels)] | |
off_pixels_values = [0,0,0] * off_pixels | |
while True: | |
active = [ color_value for osc in oscs for color_value in osc.next()] | |
Push([[0] + active + off_pixels_values]) | |
time.sleep(1.0/50) | |
if __name__ == '__main__': | |
sine_fade_test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment