示例#1
0
def get_normalized_spectral_line_colors_annotated (
    brightness = 1.0,
    num_purples = 0,
    dwl_angstroms = 10):
    '''Get an array of xyz colors covering the visible spectrum.
    Optionally add a number of 'purples', which are colors interpolated between the color
    of the lowest wavelength (violet) and the highest (red).
    A text string describing the color is supplied for each color.

    brightness - Desired maximum rgb component of each color.  Default 1.0.  (Maxiumum displayable brightness)
    num_purples - Number of colors to interpolate in the 'purple' range.  Default 0.  (No purples)
    dwl_angstroms - Wavelength separation, in angstroms (0.1 nm).  Default 10 A. (1 nm spacing)
    '''
    # get range of wavelengths, in angstroms, so that we can have finer resolution than 1 nm
    wl_angstrom_range = range (10*start_wl_nm, 10*(end_wl_nm + 1), dwl_angstroms)
    # get total point count
    num_spectral = len (wl_angstrom_range)
    num_points   = num_spectral + num_purples
    xyzs = numpy.empty ((num_points, 3))
    names = []
    # build list of normalized color x,y values proceeding along each wavelength
    i = 0
    for wl_A in wl_angstrom_range:
        wl_nm = wl_A * 0.1
        xyz = xyz_from_wavelength (wl_nm)
        colormodels.xyz_normalize (xyz)
        xyzs [i] = xyz
        name = '%.1f nm' % wl_nm
        names.append (name)
        i += 1
    # interpolate from end point to start point (filling in the purples)
    first_xyz = xyzs [0]
    last_xyz  = xyzs [num_spectral - 1]
    for ipurple in range (0, num_purples):
        t = float (ipurple) / float (num_purples - 1)
        omt = 1.0 - t
        xyz = t * first_xyz + omt * last_xyz
        colormodels.xyz_normalize (xyz)
        xyzs [i] = xyz
        name = '%03d purple' % math.floor (1000.0 * t + 0.5)
        names.append (name)
        i += 1
    # scale each color to have the max rgb component equal to the desired brightness
    for i in range (0, num_points):
        rgb = colormodels.brightest_rgb_from_xyz (xyzs [i], brightness)
        xyzs [i] = colormodels.xyz_from_rgb (rgb)
    # done
    return (xyzs, names)
