Ejemplo n.º 1
0
def main():
    out = ColorsOut()
    pix = [(0.0, 0.0, 0.0)] * 48

    curr = 0
    r = (float)(random.randrange(lower, 1024))
    g = (float)(random.randrange(lower, 1024))
    b = (float)(random.randrange(lower, 1024))
    pix[curr] = (r, g, b)
    curr += 1
    out.write(pix)
    time.sleep(0.2)

    while True:
        while curr < 47:
            r, g, b = colorAdd(r, g, b)
            pix[curr] = (r, g, b)
            out.write(pix)
            time.sleep(0.2)
            curr += 1
        while curr > 0:
            r, g, b = colorAdd(r, g, b)
            pix[curr] = (r, g, b)
            out.write(pix)
            time.sleep(0.2)
            curr -= 1
Ejemplo n.º 2
0
def main():
    out = ColorsOut()
    pix = [(0.0,0.0,0.0)]*48

    curr = 0
    r = (float)(random.randrange(lower, 1024))
    g = (float)(random.randrange(lower, 1024))
    b = (float)(random.randrange(lower, 1024))
    pix[curr] = (r, g, b)
    curr += 1
    out.write(pix)
    time.sleep(0.2)

    while True:
        while curr < 47:
            r, g, b = colorAdd(r, g, b)
            pix[curr] = (r, g, b)
            out.write(pix)
            time.sleep(0.2)
            curr += 1
        while curr > 0:
            r, g, b = colorAdd(r, g, b)
            pix[curr] = (r, g, b)
            out.write(pix)
            time.sleep(0.2)
            curr -= 1
Ejemplo n.º 3
0
class FadeAnimation(threading.Thread):
    curcolors = [(0.0,0.0,0.0)]*24
    targetcolors= [(0.0,0.0,0.0)]*24
    FADEINRATE = 3.0
    FADEOUTRATE = 3.0
    FRAMERATE = 30.0
    dorun = True

    def __init__(self):
        threading.Thread.__init__(self)
        self.out = ColorsOut()

    def write(self, pixels):
        self.targetcolors = pixels[:]

    def run(self):
        while self.dorun:
            self.curcolors = self.animate(self.curcolors, self.targetcolors)
            self.out.write(self.curcolors)
            time.sleep(1.0/self.FRAMERATE)

    def animate(self, pixels, pixelsmod):
        for index,pixel in enumerate(pixelsmod):
            pixels[index] = self.animatePixel(pixels[index], pixel)
        #pixels = pixelsmod[:]
        return pixels 

    def animatePixel(self,pixel, pixelmod):
        (r,g,b) = pixel
        (s,t,q) = pixelmod
        rdiff = (s-r)/(self.FADEINRATE if s-r > 0 else self.FADEOUTRATE)
        r = r + rdiff 
        gdiff = (t-g)/(self.FADEINRATE if t-g > 0 else self.FADEOUTRATE)
        g = g + gdiff 
        bdiff = (q-b)/(self.FADEINRATE if q-b > 0 else self.FADEOUTRATE)
        b = b + bdiff
        return (r,g,b)
Ejemplo n.º 4
0
class FadeAnimation(threading.Thread):
    curcolors = [(0.0, 0.0, 0.0)] * 48
    targetcolors = [(0.0, 0.0, 0.0)] * 48
    FADEINRATE = 3.0
    FADEOUTRATE = 3.0
    FRAMERATE = 30.0
    dorun = True

    def __init__(self):
        threading.Thread.__init__(self)
        self.out = ColorsOut()

    def write(self, pixels):
        self.targetcolors = pixels[:]

    def run(self):
        while self.dorun:
            self.curcolors = self.animate(self.curcolors, self.targetcolors)
            self.out.write(self.curcolors)
            time.sleep(1.0 / self.FRAMERATE)

    def animate(self, pixels, pixelsmod):
        for index, pixel in enumerate(pixelsmod):
            pixels[index] = self.animatePixel(pixels[index], pixel)
        #pixels = pixelsmod[:]
        return pixels

    def animatePixel(self, pixel, pixelmod):
        (r, g, b) = pixel
        (s, t, q) = pixelmod
        rdiff = (s - r) / (self.FADEINRATE if s - r > 0 else self.FADEOUTRATE)
        r = r + rdiff
        gdiff = (t - g) / (self.FADEINRATE if t - g > 0 else self.FADEOUTRATE)
        g = g + gdiff
        bdiff = (q - b) / (self.FADEINRATE if q - b > 0 else self.FADEOUTRATE)
        b = b + bdiff
        return (r, g, b)
Ejemplo n.º 5
0
import sys, random
from oscapi import ColorsOut

falloffRate = 7.0

