Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/colors.py
diff options
context:
space:
mode:
Diffstat (limited to 'colors.py')
-rw-r--r--colors.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/colors.py b/colors.py
index af75e1a..161c0e6 100644
--- a/colors.py
+++ b/colors.py
@@ -1,3 +1,5 @@
+import logging
+
CREDIT_COLOR = '#009900'
DEBIT_COLOR = '#ff4040'
@@ -41,3 +43,21 @@ def get_category_color_str(catname):
color = get_category_color(catname)
return "#%02x%02x%02x" % \
(int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))
+
+
+def is_too_light(color):
+ return _luminance(color) > 96
+
+
+def _luminance(color):
+ ''' Calculate luminance value '''
+ return int(color[1:3], 16) * 0.3 + int(color[3:5], 16) * 0.6 + \
+ int(color[5:7], 16) * 0.1
+
+
+def test_luminances():
+ for cat_color in CATEGORY_COLORS:
+ color = "#%02x%02x%02x" % \
+ (int(cat_color[0] * 255), int(cat_color[1] * 255),
+ int(cat_color[2] * 255))
+ logging.error('color %s luminance %s', color, _luminance(color))