示例#2
0
def visible_spectrum_table(filename='visible_spectrum.html'):
    '''Write an HTML table with the visible spectrum colors.'''
    spectrum = ciexyz.empty_spectrum()
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors_1 = numpy.empty((num_wl, 3))
    rgb_colors_2 = numpy.empty((num_wl, 3))
    for i in range(0, num_wl):
        xyz = ciexyz.xyz_from_wavelength(spectrum[i][0])
        rgb_1 = colormodels.rgb_from_xyz(xyz)
        rgb_2 = colormodels.brightest_rgb_from_xyz(xyz)
        rgb_colors_1[i] = rgb_1
        rgb_colors_2[i] = rgb_2
    # scale 1 to make brightest rgb value = 1.0
    rgb_max = numpy.max(rgb_colors_1)
    scaling = 1.0 / rgb_max
    rgb_colors_1 *= scaling

    # write HTML file

    def write_link(f, url, text):
        '''Write an html link.'''
        link = '<a href="%s">%s</a><br/>\n' % (url, text)
        f.write(link)

    f = open(filename, 'w')
    # html headers
    f.write('<html>\n')
    f.write('<head>\n')
    f.write('<title>Colors of Pure Spectral Lines</title>\n')
    f.write('</head>\n')
    f.write('<body>\n')
    f.write('<p><h1>Colors of Pure Spectral Lines</h1></p>\n')
    f.write('<p>%s</p>\n' %
            'White added to undisplayable pure colors to fit into rgb space.')
    f.write('<hr/>\n')
    # table header
    f.write('<table border cellpadding="5">\n')
    f.write('<tr>\n')
    f.write('<th>Wavelength</th>\n')
    f.write('<th>R</th>\n')
    f.write('<th>G</th>\n')
    f.write('<th>B</th>\n')
    f.write('<th>Hex Code</th>\n')
    f.write('<th width=200>Full Brightness</th>\n')
    f.write('<th width=200>Perceptual Brightness</th>\n')
    f.write('</tr>\n')
    # each row

    for i in range(0, num_wl):
        irgb_1 = colormodels.irgb_from_rgb(rgb_colors_1[i])
        irgb_2 = colormodels.irgb_from_rgb(rgb_colors_2[i])
        red = irgb_2[0]
        green = irgb_2[1]
        blue = irgb_2[2]
        hexstr_1 = colormodels.irgb_string_from_irgb(irgb_1)
        hexstr_2 = colormodels.irgb_string_from_irgb(irgb_2)

        iwl = spectrum[i][0]
        code = '%.1f nm' % iwl

        f.write('<tr>\n')
        f.write('<td>%s</td>\n' % (code))
        f.write('<td>%d</td>\n' % (red))
        f.write('<td>%d</td>\n' % (green))
        f.write('<td>%d</td>\n' % (blue))
        f.write('<td>%s</td>\n' % (hexstr_2))
        swatch = "&nbsp;"
        f.write('<td bgcolor="%s">%s</td>\n' % (hexstr_2, swatch))
        f.write('<td bgcolor="%s">%s</td>\n' % (hexstr_1, swatch))
        f.write('</tr>\n')

    f.write('</table>\n')
    # references
    f.write('<hr/>\n')
    f.write('<p>References</p>\n')
    # one source for data
    write_link(f, 'http://goffgrafix.com/pantone-rgb-100.php',
               'Goffgrafix.com')
    # another source with basically the same data
    write_link(f, 'http://www.sandaleo.com/pantone.asp', 'Sandaleo.com')
    # one with more colors including metallic (also some errors), not quite consistent with the first two
    write_link(
        f, 'http://www.loral.org/Z/Colors/100.html',
        'Loral.org - Conversions based on CorelDRAW v12 Pantone Solid Coated or Pastel Coated tables and sRGB color space.'
    )
    # some colors for various sports teams
    write_link(
        f,
        'http://www.pennjersey.info/forums/questions-answers/7895-pantone-colors-colleges-university-mlb-nfl-teams.html',
        'Pantone colors for some sports teams.')
    # some colors for various national flags
    write_link(
        f, 'http://desktoppub.about.com/od/colorpalettes/l/aa_flagcolors.htm',
        'What color is your flag? Pantone colors for some flags.')
    write_link(f,
               'http://desktoppub.about.com/library/weekly/blcpflagsrwb.htm',
               'Red, White, &amp Blue - Pantone colors for some flags.')
    write_link(
        f, 'http://desktoppub.about.com/library/weekly/blcpflagsyellow.htm',
        'Yellow or Gold - Pantone colors for some flags.')
    write_link(
        f, 'http://desktoppub.about.com/library/weekly/blcpflagsgreen.htm',
        'Green - Pantone colors for some flags.')
    write_link(
        f,
        'http://desktoppub.about.com/library/weekly/blcpatrioticswatches.htm',
        'Color swatches - Pantone colors for some flags.')
    # official Pantone webpages
    write_link(f,
               'http://pantone.com/pages/pantone/Pantone.aspx?pg=19970&ca=25',
               'An official PANTONE page')
    write_link(f,
               'http://pantone.com/pages/products/product.aspx?ca=1&pid=293&',
               'Another official PANTONE page')
    # html ending
    f.write('</body>\n')
    f.write('</html>\n')
    f.close()
