def check_irgb_string(self, irgb, verbose): ''' Convert back and forth from irgb and irgb_string. ''' irgb_string = colormodels.irgb_string_from_irgb (irgb) irgb2 = colormodels.irgb_from_irgb_string (irgb_string) irgb_string2 = colormodels.irgb_string_from_irgb (irgb2) # Values should match. self.assertEqual(irgb[0], irgb2[0]) self.assertEqual(irgb[1], irgb2[1]) self.assertEqual(irgb[2], irgb2[2]) # String should match. self.assertEqual(irgb_string, irgb_string2) msg = 'irgb: %s irgb2: %s irgb_string: %s irgb_string2: %s' % ( str(irgb), str(irgb2), irgb_string, irgb_string2) if verbose: print (msg)
def check_irgb_string(self, irgb, verbose): ''' Convert back and forth from irgb and irgb_string. ''' irgb_string = colormodels.irgb_string_from_irgb(irgb) irgb2 = colormodels.irgb_from_irgb_string(irgb_string) irgb_string2 = colormodels.irgb_string_from_irgb(irgb2) # Values should match. self.assertEqual(irgb[0], irgb2[0]) self.assertEqual(irgb[1], irgb2[1]) self.assertEqual(irgb[2], irgb2[2]) # String should match. self.assertEqual(irgb_string, irgb_string2) msg = 'irgb: %s irgb2: %s irgb_string: %s irgb_string2: %s' % ( str(irgb), str(irgb2), irgb_string, irgb_string2) if verbose: print(msg)
def test_irgb_string (verbose=1): '''Convert back and forth from irgb and irgb_string.''' for i in xrange (0, 100): ir = random.randrange (0, 256) ig = random.randrange (0, 256) ib = random.randrange (0, 256) irgb = colormodels.irgb_color (ir, ig, ib) irgb_string = colormodels.irgb_string_from_irgb (irgb) irgb2 = colormodels.irgb_from_irgb_string (irgb_string) irgb_string2 = colormodels.irgb_string_from_irgb (irgb2) if (irgb[0] != irgb2[0]) or (irgb[1] != irgb2[1]) or (irgb[2] != irgb2[2]): msg = 'irgb %s and irgb2 %s do not match' % (str (irgb), str (irgb2)) raise ValueError, msg if (irgb_string != irgb_string2): msg = 'irgb_string %s and irgb_string2 %s do not match' % (irgb_string, irgb_string2) raise ValueError, msg if verbose >= 1: print 'Passed test_irgb_string()'
def test_irgb_string(verbose=1): '''Convert back and forth from irgb and irgb_string.''' for i in xrange(0, 100): ir = random.randrange(0, 256) ig = random.randrange(0, 256) ib = random.randrange(0, 256) irgb = colormodels.irgb_color(ir, ig, ib) irgb_string = colormodels.irgb_string_from_irgb(irgb) irgb2 = colormodels.irgb_from_irgb_string(irgb_string) irgb_string2 = colormodels.irgb_string_from_irgb(irgb2) if (irgb[0] != irgb2[0]) or (irgb[1] != irgb2[1]) or (irgb[2] != irgb2[2]): msg = 'irgb %s and irgb2 %s do not match' % (str(irgb), str(irgb2)) raise ValueError(msg) if (irgb_string != irgb_string2): msg = 'irgb_string %s and irgb_string2 %s do not match' % ( irgb_string, irgb_string2) raise ValueError(msg) if verbose >= 1: print('Passed test_irgb_string()')
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 = " " 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, & 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()
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 = " " 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, & 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()