Created
October 28, 2016 05:57
-
-
Save justbuchanan/d9c5632851379f0728e9cb9a5bb4bcac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import tools | |
import time | |
import sys | |
from colorsys import * | |
# #010101 -> (1.0/2^16) * 3 | |
def hex2triplet(hexval): | |
# print("hexval: %s" % hexval) | |
result = [] | |
for i in range(3): | |
ind = 1+i*2 | |
s = hexval[ind:ind+2] | |
val = float(int(s, 16)) | |
result.append(val / 255) | |
return result | |
def twoDigitHexFromFloat(val): | |
hex1 = hex(int(val*255))[2:] | |
if len(hex1) == 1: hex1 = '0' + hex1 | |
return hex1 | |
def triplet2hex(triplet): | |
return '#' + ''.join([twoDigitHexFromFloat(v) for v in triplet]) | |
def interp(start, end, t): | |
return start + (end - start) * t | |
def interp_hsv(start, end, t): | |
return [interp(start[i], end[i], t) for i in range(3)] | |
start = rgb_to_hsv(*hex2triplet(tools.ICON_COLOR)) | |
end = rgb_to_hsv(*hex2triplet(tools.BAR_BACKGROUND_COLOR)) | |
# end = rgb_to_hsv(*hex2triplet('#ffffff')) | |
duration = 0.5 | |
fps = 30 | |
delay = duration / fps | |
def fade(num_frames = fps * duration): | |
iteration = 0 | |
while True: | |
color = interp_hsv(start, end, float(iteration)/num_frames) | |
color_rgb = hsv_to_rgb(*color) | |
color_hex = triplet2hex(color_rgb) | |
# color += 1 | |
# hex1 = hex(color)[2:] | |
# if len(hex1) == 1: hex1 = '0' + hex1 | |
# color_hex = '#' + hex1 * 3 | |
# print(tools.pango(' ', background=color_hex, font_size='large')) | |
print(tools.pango('30%', background=color_hex)) | |
sys.stdout.flush() | |
iteration += 1 | |
if iteration == num_frames: | |
break | |
time.sleep(delay) | |
tools.autoreload_xresources_with_callback(lambda: fade()) | |
fade() | |
while True: | |
sleep(1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment