closer color matching

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-06-10 23:41:53 -04:00
parent 6534ec0cdf
commit a4475951e7
2 changed files with 39 additions and 23 deletions

View File

@ -28,6 +28,28 @@ def add_color(name, value, abbrev):
ascii_map[abbrev] = name ascii_map[abbrev] = name
rev_ascii_map[name] = abbrev rev_ascii_map[name] = abbrev
def iter256():
for r in range(0, 6):
for g in range(0, 6):
for b in range(0, 6):
if r >= g and g > b: name = 'yellow'
elif r >= b and b - g > 1: name = 'magenta'
elif b >= g and g - r > 2: name = 'cyan'
elif b >= r and r > g: name = 'magenta'
elif g >= r and r - b > 2: name = 'yellow'
elif g >= b and b - r > 1: name = 'cyan'
elif r > b and r > g: name = 'red'
elif g > b and g > r: name = 'green'
elif b > r and b > g: name = 'blue'
else: continue
yield (name, r, g, b)
raise StopIteration
def color256(name, fallback, abbrev, r, g, b): def color256(name, fallback, abbrev, r, g, b):
name2 = '%s%d%d%d' % (name, r, g, b) name2 = '%s%d%d%d' % (name, r, g, b)
abbrev2 = '%s%d%d%d' % (abbrev, r, g, b) abbrev2 = '%s%d%d%d' % (abbrev, r, g, b)
@ -84,18 +106,8 @@ def init():
value = curses.COLOR_WHITE value = curses.COLOR_WHITE
add_color(name2, value, abbrev2) add_color(name2, value, abbrev2)
for i in range(1, 6): for name, r, g, b in iter256():
for j in range(0, i): color256(name, colors[name], rev_ascii_map[name], r, g, b)
for k in range(0, i):
color256('red', curses.COLOR_RED, 'r', i, j, k)
color256('green', curses.COLOR_GREEN, 'g', j, i, k)
color256('blue', curses.COLOR_BLUE, 'b', j, k, i)
for i in range(1, 6):
for j in range(0, i):
color256('yellow', curses.COLOR_YELLOW, 'y', i, i, j)
color256('cyan', curses.COLOR_CYAN, 'c', j, i, i)
color256('magenta', curses.COLOR_MAGENTA, 'm', i, j, i)
def build(fg, bg, *attr): def build(fg, bg, *attr):
v = curses.A_NORMAL | pairs(fg, bg) v = curses.A_NORMAL | pairs(fg, bg)

View File

@ -1,3 +1,4 @@
import color
from mode import Fundamental from mode import Fundamental
from lex import Grammar, PatternRule from lex import Grammar, PatternRule
@ -17,17 +18,20 @@ def abc(name, r, g, b):
ColortestGrammar.rules.append(PatternRule('z-' + name2, name2)) ColortestGrammar.rules.append(PatternRule('z-' + name2, name2))
Colortest.colors['z-' + name2] = (name2, 'default') Colortest.colors['z-' + name2] = (name2, 'default')
for i in range(1, 6): for name, r, g, b in color.iter256():
for j in range(0, i): abc(name, r, g, b)
for k in range(0, i):
abc('red', i, j, k)
abc('green', j, i, k)
abc('blue', j, k, i)
for i in range(1, 6): #for i in range(1, 6):
for j in range(0, i): # for j in range(0, i):
abc('yellow', i, i, j) # for k in range(0, i):
abc('cyan', j, i, i) # abc('red', i, j, k)
abc('magenta', i, j, i) # abc('green', j, i, k)
# abc('blue', j, k, i)
#
#for i in range(1, 6):
# for j in range(0, i):
# abc('yellow', i, i, j)
# abc('cyan', j, i, i)
# abc('magenta', i, j, i)
install = Colortest.install install = Colortest.install