#author: Robert Pieta
if __name__ == "__main__":
    import time
    out = ColorsOut()
    pix = [(0.0,0.0,0.0)] * 24
    runInAnimation = True
    smoothnessRatio = 200
    sleepTime = .01
    while True:
        # Make some rain
        #    if random.randint(0,5) < 3:
        #   pix[random.randint(0,23)] = (random.randint(0,1023.0),random.randint(0,1023.0),random.randint(0,1023.0))
        #out.write(pix)
        #for i in xrange(24):
        #   if pix[i][2] > 0.0:
        #       pix[i] = (pix[i][0] - falloffRate, pix[i][1] - falloffRate,pix[i][2] - falloffRate)
        #else:
        #       pix[i] = (0.0,0.0,0.0)
        if runInAnimation:
            for i in xrange(12):
                pix[random.randint(0,23)] = (pix[i][0] + 1023/smoothnessRatio, 0.0, 0.0)
            out.write(pix)
            if pix[i][0] > 900:
                    runInAnimation = False
            time.sleep(sleepTime)
        else:
Ejemplo n.º 6
0
import colorsys
from math import floor
sys.path.append("./osc")
from oscapi import ColorsOut
from animations import FadeAnimation

MAX_BULBS = 24

fps = 60.0

# numerical rate is in % points/second
falloffRate = 15.0 /fps

if __name__ == "__main__":
    # writing pixel values every time:
    out = ColorsOut()
    
    # yeah I know it's an inefficient use of space, but hey, it's constant space!
    hsv    = [(0.0,0.0,0.0,0.0)] * MAX_BULBS
    # because hsv_to_rgb takes values scaled from 0-1
    hsv01  = [(0.0,0.0,0.0)] * MAX_BULBS
    # because hsv_to_rgb returns values scaled from 0-1
    rgb01  = [(0.0,0.0,0.0)] * MAX_BULBS
    # because ColorsOut() is of course, 10-bit rgb
    pixOut = [(0.0,0.0,0.0)] * MAX_BULBS
    
    loopCounter = 0
    # main loop:
    while True:
        loopCounter += 1
        # using Kevin's "raindrop" algorithm:
Ejemplo n.º 7
0
    # 1001
    # 1111
    numbers.append([[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1],
                    [1, 1, 1, 1]])
    # 1111
    # 1001
    # 1111
    # 0001
    # 0001
    numbers.append([[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [0, 0, 0, 1],
                    [0, 0, 0, 1]])


if __name__ == "__main__":
    import time
    out = ColorsOut()
    init()
    num = 0
    while True:
        pix = []
        output = []
        if num == len(numbers):
            num = 0
        for i in numbers[num]:
            output.insert(0, i)
        output.append([0, 0, 0, 0])
        for i in output:
            for j in i:
                if j:
                    pix.append((1023.0, 0.0, 0.0))
                else:
Ejemplo n.º 8
0
import sys, random, scripts, select, simplejson
from socket import *
sys.path.append("./osc")
from oscapi import ColorsOut

HOST = ''    
PORT = 8012    
ADDR = (HOST,PORT)    
BUFSIZE = 4096     


#author: Robert Pieta
if __name__ == "__main__":
    import time
    sleepTime = 0.05
    out = ColorsOut()
    pix = [(0.0,0.0,0.0)] * 24
    currentPixels = [(0.0,0.0,0.0)] * 24
    timeout = 1.0
    out.write(pix)
    
    serv = socket( AF_INET,SOCK_STREAM)    
    serv.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    
    
    serv.bind((ADDR))
    serv.listen(5)   
    print 'listening...'
    
    conn,addr = serv.accept()
    print '...connected!'
Ejemplo n.º 9
0
def init():
    for i in range(-3,10):
        for j in range(-3,10):
            if random.random() < 0.5:
                board[(i,j)] = 1
            else:
                board[(i,j)] = 0


if __name__ == "__main__":
    import time

    init()

    out = ColorsOut()
    twoback = {}
    oldpix = {}
    while True:
        pix = []
        alive = 0
        for i in xrange(6):
            for j in xrange(4):
                if board[(i,j)] > 0:
                    pix.append((1023.0,0.0,0.0))
                    alive += 1
                else:
                    pix.append((0.0,0.0,1023.0))
        out.write(pix)
        update()
        time.sleep(0.2)
Ejemplo n.º 10
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.out = ColorsOut()
Ejemplo n.º 11
0
import sys, random, scripts, select, simplejson
from socket import *
sys.path.append("./osc")
from oscapi import ColorsOut

HOST = ''
PORT = 8012
ADDR = (HOST, PORT)
BUFSIZE = 4096

#author: Robert Pieta
if __name__ == "__main__":
    import time
    sleepTime = 0.05
    out = ColorsOut()
    pix = [(0.0, 0.0, 0.0)] * 24
    currentPixels = [(0.0, 0.0, 0.0)] * 24
    timeout = 1.0
    out.write(pix)

    serv = socket(AF_INET, SOCK_STREAM)
    serv.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

    serv.bind((ADDR))
    serv.listen(5)
    print 'listening...'

    conn, addr = serv.accept()
    print '...connected!'

    pix = scripts.showSuccessfulConnection(pix)
Ejemplo n.º 12
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.out = ColorsOut()