def main():
    """ Generates code for name_to_rgb dict, assuming an rgb.txt file available (in X11 format)."""
    import re
    with open('rgb.txt') as fp:
        line = fp.readline()
        while line:
            reg = re.match(r'\s*(\d+)\s*(\d+)\s*(\d+)\s*(\w.*\w).*', line)
            if reg:
                r = int(reg.group(1)) / 255.
                g = int(reg.group(2)) / 255.
                b = int(reg.group(3)) / 255.
                d = reg.group(4)
                print "'%s' : np.array([%.2f, %.2f, %.2f])," % (d, r, g, b)
            line = fp.readline()
def main ( ) : import re with open ( 'rgb.txt' ) as fp : line = fp . readline ( ) while line : reg = re . match ( r'\s*(\d+)\s*(\d+)\s*(\d+)\s*(\w.*\w).*' , line ) if reg : r = int ( reg . group ( 1 ) ) / 255. g = int ( reg . group ( 2 ) ) / 255. b = int ( reg . group ( 3 ) ) / 255. d = reg . group ( 4 ) print "'%s' : np.array([%.2f, %.2f, %.2f])," % ( d , r , g , b ) line = fp . readline ( )
Generates code for name_to_rgb dict, assuming an rgb.txt file available (in X11 format).