Commit d1702c39 authored by Ture Pålsson's avatar Ture Pålsson

Factor out dark/light check

parent 6ddf2ec2
......@@ -3,6 +3,9 @@ import sys
def ff(n):
return [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff][n]
def light(r, g, b):
return (21 * r + .71 * g + .07 * b >= 128)
def c():
columns = 6
rows = 216 / columns
......@@ -15,8 +18,7 @@ def c():
green = ff((c // 6) % 6)
blue = ff(c % 6)
grey = .21 * red + .71 * green + .07 * blue
fgcolor = (1, 1, 1) if grey < 128 else (0, 0, 0)
fgcolor = (0, 0, 0) if light(red, green, blue) else (1, 1, 1)
name = '%02x%02x%02x' % (red, green, blue)
alt = '%d' % (16 + c,)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment