Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal simulation of blinkt library #98

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/eyedropper.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
76 changes: 76 additions & 0 deletions examples/fake_blinkt.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions examples/rampup.py
Original file line number Diff line number Diff line change
@@ -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)