def test2(count): print( "*** test2 ***" ) lenx = 7 leny = 21 strip2D = Strip2D(lenx, leny) strip = strip2D.strip while count > 0: strip2D.strip.clear([255, 255, 255]) for y in range(leny): strip2D.set(0, y, [255, 0, 0]) strip.artnet.send(strip2D.strip) for _i in range(30): time.sleep(0.1) strip2D.rotl() strip.artnet.send(strip2D.strip) for _i in range(30): time.sleep(0.1) strip2D.rotr() strip.artnet.send(strip2D.strip) strip2D.strip.clear([255, 255, 255]) for x in range(lenx): strip2D.set(x, 0, [255, 0, 0]) strip.artnet.send(strip2D.strip) for _i in range(40): time.sleep(0.1) strip2D.rotu() strip.artnet.send(strip2D.strip) for _i in range(40): time.sleep(0.1) strip2D.rotd() strip.artnet.send(strip2D.strip) count -= 1 strip2D.strip.clear([255, 255, 255]) for x in range(lenx): strip2D.set(x, 0, [255, 0, 0]) strip.artnet.send(strip2D.strip) for y in range(leny): strip2D.set(0, y, [255, 0, 0]) strip.artnet.send(strip2D.strip) for _i in range(40): time.sleep(0.1) strip2D.rotu() strip2D.rotr() strip.artnet.send(strip2D.strip) count -= 1 strip.artnet.close()
def test5(count): print( "*** test5 ***" ) lenx = 7 leny = 21 strip2D = Strip2D(lenx, leny) global strip strip = strip2D.strip strip2D.pattern([ \ [255, 0, 0], [255, 96, 0], [255, 255, 0], \ [0, 255, 0], [0, 255, 255], \ [0, 0, 255], [255, 0, 255] \ ], 0) strip.artnet.send(strip) while count > 0: time.sleep(0.1) strip2D.rotr() strip.artnet.send(strip2D.strip) count -= 1 strip.artnet.close()
def test3(count): print( "*** test3 ***" ) lenx = 7 leny = 21 strip2D = Strip2D(lenx, leny) strip = strip2D.strip #strip2D.strip.clear([0, 0, 0]) #for y in range(leny): # strip2D.set(0, y, [255, 0, 0]) strip2D.strip.clear([255, 255, 255]) for y in range(leny): strip2D.set(y % lenx, y, [255, 0, 0]) strip2D.set((y + 1) % lenx, y, [255, 0, 0]) strip2D.set((y + 5) % lenx, y, [0, 0, 255]) strip2D.set((y + 6) % lenx, y, [0, 0, 255]) strip.artnet.send(strip2D.strip) while count > 0: for _i in range(30): time.sleep(0.1) strip2D.rotl() strip.artnet.send(strip2D.strip) for _i in range(30): time.sleep(0.1) strip2D.rotr() strip.artnet.send(strip2D.strip) for _i in range(30): time.sleep(0.1) strip2D.rotu() strip.artnet.send(strip2D.strip) for _i in range(30): time.sleep(0.1) strip2D.rotd() strip.artnet.send(strip2D.strip) count -= 1 strip.artnet.close()
self.strip2D.strip.clear([255, 255, 255]) for x in range(self.strip2D.lenx): self.strip2D.set(x, 0, [255, 0, 0]) self.strip2D.set(x, 1, [255, 0, 0]) self.strip2D.set(x, 2, [255, 0, 0]) for y in range(self.strip2D.leny): self.strip2D.set(0, y, [255, 0, 0]) self.strip2D.send() now = time.time() while (not self.quit) and ((time.time() - now) < runtime): for _i in range(18): time.sleep(0.1) self.strip2D.rotu() self.strip2D.rotr() self.strip2D.send() for _i in range(18): time.sleep(0.1) self.strip2D.rotd() self.strip2D.rotl() self.strip2D.send() self.quit = False if __name__ == "__main__": e = Bump1(Strip2D(7, 21)) e.run()
self.quit = True print("cleanup") #client.unsubscribe( "home/groundfloor/entrance/hallway/stat/POWER3" ) #client.unsubscribe( "cmnd/mancave-melder/POWER1" ) #client.unsubscribe( "cmnd/steeg-melder/POWER1" ) #client.disconnect() #client.loop_stop() termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags) self.quit = True """ ./eyes.py [pairs [distance]] addr=192.168.1.255 ./eyes.py [pairs [distance] 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./eyes.py [pairs [distance] 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": pairs = 5 distance = 2 if len(sys.argv) >= 2: pairs = int(sys.argv[1]) if len(sys.argv) >= 3: distance = int(sys.argv[2]) e = Eyes(Strip2D(10, 10), pairs, distance) e.run()
m = 129 - (count // 50) % 7 a = -1 if self.strip2D.strip.get(m - 0) == self.colors[1]: a = 180 self.strip2D.strip.set(m - 0, self.gold, a) a = -1 if self.strip2D.strip.get(m - 13) == self.colors[1]: a = 180 self.strip2D.strip.set(m - 13, self.gold, a) a = -1 if self.strip2D.strip.get(m - 20) == self.colors[1]: a = 180 self.strip2D.strip.set(m - 20, self.gold, a) a = -1 if self.strip2D.strip.get(m - 27) == self.colors[1]: a = 180 self.strip2D.strip.set(m - 27, self.gold, a) a = -1 if self.strip2D.strip.get(m - 28) == self.colors[1]: a = 180 self.strip2D.strip.set(m - 28, self.gold, a) def setColors(self, colors): self.colors = colors if __name__ == "__main__": e = Night(Strip2D(7, 21)) e.run()
intx = int(self.x) inty = int(self.y) self.intoarray(intx, inty, self.rgb) # Reset if particle is done if (self.fire.strip2D.leny - self.y) > life or self.y > self.fire.strip2D.leny: if alive: x = random.randint(0, self.fire.strip2D.lenx - 1) self.__init__(self.fire, x, self.fire.strip2D.leny) else: self.rgb = (0, 0, 0) def intoarray(self, x, y, rgb): self.fire.rdata[y * self.fire.strip2D.lenx + x] = rgb[0] self.fire.gdata[y * self.fire.strip2D.lenx + x] = rgb[1] self.fire.bdata[y * self.fire.strip2D.lenx + x] = rgb[2] """ ./fire.py addr=192.168.1.255 ./fire.py 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./fire.py 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": e = Fire2(Strip2D(7, 21)) e.run()
self.strip2D.send() time.sleep(.5) for i in range(100): self.index = random.randint(0, 149) self.draw(self.index, [255, 255, 255]) #self.strip2D.strip.set(self.index, [255, 255, 255]) self.strip2D.send() time.sleep(.05) for j in range(5): self.draw(self.index, [255, 255 / (7 - j), 255 / (7 - j)]) #self.strip2D.strip.set(self.index, [255, 255 / (7 - j), 255 / (7 - j)]) self.strip2D.send() time.sleep(.02) self.draw(self.index, [255, 0, 0]) #self.strip2D.strip.set(self.index, [255, 0, 0]) self.strip2D.send() def draw(self, index, color): self.strip2D.strip.set(index, color) self.strip2D.strip.set(index + 1, color) self.strip2D.strip.set(index + 7, color) self.strip2D.strip.set(index + 8, color) if __name__ == "__main__": e = Weird3(Strip2D(7, 21)) e.run()
self.rgb = (255, self.rgb[1] - int(self.rnderp + 30), 0) else: if self.rgb[0] > self.rnderp + 5: self.rgb = (self.rgb[0] - int(self.rnderp + 1), self.rgb[1], 0) self.y -= self.speed intx = int(self.x) inty = int(self.y) self.intoarray(intx, inty, self.rgb) if self.y < self.life or self.y < 0.5: self.__init__(self.fire, self.x, self.fire.strip2D.leny) def intoarray(self, x, y, rgb): self.fire.rdata[y * 7 + x] = rgb[0] self.fire.gdata[y * 7 + x] = rgb[1] self.fire.bdata[y * 7 + x] = rgb[2] """ ./fire.py addr=192.168.1.255 ./fire.py 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./fire.py 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": e = Fire(Strip2D(7, 21)) e.run()
b = getColorValue2(count - period23) #[r, g, b] = getColorValue3(count) return [r, g, b] class Weird2(Effect): def __init__(self, strip2D): super(Weird2, self).__init__(strip2D) self.strip2D.strip.clear() self.strip2D.send() def step(self, count): #if count % 8 != 0: # return for i in range(11): #c = rainbow((count - i) % period) c = rainbow(count) for x in range(7): self.strip2D.set(x, 10 + i, c) self.strip2D.set(x, 10 - i, c) self.strip2D.coneFade(10) #self.strip2D.fade(.5) self.strip2D.send() if __name__ == "__main__": e = Weird2(Strip2D(7, 21)) e.run()
def step(self, count): if self.bgSpeedCount <= 0: (self.bg1, self.bg2) = (self.bg2, self.bg1) self.bgSpeedCount = self.bgSpeed else: self.bgSpeedCount -= 1 if self.fgSpeedCount <= 0: self.fgCount += 1 if self.fgCount > 10: self.fgCount = 0 self.fgSpeedCount = self.fgSpeed else: self.fgSpeedCount -= 1 for y in range(21): for x in range(7): if y % 2 == 0: self.strip2D.set(x, y, self.bg1) else: self.strip2D.set(x, y, self.bg2) for x in range(7): self.strip2D.set(x, 10 + self.fgCount, self.fg) self.strip2D.set(x, 10 - self.fgCount, self.fg) if __name__ == "__main__": e = Weird1(Strip2D(7, 21)) e.run()
if count < 1024: count -= 768 return [0, 255, count] if count < 1280: count -= 1024 return [0, 255 - count, 255] if count < 1536: count -= 1280 return [count, 0, 255] def color2(self, count): if count < 256: count -= 0 return [count, count / 2, 0] if count < 512: count -= 256 return [255, (255 + 2 * count) / 3, count] if count < 768: count = 767 - count return [count, count, count] """ ./plasma.py 'addr=[("localhost", 7000)]' """ if __name__ == "__main__": e = Plasma(Strip2D(7, 21)) e.run()
if runtime is None: if hasattr(sys, "maxint"): # Python 2 runtime = sys.maxint elif hasattr(sys, "maxsize"): # Python 3 runtime = sys.maxsize count2 = 0 now = time.time() while (not self.quit) and ((time.time() - now) < runtime): for _i in range(self.strip2D.lenx): c = self.color(count2) self.strip2D.strip.clear(c) self.strip2D.send() time.sleep(0.05) count2 += 3 count2 = count2 % 100 self.quit = False """ ./cmorph.py addr=192.168.1.255 ./cmorph.py 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./cmorph.py 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": if len(sys.argv) >= 2: select = int(sys.argv[1]) e = CMorph(Strip2D(7, 21)) e.run()
runtime = sys.maxint elif hasattr(sys, "maxsize"): # Python 3 runtime = sys.maxsize now = time.time() while (not self.quit) and ((time.time() - now) < runtime): for _i in range(self.strip2D.lenx): c = self.color(count2) self.strip2D.strip.clear(c) self.strip2D.send() time.sleep(0.03) count2 += 30 count2 = count2 % 768 self.quit = False """ ./police.py [1|2|3] addr=192.168.1.255 ./police.py [1|2|3] 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./police.py [1|2|3] 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": if len(sys.argv) >= 2 and sys.argv[1] == "2": e = Police2(Strip2D(7, 21)) elif len(sys.argv) >= 2 and sys.argv[1] == "3": e = Police3(Strip2D(7, 21)) else: e = Police1(Strip2D(7, 21)) e.run()
], 0) """ self.strip2D.pattern([ \ [255, 0, 0], [255, 102, 0], [255, 255, 0], [0, 255, 0], [0, 0, 255], [128, 0, 255], #[72, 0, 130], [255, 0, 255], #[134, 0, 255], ], 0) self.strip2D.send() now = time.time() while (not self.quit) and ((time.time() - now) < runtime): time.sleep(0.1) self.strip2D.rotr() self.strip2D.send() self.quit = False """ ./rainbow.py addr=192.168.1.255 ./rainbow.py 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./rainbow.py 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": e = Rainbow(Strip2D(7, 21)) e.run()
for y in range(h): line = sprite[y] w = len(line) for x in range(w): c = line[x] xx = x + count if (c > 0) and (xx >= start) and (xx < end): yy = h - 1 - y self.strip2D.strip.set( \ xx + yy * self.strip2D.lenx, self.palette[c - 1]) if True: # pylint: disable=using-constant-test count += self.step[i] if count > 70: count = start - self.strip2D.lenx else: count = 30 self.strip2D.send() time.sleep(0.15) self.quit = False """ ./lemmings.py 'addr=[("localhost", 7000)]' """ if __name__ == "__main__": e = Lemmings1(Strip2D(7, 21)) e.run()
while (not self.quit) and ((time.time() - now) < runtime): time.sleep(0.1) for y in range(self.strip2D.leny): for x in range(self.strip2D.lenx): renderedcolor = screen.get_at((x + offset, y))[0:3] self.strip2D.set(x + 1, self.strip2D.leny - y, renderedcolor) #self.strip2D.set(x, 2 * y + 1, color ) offset += 1 if offset > screen.get_width() - 7: offset = 0 self.strip2D.send() self.quit = False """ ./marquee.py "Hello world" addr=192.168.1.255 ./marquee.py "Hello world" 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./marquee.py "Hello world" 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": print(sys.argv) e = Marquee(Strip2D(7, 21)) if len(sys.argv) > 2: e.text = sys.argv[1] e.run()
p = Particle(self, level) p.y = random.randint(0, 20) self.particles[level].append(p) def step(self, count): self.strip2D.strip.clear([0, self.bgcolor, 0]) for level, particles in enumerate(self.numParticles): for i in range(particles): p = self.particles[level][i] if p.y <= -p.len: p = Particle(self, level) self.particles[level][i] = p if p.speedCount <= 0: p.y -= 1 p.speedCount = p.speed else: p.speedCount -= 1 for y in range(p.len): c = ((4 * p.len - 3 * y) * self.colors[p.color]) / (4 * p.len) #cc = self.strip2D.get(p.x, p.y + y)[1] #if cc > c: # c = cc self.strip2D.set(p.x, p.y + y, [0, c, 0]) if __name__ == "__main__": e = Matrix(Strip2D(7, 21)) e.run()
stars = [] numStars = 20 life = 30 color = Color() def __init__(self, strip2D): super(Stars3, self).__init__(strip2D) self.stars = [[random.randint(0, 6), random.randint(0, 20), \ random.randint(0, self.life)] for i in range(self.numStars)] self.strip2D.strip.clear() def step(self, count): if (count % 4) != 0: return self.strip2D.strip.clear([0, 0, 2]) for _i, stars in enumerate(self.stars): if stars[2] <= 0: stars = [random.randint(0, 6), random.randint(0, 20) \ , self.life / 2] s = stars else: s = stars s[2] -= 1 self.strip2D.set(s[0], s[1], self.color.colorFade( \ float(s[2]) / float(self.life))) if __name__ == "__main__": e = Stars3(Strip2D(7, 21)) e.run()
self.initcnt *= 3 # drop next one if (len(self.top) > 0) and (count % 9 == 0): p = self.top.pop() p[1] = 20 - (self.numlayer - 1 - p[1]) self.active.insert(0, p) for i in reversed(range(len(self.active))): self.active[i][2] += 1 if self.active[i][2] >= self.active[i][1]: p = self.active.pop(i) self.bottom.append(p) for i, top in enumerate(self.top): self.strip2D.set(top[0], 20 - top[2], self.colors[1]) for i, bottom in enumerate(self.bottom): self.strip2D.set(bottom[0], 20 - bottom[2], self.colors[1]) for i, active in enumerate(self.active): self.strip2D.set(active[0], 20 - active[2], self.colors[1]) def setColors(self, colors): self.colors = colors if __name__ == "__main__": e = Hourglass(Strip2D(7, 21)) e.run()
self.strip2D.strip.clear([255, 255, 255]) count = 0 now = time.time() while (not self.quit) and ((time.time() - now) < runtime): for _i in range(self.strip2D.lenx): self.strip2D.strip.fade(.6) self.strip2D.rotr() for y in range(self.strip2D.leny): self.strip2D.set(count, y, [255, 90, 0]) self.strip2D.send() time.sleep(0.02) count += 1 count = count % self.strip2D.lenx self.quit = False """ ./fade.py [1|2] addr=192.168.1.255 ./fade.py [1|2] 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./fade.py [1|2] 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": if (len(sys.argv) >= 2 and sys.argv[1] == "2"): e = Fade2(Strip2D(7, 21)) else: e = Fade1(Strip2D(7, 21)) e.run()
while count < 0: count += period while count >= period: count -= period if count < period16: return 255 if count < period26: count -= period16 return 255 * (period16 - count) / period16 if count < period46: return 0 if count < period56: count -= period46 return 255 * count / period16 if count < period: return 255 return 0 def rainbow(count): r = getColorValue2(count) g = getColorValue2(count - period13) b = getColorValue2(count - period23) return [r, g, b] if __name__ == "__main__": e = Life(Strip2D(7, 21)) e.run()
import sys import math sys.path.append('../lib') sys.path.append('../singleSleeve') from strip import Strip2D, getAddr from power import Power lenx = 7 leny = 21 strips = [] count = 0 addr = getAddr() for i, address in enumerate(addr): s = Strip2D(lenx, leny) s.strip.artnet.addr = [address] p = Power(s, i * .3) strips.append(p) if False: # pylint: disable=using-constant-test for i, s in enumerate(strips): s.auto = True thread = threading.Thread(target=s.run, args=[]) thread.daemon = True thread.start() while True: time.sleep(2) if True: # pylint: disable=using-constant-test for i, s in enumerate(strips):
offset = 0 self.strip2D.send() time.sleep(0.20) offset += 1 if offset >= len(self.colors): offset = 0 self.quit = False """ ./barber.py addr=192.168.1.255 ./barber.py [surgeon|barber] 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./barber.py [1|2|3] 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": red = [255, 0, 0] white = [64, 64, 64] blue = [0, 0, 255] if (len(sys.argv) >= 2 and sys.argv[1] == "surgeon"): e = Barber(Strip2D(7, 21), [red, white, white]) elif (len(sys.argv) >= 2 and sys.argv[1] == "barber"): e = Barber(Strip2D(7, 21), [blue, white, white]) else: # Modern (patriot) style e = Barber(Strip2D(7, 21), [red, white, white, blue, white, white]) e.run()
class Power(Effect): auto = True v = 0 def __init__(self, strip2D, offset = 0.0): super(Power, self).__init__(strip2D) self.strip2D.strip.clear() self.offset = offset def step(self, count): #if (count % 5) != 0: # return if self.auto: self.v = int(74.0 + 70.0 * math.sin((count + self.offset) / 20.0)) self.strip2D.strip.clear() for i in range(self.v): self.strip2D.strip.set(i, self.getColor(i)) def getColor(self, i): x = 255 * i / 144 if x < 0: x = 0 if x > 255: x = 255 return [x, 255 - x, 0] if __name__ == "__main__": e = Power(Strip2D(7, 21)) e.run()
def __init__(self, strip2D): super(JacobLadder, self).__init__(strip2D) self.strip2D.strip.clear() def run(self, runtime=None): if runtime is None: if hasattr(sys, "maxint"): # Python 2 runtime = sys.maxint elif hasattr(sys, "maxsize"): # Python 3 runtime = sys.maxsize self.strip2D.strip.clear([0, 0, 0]) for x in range(self.strip2D.lenx): self.strip2D.set(x, 0, [64, 192, 255]) now = time.time() while (not self.quit) and ((time.time() - now) < runtime): for _i in range(self.strip2D.leny): time.sleep(0.05) self.strip2D.rotu() self.strip2D.send() self.quit = False if __name__ == "__main__": e = JacobLadder(Strip2D(7, 21)) e.run()
def run(self, runtime=None): if runtime is None: if hasattr(sys, "maxint"): # Python 2 runtime = sys.maxint elif hasattr(sys, "maxsize"): # Python 3 runtime = sys.maxsize self.strip2D.strip.clear() x = 5 for y in range(self.strip2D.leny): if y % 7 == 0: x -= 1 self.strip2D.set(x - 1, y, [40, 40, 40]) self.strip2D.set(x, y, [255, 255, 255]) self.strip2D.send() now = time.time() while (not self.quit) and ((time.time() - now) < runtime): time.sleep(0.2) self.strip2D.rotr() self.strip2D.send() self.quit = False if __name__ == "__main__": e = Lighthouse(Strip2D(7, 21)) e.run()
sleeve.palette = 2 sleeve.restoretime = time.time() + 5 if payload == 'OFF': print("dong") #e.palette = 0 """ ./fire.py addr=192.168.1.255 ./fire.py 'addr=[("192.168.1.255", ), ("localhost", 7000)]' ./fire.py 'addr=[("192.168.1.255", 6454), ("localhost", 7000)]' """ if __name__ == "__main__": # Consistent client_id and don't clean session client = paho.Client(client_id="cave-bell", clean_session=False) client.on_message = on_mqtt_message client.connect(broker) # Subscribe to the door bell switch client.subscribe("home/groundfloor/entrance/hallway/stat/POWER3", qos=1) client.subscribe("mancave/groundfloor/office/motion/cmnd/POWER1", qos=1) client.subscribe("outside/groundfloor/alley/motion/cmnd/POWER1", qos=1) time.sleep(0.5) client.loop_start() sleeve = Mqtt_Fire(Strip2D(7, 21)) sleeve.run()