From 2a74911541ce65ae566fd5f2a524ae6dcf2b00de Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 28 Jul 2013 00:19:47 +0200 Subject: Added two useful tools --- colorcube.py | 21 +++++++++++++++++++++ resolvecolor.py | 13 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 colorcube.py create mode 100755 resolvecolor.py diff --git a/colorcube.py b/colorcube.py new file mode 100755 index 0000000..dc84e2e --- /dev/null +++ b/colorcube.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import os, sys, argparse, os.path, json + +reset_sequence = '\033[39;49m' + +def esc(i): + return '\033[48;5;'+str(i)+'m' + +print(''.join([str(i).ljust(4) for i in range(16)])) +print(' '.join([esc(i) for i in range(16)])+' ' + reset_sequence) + +for j in range(6): + for k in range(6): + c = 16+j*6+k*6*6 + print(''.join([str(c+i).ljust(4) for i in range(6)])) + print(' '.join([esc(c+i) for i in range(6)])+' ' + reset_sequence) + +print(''.join([str(i).ljust(4) for i in range(16+6*6*6, 16+6*6*6+24)])) +print(' '.join([esc(i) for i in range(16+6*6*6, 16+6*6*6+24)])+' ' + reset_sequence) + diff --git a/resolvecolor.py b/resolvecolor.py new file mode 100755 index 0000000..9f1b181 --- /dev/null +++ b/resolvecolor.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +import os, sys, argparse, os.path, json, re +from pygments.formatters import terminal256 + +formatter = terminal256.Terminal256Formatter() + +if len(sys.argv) != 2: + print('Usage: resolvecolor.py #RRGGBB') + exit() + +print(formatter._closest_color(*[int(s, 16) for s in re.match('#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})', sys.argv[1]).groups()])) + -- cgit