File tree Expand file tree Collapse file tree 1 file changed +23
-21
lines changed Expand file tree Collapse file tree 1 file changed +23
-21
lines changed Original file line number Diff line number Diff line change @@ -105,17 +105,17 @@ class ColorConverter(object):
105
105
*colorConverter*, is needed.
106
106
"""
107
107
colors = {
108
- 'b' : '#0000ff' ,
109
- 'r ' : '#ff0000' ,
110
- 'g ' : '#008000' ,
111
- 'c' : '#00bfbf' ,
112
- 'm' : '#bf00bf' ,
113
- 'y' : '#bfbf00' ,
114
- 'k' : '#000000' ,
115
- 'w' : '#ffffff' }
108
+ 'b' : ( 0 , 0 , 1 ) ,
109
+ 'g ' : ( 0 , 0.5 , 0 ) ,
110
+ 'r ' : ( 1 , 0 , 0 ) ,
111
+ 'c' : ( 0 , 0.75 , 0.75 ) ,
112
+ 'm' : ( 0.75 , 0 , 0.75 ) ,
113
+ 'y' : ( 0.75 , 0.75 , 0 ) ,
114
+ 'k' : ( 0 , 0 , 0 ) ,
115
+ 'w' : ( 1 , 1 , 1 ) }
116
116
117
117
cache = {}
118
- CN_LOOKUPS = [colors , ] + [ COLOR_NAMES [k ] for k in ['css4' , 'xkcd' ]]
118
+ CN_LOOKUPS = [COLOR_NAMES [k ] for k in ['css4' , 'xkcd' ]]
119
119
120
120
def to_rgb (self , arg ):
121
121
"""
@@ -152,18 +152,20 @@ def to_rgb(self, arg):
152
152
try :
153
153
if cbook .is_string_like (arg ):
154
154
argl = arg .lower ()
155
- for cmapping in self .CN_LOOKUPS :
156
- str1 = cmapping .get (argl , argl )
157
- if str1 != argl :
158
- break
159
- if str1 .startswith ('#' ):
160
- color = hex2color (str1 )
161
- else :
162
- fl = float (argl )
163
- if fl < 0 or fl > 1 :
164
- raise ValueError (
165
- 'gray (string) must be in range 0-1' )
166
- color = (fl ,)* 3
155
+ color = self .colors .get (argl , None )
156
+ if color is None :
157
+ for cmapping in self .CN_LOOKUPS :
158
+ str1 = cmapping .get (argl , argl )
159
+ if str1 != argl :
160
+ break
161
+ if str1 .startswith ('#' ):
162
+ color = hex2color (str1 )
163
+ else :
164
+ fl = float (argl )
165
+ if fl < 0 or fl > 1 :
166
+ raise ValueError (
167
+ 'gray (string) must be in range 0-1' )
168
+ color = (fl ,)* 3
167
169
elif cbook .iterable (arg ):
168
170
if len (arg ) > 4 or len (arg ) < 3 :
169
171
raise ValueError (
You can’t perform that action at this time.
0 commit comments