示例#3
0
def visible_spectrum_table (filename='visible_spectrum.html'):
    '''Write an HTML table with the visible spectrum colors.'''
    spectrum = ciexyz.empty_spectrum()
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors_1 = numpy.empty ((num_wl, 3))
    rgb_colors_2 = numpy.empty ((num_wl, 3))
    for i in range (0, num_wl):
        xyz = ciexyz.xyz_from_wavelength (spectrum [i][0])
        rgb_1 = colormodels.rgb_from_xyz (xyz)
        rgb_2 = colormodels.brightest_rgb_from_xyz (xyz)
        rgb_colors_1 [i] = rgb_1
        rgb_colors_2 [i] = rgb_2
    # scale 1 to make brightest rgb value = 1.0
    rgb_max = numpy.max (rgb_colors_1)
    scaling = 1.0 / rgb_max
    rgb_colors_1 *= scaling
    # write HTML file

    def write_link (f, url, text):
        '''Write an html link.'''
        link = '<a href="%s">%s</a><br/>\n' % (url, text)
        f.write (link)

    f = open (filename, 'w')
    # html headers
    f.write ('<html>\n')
    f.write ('<head>\n')
    f.write ('<title>Colors of Pure Spectral Lines</title>\n')
    f.write ('</head>\n')
    f.write ('<body>\n')
    f.write ('<p><h1>Colors of Pure Spectral Lines</h1></p>\n')
    f.write ('<p>%s</p>\n' % 'White added to undisplayable pure colors to fit into rgb space.')
    f.write ('<hr/>\n')
    # table header
    f.write ('<table border cellpadding="5">\n')
    f.write ('<tr>\n')
    f.write ('<th>Wavelength</th>\n')
    f.write ('<th>R</th>\n')
    f.write ('<th>G</th>\n')
    f.write ('<th>B</th>\n')
    f.write ('<th>Hex Code</th>\n')
    f.write ('<th width=200>Full Brightness</th>\n')
    f.write ('<th width=200>Perceptual Brightness</th>\n')
    f.write ('</tr>\n')
    # each row

    for i in range (0, num_wl):
        irgb_1 = colormodels.irgb_from_rgb (rgb_colors_1 [i])
        irgb_2 = colormodels.irgb_from_rgb (rgb_colors_2 [i])
        red   = irgb_2 [0]
        green = irgb_2 [1]
        blue  = irgb_2 [2]
        hexstr_1 = colormodels.irgb_string_from_irgb (irgb_1)
        hexstr_2 = colormodels.irgb_string_from_irgb (irgb_2)

        iwl = spectrum [i][0]
        code = '%.1f nm' % iwl

        f.write ('<tr>\n')
        f.write ('<td>%s</td>\n' % (code))
        f.write ('<td>%d</td>\n' % (red))
        f.write ('<td>%d</td>\n' % (green))
        f.write ('<td>%d</td>\n' % (blue))
        f.write ('<td>%s</td>\n' % (hexstr_2))
        swatch = "&nbsp;"
        f.write ('<td bgcolor="%s">%s</td>\n' % (hexstr_2, swatch))
        f.write ('<td bgcolor="%s">%s</td>\n' % (hexstr_1, swatch))
        f.write ('</tr>\n')

    f.write ('</table>\n')
    # references
    f.write ('<hr/>\n')
    f.write ('<p>References</p>\n')
    # one source for data
    write_link (f, 'http://goffgrafix.com/pantone-rgb-100.php', 'Goffgrafix.com')
    # another source with basically the same data
    write_link (f, 'http://www.sandaleo.com/pantone.asp', 'Sandaleo.com')
    # one with more colors including metallic (also some errors), not quite consistent with the first two
    write_link (f, 'http://www.loral.org/Z/Colors/100.html',
        'Loral.org - Conversions based on CorelDRAW v12 Pantone Solid Coated or Pastel Coated tables and sRGB color space.')
    # some colors for various sports teams
    write_link (f, 'http://www.pennjersey.info/forums/questions-answers/7895-pantone-colors-colleges-university-mlb-nfl-teams.html',
        'Pantone colors for some sports teams.')
    # some colors for various national flags
    write_link (f, 'http://desktoppub.about.com/od/colorpalettes/l/aa_flagcolors.htm', 'What color is your flag? Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpflagsrwb.htm', 'Red, White, &amp Blue - Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpflagsyellow.htm', 'Yellow or Gold - Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpflagsgreen.htm', 'Green - Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpatrioticswatches.htm', 'Color swatches - Pantone colors for some flags.')
    # official Pantone webpages
    write_link (f, 'http://pantone.com/pages/pantone/Pantone.aspx?pg=19970&ca=25', 'An official PANTONE page')
    write_link (f, 'http://pantone.com/pages/products/product.aspx?ca=1&pid=293&', 'Another official PANTONE page')
    # html ending
    f.write ('</body>\n')
    f.write ('</html>\n')
    f.close()
示例#4
0
 def get_brightest_irgb_string(xyz):
     '''Convert the xyz color to rgb, scale to maximum displayable brightness, and convert to a string.'''
     rgb = colormodels.brightest_rgb_from_xyz(xyz)
     color_string = colormodels.irgb_string_from_rgb(rgb)
     return color_string
示例#5
0
 def get_brightest_irgb_string (xyz):
     '''Convert the xyz color to rgb, scale to maximum displayable brightness, and convert to a string.'''
     rgb = colormodels.brightest_rgb_from_xyz (xyz)
     color_string = colormodels.irgb_string_from_rgb (rgb)
     return color_string