diff --git a/examples/eyedropper.py b/examples/eyedropper.py old mode 100644 new mode 100755 index 9957464..92c4380 --- a/examples/eyedropper.py +++ b/examples/eyedropper.py @@ -14,7 +14,7 @@ rawrgb = list(im.getdata()) rgb = str(rawrgb)[2:-2] r, g, b = rgb.split(', ') - blinkt.set_all(r, g, b) + blinkt.set_all(int(r), int(g), int(b)) blinkt.set_brightness(1) blinkt.show() time.sleep(0.01) diff --git a/examples/fake_blinkt.py b/examples/fake_blinkt.py new file mode 100644 index 0000000..b84d79f --- /dev/null +++ b/examples/fake_blinkt.py @@ -0,0 +1,76 @@ +"""fake_blink terminal simulation of blinkt, to use rename to blinkt.py and place in same directory as blinkt program""" +import sys +import atexit + +_clear_on_exit = True +_true_color = True +NUM_PIXELS = 8 +pixels = [(0, 0, 0, 1)] * NUM_PIXELS + + +def _exit(): + if _clear_on_exit: + clear() + show() + else: + print("") + + +def set_brightness(brightness): + pass + + +def clear(): + pixels[:] = [(0, 0, 0, 1)] * NUM_PIXELS + + +def show(): + sys.stdout.write(" ") + for (r, g, b, _) in pixels: + if _true_color: + sys.stdout.write("\033[48;2;%d;%d;%dm " % (r, g, b)) + else: + if r == g == b: + col = 232 + (r * 24) // 256 + else: + col = 16 + ((b * 6) // 256) + ((g * 6) // 256) * 6 + ((r * 6) // 256) * 36 + sys.stdout.write("\033[48;5;%dm " % col) + sys.stdout.write("\033[0m\r") + sys.stdout.flush() + + +def set_all(r, g, b, brightness=None): + global _brightness + if brightness is not None: + _brightness = brightness + pixels[:] = [(r, g, b, 1)] * NUM_PIXELS + + +def set_pixel(x, r, g, b, brightness=None): + global _brightness + if brightness is not None: + _brightness = brightness + pixels[x] = (r, g, b, 1) + + +def get_pixel(x): + return pixels[x] + + +def set_clear_on_exit(value=True): + """Set whether Blinkt! should be cleared upon exit + + By default Blinkt! will turn off the pixels on exit, but calling:: + + blinkt.set_clear_on_exit(False) + + Will ensure that it does not. + + :param value: True or False (default True) + """ + global _clear_on_exit + _clear_on_exit = value + + +# Module Initialisation +atexit.register(_exit) diff --git a/examples/rampup.py b/examples/rampup.py new file mode 100755 index 0000000..b034647 --- /dev/null +++ b/examples/rampup.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import sys +from time import sleep +import blinkt + +for i in range(256): + blinkt.set_all(i, i, i, 1.0) + sys.stdout.write("%3d" % i) + blinkt.show() + sleep(0.1)