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
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
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)
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)
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: 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] < 100.0: runInAnimation = True time.sleep(sleepTime)
# (could do something with hue and luminance too): for i in xrange(MAX_BULBS): hue = hsv[i][0] sat = hsv[i][1] - falloffRate lum = hsv[i][2] fun = hsv[i][3] hsv[i] = (hue,sat,lum,fun) # -------------------------------------------------------------------------- # Everything below this is strictly utilitarian (changing hsv to 10bit rgb): # -------------------------------------------------------------------------- # Convert from hsv to 10 bit rgb: for i in xrange(MAX_BULBS): hue = (hsv[i][0] %360) * 1.0 / 360.0 sat = min(100,abs(hsv[i][1])) * 1.0 / 100.0 lum = min(100,abs(hsv[i][2])) * 1.0 / 100.0 hsv01[i] = (hue,sat,lum) rgb01[i] = colorsys.hsv_to_rgb(hsv01[i][0],hsv01[i][1],hsv01[i][2]) pixOut[i] = (rgb01[i][0] *1023.0,rgb01[i][1] *1023.0,rgb01[i][2] *1023.0) out.write(pixOut) time.sleep(1.0/fps)
# 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: pix.append((0.0, 0.0, 1023.0)) out.write(pix) num += 1 time.sleep(1)
for i in xrange(MAX_BULBS): hue = hsv[i][0] - falloffRate sat = abs(40 *sin(loopCounter /fps)) + 60 lum = hsv[i][2] fun = hsv[i][3] hsv[i] = (hue,sat,lum,fun) # -------------------------------------------------------------------------- # Everything below this is strictly utilitarian (changing hsv to 10bit rgb): # -------------------------------------------------------------------------- # Convert from hsv to 10 bit rgb: for i in xrange(MAX_BULBS): hue = (hsv[i][0] %360) * 1.0 / 360.0 sat = min(100,abs(hsv[i][1])) * 1.0 / 100.0 lum = min(100,abs(hsv[i][2])) * 1.0 / 100.0 hsv01[i] = (hue,sat,lum) rgb01[i] = colorsys.hsv_to_rgb(hsv01[i][0],hsv01[i][1],hsv01[i][2]) pixOut[i] = (rgb01[i][0] *1023.0,rgb01[i][1] *1023.0,rgb01[i][2] *1023.0) out.write(pixOut) time.sleep(1.0/fps)
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) for i in xrange(24):
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) if alive == 0 or oldpix == board or twoback == board: out.write([(0.0,1023.0,0.0)] * 24) time.sleep(0.4) init() twoback = oldpix.copy() oldpix = board.copy()
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) for i in xrange(24): currentPixels[i] = pix[i]