def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.parent = parent self.time_now = datetime.now() self.time_then = self.time_now self.display() self.parent.after(200, self.update)
def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.time_now = datetime.now() self.time_then = self.time_now self.parent = parent self.__reset_second_fade() self.__reset_minute_fade() self.__reset_hour_fade() self.display() self.update()
class Hypno(object): def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.parent = parent self.time_now = datetime.now() self.time_then = self.time_now self.idx = 0 self.display() self.parent.after(0, self.update) def display(self): self.time_now = datetime.now() for x in range(len(self.np.pixels)): self.np.set_pixel_color(x, 0, 0, 0, 0) for x in range(40, 60, 1): blue = 200 if x == self.time_now.second else 0 green = 200 if x == self.time_now.minute else 0 red = 200 if x == hour_pixel(self.time_now.hour) else 0 white = (x - 40) * 10 self.np.set_pixel_color(x, red, green, blue, white) def update(self): if self.idx == 0: self.time_now = datetime.now() blue = 250 if self.idx == self.time_now.second else 0 green = 250 if self.idx == self.time_now.minute else 0 red = 250 if self.idx == hour_pixel(self.time_now.hour) else 0 self.np.set_pixel_color(self.idx, red, green, blue, 200) prev = self.idx for x in range(20): prev = prev - 1 if prev > 0 else 59 r, g, b, w = self.np.get_pixel_color(prev) r = r - 10 if r else 0 g = g - 10 if g else 0 b = b - 10 if b else 0 w = w - 10 if w else 0 self.np.set_pixel_color(prev, r, g, b, w) self.idx = self.idx + 1 if self.idx < 59 else 0 # 60 LED doesn't divide evenly into 1000ms (== 1 s) so delay size # is 17, 17, 16 (repeat 20 times = 1000). delay = 16 if (self.idx % 3) == 0 else 17 self.parent.after(delay, self.update)
class Hands(object): def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.time_now = datetime.now() self.time_then = self.time_now self.parent = parent self.display() self.parent.after(200, self.update) def hour_hand(self, hour): for x in range(-2, 3, 1): idx = (hour_pixel(hour) + x) % 60 intensity = 250 - (abs(x) * 50) self.np.set_pixel_color(idx, intensity, 0, 0, 0) def minute_hand(self, minute): for x in range(-1, 2, 1): idx = (minute + x) % 60 intensity = 250 - (abs(x) * 50) self.np.set_pixel_color(idx, 0, intensity, 0, 0) def second_hand(self, second): self.np.set_pixel_color(second, 0, 0, 250, 0) def display(self): self.hour_hand(self.time_now.hour) self.minute_hand(self.time_now.minute) self.second_hand(self.time_now.second) self.time_then = self.time_now def update(self): self.time_now = datetime.now() if self.time_now.second != self.time_then.second: for pixel in range(len(self.np.pixels)): self.np.set_pixel_color(pixel, 0, 0, 0, 0) self.hour_hand(self.time_now.hour) self.minute_hand(self.time_now.minute) self.second_hand(self.time_now.second) self.time_then = self.time_now self.parent.after(200, self.update)
class Pastel(object): def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.time_now = datetime.now() self.time_then = self.time_now self.parent = parent self.display() self.parent.after(200, self.update) def wheel(self, pixel, cidx): rgbw = list(self.np.get_pixel_color(pixel)) rgbw[cidx] = 250 self.np.set_pixel_color(pixel, rgbw[0], rgbw[1], rgbw[2], 0) brg = 145 stp = -5 for x in range(1, 60): idx = (pixel + x) % 60 rgbw = list(self.np.get_pixel_color(idx)) rgbw[cidx] = brg self.np.set_pixel_color(idx, rgbw[0], rgbw[1], rgbw[2], 0) if brg == 0: stp = 5 brg = brg + stp def display(self): self.update() def update(self): self.time_now = datetime.now() if self.time_now.second != self.time_then.second: self.wheel(self.time_now.second, 2) self.wheel(self.time_now.minute, 1) self.wheel(hour_pixel(self.time_now.hour), 0) self.time_then = self.time_now self.parent.after(200, self.update)
class Analog(object): def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.time_now = datetime.now() self.time_then = self.time_now self.parent = parent self.display() self.parent.after(200, self.update) def display(self): for pixel in range(len(self.np.pixels)): if (pixel % 5) == 0: self.np.set_pixel_color(pixel, 0, 0, 0, 100) white = lambda x: 100 if (x % 5) == 0 else 0 self.np.set_pixel_color(self.time_now.second, 0, 0, 255, white(self.time_now.second)) self.np.set_pixel_color(self.time_now.minute, 0, 255, 0, white(self.time_now.minute)) self.np.set_pixel_color(hour_pixel(self.time_now.hour), 255, 0, 0, white(hour_pixel(self.time_now.hour))) self.time_then = self.time_now def update(self): self.time_now = datetime.now() if self.time_now.second != self.time_then.second: r, g, b, w = self.np.get_pixel_color(self.time_then.second) self.np.set_pixel_color(self.time_then.second, r, g, 0, w) r, g, b, w = self.np.get_pixel_color(self.time_now.second) self.np.set_pixel_color(self.time_now.second, r, g, 255, w) if self.time_now.minute != self.time_then.minute: r, g, b, w = self.np.get_pixel_color(self.time_then.minute) self.np.set_pixel_color(self.time_then.minute, r, 0, b, w) r, g, b, w = self.np.get_pixel_color(self.time_now.minute) self.np.set_pixel_color(self.time_now.minute, r, 255, b, w) if self.time_now.hour != self.time_then.hour: r, g, b, w = self.np.get_pixel_color(self.time_then.hour) self.np.set_pixel_color(hour_pixel(self.time_then.hour), 0, g, b, w) r, g, b, w = self.np.get_pixel_color(self.time_now.hour) self.np.set_pixel_color(hour_pixel(self.time_now.hour), 255, g, b, w) self.time_then = self.time_now self.parent.after(200, self.update)
class Flood(object): def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.time_now = datetime.now() self.time_then = self.time_now self.parent = parent self.display() self.parent.after(200, self.update) def display(self): for pixel in range(len(self.np.pixels)): self.np.set_pixel_color(pixel, 0, 0, 0, 0) brg = 250 if (self.time_now.minute % 2) == 0 else 0 for idx in range(0, self.time_now.second + 1): self.np.set_pixel_color(idx, 0, 0, brg, 0) brg = 0 if brg == 250 else 250 for idx in range(self.time_now.second + 1, 60): self.np.set_pixel_color(idx, 0, 0, brg, 0) r, g, b, w = self.np.get_pixel_color(hour_pixel(self.time_now.hour)) self.np.set_pixel_color(hour_pixel(self.time_now.hour), 250, g, b, 0) r, g, b, w = self.np.get_pixel_color(self.time_now.minute) self.np.set_pixel_color(self.time_now.minute, g, 250, b, 0) def update(self): self.time_now = datetime.now() if self.time_now.second != self.time_then.second: brg = 250 if (self.time_now.minute % 2) == 0 else 0 r, g, b, w = self.np.get_pixel_color(self.time_now.second) self.np.set_pixel_color(self.time_now.second, r, g, brg, w) if self.time_now.minute != self.time_then.minute: r, g, b, w = self.np.get_pixel_color(self.time_then.minute) self.np.set_pixel_color(self.time_then.minute, r, 0, b, w) r, g, b, w = self.np.get_pixel_color(self.time_now.minute) self.np.set_pixel_color(self.time_now.minute, r, 250, b, w) if self.time_now.hour != self.time_then.hour: r, g, b, w = self.np.get_pixel_color( hour_pixel(self.time_then.hour)) self.np.set_pixel_color(hour_pixel(self.time_then.hour), 0, g, b, w) r, g, b, w = self.np.get_pixel_color( hour_pixel(self.time_now.hour)) self.np.set_pixel_color(hour_pixel(self.time_now.hour), 250, g, b, w) self.time_then = self.time_now self.parent.after(200, self.update)
class Fade(object): def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.time_now = datetime.now() self.time_then = self.time_now self.parent = parent self.__reset_second_fade() self.__reset_minute_fade() self.__reset_hour_fade() self.display() self.update() def __reset_second_fade(self): self.nsc = 0 self.tsc = 250 self.ns = (self.time_now.second + 1) % 60 def __reset_minute_fade(self): self.nhc = 0 self.thc = 240 self.nh = (self.time_now.hour + 1) % 12 def display(self): "Initially, only display Minute of hour at full brightness." for pixel in range(len(self.np.pixels)): if (pixel%5) == 0: self.np.set_pixel_color(pixel, 0, 0, 0, 100) white = lambda x: 100 if (x%5)==0 else 0 self.np.set_pixel_color( self.time_now.second, 0, 0, self.tsc, white(self.time_now.second) ) self.np.set_pixel_color( self.time_now.minute, 0, self.tmc, 0, white(self.time_now.minute) ) self.time_then = self.time_now def update(self): self.time_now = datetime.now() if self.time_now.second != self.time_then.second: self.__reset_second_fade() r, g, b, w = self.np.get_pixel_color(self.time_now.second) self.np.set_pixel_color( self.time_now.second, r, g, self.tsc, w ) r, g, b, w = self.np.get_pixel_color(self.time_then.second) self.np.set_pixel_color( self.time_then.second, r, g, 0, w ) if self.time_now.minute != self.time_then.minute: self.__reset_minute_fade() r, g, b, w = self.np.get_pixel_color(self.time_now.minute) self.np.set_pixel_color( self.time_now.minute, r, self.tmc, b, w ) r, g, b, w = self.np.get_pixel_color(self.time_then.minute) self.np.set_pixel_color( self.time_then.minute, r, 0, b, w ) else: r, g, b, w = self.np.get_pixel_color(self.time_now.minute) self.np.set_pixel_color( self.time_now.minute, r, self.tmc, b, w ) r, g, b, w = self.np.get_pixel_color(self.nm) self.np.set_pixel_color( self.nm, r, self.nmc, b, w ) self.nmc = self.nmc + 4 if self.nmc < 240 else 240 self.tmc = self.tmc - 4 if self.tmc > 0 else 0 else: r, g, b, w = self.np.get_pixel_color(self.time_now.second) self.np.set_pixel_color( self.time_now.second, r, g, self.tsc, w ) r, g, b, w = self.np.get_pixel_color(self.ns) self.np.set_pixel_color( self.ns, r, g, self.nsc, w ) self.nsc = self.nsc + 10 if self.nsc < 250 else 250 self.tsc = self.tsc - 10 if self.tsc > 0 else 0 self.time_then = self.time_now self.parent.after(40, self.update)
class Comet(object): def __init__(self, parent): self.np = NeopixelRing(parent, 200) self.parent = parent self.time_now = datetime.now() self.time_then = self.time_now self.display() self.parent.after(200, self.update) def display(self): self.time_now = datetime.now() for x in range(len(self.np.pixels)): self.np.set_pixel_color(x, 0, 0, 0, 0) idx = self.time_now.second blue = 240 for x in range(16): self.np.set_pixel_color(idx, 0, 0, blue, 0) blue -= 16 idx = dec_pix(idx) idx = self.time_now.minute green = 240 for x in range(16): r, g, b, w = self.np.get_pixel_color(idx) self.np.set_pixel_color(idx, r, green, b, w) green -= 16 idx = dec_pix(idx) idx = hour_pixel(self.time_now.hour) red = 240 for x in range(16): r, g, b, w = self.np.get_pixel_color(idx) self.np.set_pixel_color(idx, red, g, b, w) red -= 16 idx = dec_pix(idx) self.time_then = self.time_now def update(self): self.time_now = datetime.now() if (self.time_now.second != self.time_then.second): idx = self.time_now.second blue = 240 for x in range(16): r, g, b, w = self.np.get_pixel_color(idx) self.np.set_pixel_color(idx, r, g, blue, w) blue -= 16 idx = dec_pix(idx) if (self.time_now.minute != self.time_then.minute): idx = self.time_now.minute green = 240 for x in range(16): r, g, b, w = self.np.get_pixel_color(idx) self.np.set_pixel_color(idx, r, green, b, w) green -= 16 idx = dec_pix(idx) if (self.time_now.hour != self.time_then.hour): idx = hour_pixel(self.time_now.minute) red = 240 for x in range(16): r, g, b, w = self.np.get_pixel_color(idx) self.np.set_pixel_color(idx, red, g, b, w) red -= 16 idx = dec_pix(idx) self.time_then = self.time_now self.parent.after(200, self.update)