def test_clipping(verbose=1): '''Test the various color clipping methods.''' xyz_colors = ciexyz.get_normalized_spectral_line_colors() #print('xyz_colors', xyz_colors) (num_wl, num_cols) = xyz_colors.shape # get rgb values for standard clipping colormodels.init_clipping(colormodels.CLIP_ADD_WHITE) rgb_add_white = [] for i in range(0, num_wl): color = colormodels.irgb_string_from_rgb( colormodels.rgb_from_xyz(xyz_colors[i])) rgb_add_white.append(color) # get rgb values for clamp clipping colormodels.init_clipping(colormodels.CLIP_CLAMP_TO_ZERO) rgb_clamp = [] for i in range(0, num_wl): color = colormodels.irgb_string_from_rgb( colormodels.rgb_from_xyz(xyz_colors[i])) rgb_clamp.append(color) # compare if verbose >= 1: print('colors from add white, colors from clamp') for i in range(0, num_wl): print(rgb_add_white[i], rgb_clamp[i]) print('Passed test_clipping()')
def spectrum_subplot (spectrum): '''Plot a spectrum, with x-axis the wavelength, and y-axis the intensity. The curve is colored at that wavelength by the (approximate) color of a pure spectral color at that wavelength, with intensity constant over wavelength. (This means that dark looking colors here mean that wavelength is poorly viewed by the eye. This is not a complete plotting function, e.g. no file is saved, etc. It is assumed that this function is being called by one that handles those things.''' (num_wl, num_cols) = spectrum.shape # get rgb colors for each wavelength rgb_colors = numpy.empty ((num_wl, 3)) for i in range (0, num_wl): wl_nm = spectrum [i][0] xyz = ciexyz.xyz_from_wavelength (wl_nm) rgb_colors [i] = colormodels.rgb_from_xyz (xyz) # scale to make brightest rgb value = 1.0 rgb_max = numpy.max (rgb_colors) scaling = 1.0 / rgb_max rgb_colors *= scaling # draw color patches (thin vertical lines matching the spectrum curve) in color for i in range (0, num_wl-1): # skipping the last one here to stay in range x0 = spectrum [i][0] x1 = spectrum [i+1][0] y0 = spectrum [i][1] y1 = spectrum [i+1][1] poly_x = [x0, x1, x1, x0] poly_y = [0.0, 0.0, y1, y0] color_string = colormodels.irgb_string_from_rgb (rgb_colors [i]) pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string) # plot intensity as a curve pylab.plot ( spectrum [:,0], spectrum [:,1], color='k', linewidth=2.0, antialiased=True)
def convolve_with_eye(wl, spectrum): # Construct 2d array for ColorPy spec = np.vstack([wl, spectrum]).T # Call ColorPy modules to get irgb string rgb_eye = colormodels.irgb_string_from_rgb ( colormodels.rgb_from_xyz (ciexyz.xyz_from_spectrum (spec))) return rgb_eye
def convolve_with_eye(wl, spectrum): # Construct 2d array for ColorPy spec = np.vstack([wl, spectrum]).T # Call ColorPy modules to get irgb string rgb_eye = colormodels.irgb_string_from_rgb( colormodels.rgb_from_xyz(ciexyz.xyz_from_spectrum(spec))) return rgb_eye
def test_xyz_irgb(verbose=1): '''Test the direct conversions from xyz to irgb.''' for i in range(0, 100): x0 = 10.0 * random.random() y0 = 10.0 * random.random() z0 = 10.0 * random.random() xyz0 = colormodels.xyz_color(x0, y0, z0) irgb0 = colormodels.irgb_from_rgb(colormodels.rgb_from_xyz(xyz0)) irgb1 = colormodels.irgb_from_xyz(xyz0) if (irgb0[0] != irgb1[0]) or (irgb0[1] != irgb1[1]) or (irgb0[2] != irgb1[2]): raise ValueError irgbs0 = colormodels.irgb_string_from_rgb( colormodels.rgb_from_xyz(xyz0)) irgbs1 = colormodels.irgb_string_from_xyz(xyz0) if irgbs0 != irgbs1: raise ValueError print('Passed test_xyz_irgb()')
def SpectrumToRGB(q,iq): #mask = np.logical_and(q > 300e-9,q<800e-9) x = np.arange(300,800,1) y = np.interp(x,q[::-1],iq[::-1]) #spec = np.vstack([2*np.pi/q[mask],np.log(iq[mask]*q[mask]**2)]) #spec = np.vstack([q[mask],iq[mask]]) spec = np.vstack([x,y]) xyz = xyz_from_spectrum(spec.T) return rgb_from_xyz(xyz_normalize(xyz))
def xyz_patch_plot ( xyz_colors, color_names, title, filename, patch_gap = 0.05, num_across = 6): '''Draw a set of color patches specified as xyz colors.''' rgb_colors = [] for xyz in xyz_colors: rgb = colormodels.rgb_from_xyz (xyz) rgb_colors.append (rgb) rgb_patch_plot (rgb_colors, color_names, title, filename, patch_gap=patch_gap, num_across=num_across)
def irgb_string_from_spectrum(wl, spectrum): """ Calculates the irgb color given a wavelengh [nm] vs intensity [W/m*m/um] spectrum in the visible. """ # Filter possible nans ifin = np.isfinite(spectrum) wl = wl[ifin] spectrum = spectrum[ifin] # Run through ColorPy spec = np.vstack([wl, spectrum]).T rgb_eye = colormodels.irgb_string_from_rgb ( colormodels.rgb_from_xyz (ciexyz.xyz_from_spectrum (spec))) return rgb_eye
def test_A(xyz0, tolerance=1.0e-10, verbose=1): rgb0 = colormodels.rgb_from_xyz(xyz0) xyz1 = colormodels.xyz_from_rgb(rgb0) rgb1 = colormodels.rgb_from_xyz(xyz1) # check errors err_rgb = rgb1 - rgb0 error_rgb = math.sqrt(numpy.dot(err_rgb, err_rgb)) err_xyz = xyz1 - xyz0 error_xyz = math.sqrt(numpy.dot(err_xyz, err_xyz)) passed = (error_rgb <= tolerance) and (error_xyz <= tolerance) if passed: status = 'pass' else: status = 'FAILED' msg = 'test_xyz_rgb.test_A() : xyz0 = %s, rgb(xyz0) = %s, xyz(rgb(xyz0)) = %s, rgb(xyz(rgb(xyz0))) = %s, errors = (%g, %g), %s' % ( str(xyz0), str(rgb0), str(xyz1), str(rgb1), error_rgb, error_xyz, status) if verbose >= 1: print(msg) if not passed: pass raise ValueError(msg) return passed
def rgb_from_wavelength(wl): """ Get rgb colors for each wavelength [nm] """ num_wl = len(wl) rgb_colors = np.empty ((num_wl, 3)) for i in range (0, num_wl): wl_nm = wl[i] xyz = ciexyz.xyz_from_wavelength (wl_nm) rgb_colors [i] = colormodels.rgb_from_xyz (xyz) # scale to make brightest rgb value = 1.0 rgb_max = np.max (rgb_colors) scaling = 1.0 / rgb_max rgb_colors *= scaling return rgb_colors
def blackbody_color_vs_temperature_plot(T_list, title, filename): '''Draw a color vs temperature plot for the given temperature range.''' num_T = len(T_list) rgb_list = numpy.empty((num_T, 3)) for i in range(0, num_T): T_i = T_list[i] xyz = blackbody_color(T_i) rgb_list[i] = colormodels.rgb_from_xyz(xyz) # Note that b and g become negative for low T. # MatPlotLib skips those on the semilog plot. plots.color_vs_param_plot(T_list, rgb_list, title, filename, plotfunc=pylab.semilogy, tight=True, xlabel=r'Temperature (K)', ylabel=r'RGB Color')
def spectrum_plot ( spectrum, title, filename, xlabel = 'Wavelength ($nm$)', ylabel = 'Intensity ($W/m^2$)'): '''Plot for a single spectrum - In a two part graph, plot: top: color of the spectrum, as a large patch. low: graph of spectrum intensity vs wavelength (x axis). The graph is colored by the (approximated) color of each wavelength. Each wavelength has equal physical intensity, so the variation in apparent intensity (e.g. 400, 800 nm are very dark, 550 nm is bright), is due to perceptual factors in the eye. This helps show how much each wavelength contributes to the percieved color. spectrum - spectrum to plot title - title for plot filename - filename to save plot to xlabel - label for x axis ylabel - label for y axis ''' pylab.clf () # upper plot - solid patch of color that matches the spectrum color pylab.subplot (2,1,1) pylab.title (title) color_string = colormodels.irgb_string_from_rgb ( colormodels.rgb_from_xyz (ciexyz.xyz_from_spectrum (spectrum))) poly_x = [0.0, 1.0, 1.0, 0.0] poly_y = [0.0, 0.0, 1.0, 1.0] pylab.fill (poly_x, poly_y, color_string) # draw a solid line around the patch to look nicer pylab.plot (poly_x, poly_y, color='k', linewidth=2.0) pylab.axis ('off') # lower plot - spectrum vs wavelength, with colors of the associated spectral lines below pylab.subplot (2,1,2) spectrum_subplot (spectrum) tighten_x_axis (spectrum [:,0]) pylab.xlabel (xlabel) pylab.ylabel (ylabel)
def visible_spectrum_plot (): '''Plot the visible spectrum, as a plot vs wavelength.''' spectrum = ciexyz.empty_spectrum() (num_wl, num_cols) = spectrum.shape # get rgb colors for each wavelength rgb_colors = numpy.empty ((num_wl, 3)) for i in range (0, num_wl): xyz = ciexyz.xyz_from_wavelength (spectrum [i][0]) rgb = colormodels.rgb_from_xyz (xyz) rgb_colors [i] = rgb # scale to make brightest rgb value = 1.0 rgb_max = numpy.max (rgb_colors) scaling = 1.0 / rgb_max rgb_colors *= scaling # plot colors and rgb values vs wavelength color_vs_param_plot ( spectrum [:,0], rgb_colors, 'The Visible Spectrum', 'VisibleSpectrum', tight = True, xlabel = r'Wavelength (nm)', ylabel = r'RGB Color')
def generate_map2d(hue_quantity, lightness_quantity, hue_cmap, hue_range=None, lightness_range=None, scale_min=0, scale_max=100): ''' Given an existing color map, and two ranges of values, map the first range to hue, and the second to lightness by scaling the first component of the CIELab expression for the colors representing each hue. Parameters ---------- hue_quantity : array of floats, values to map to hue lightness_quantity : array of floats, values to map to lightness hue_cmap : colormap object, gradient of colors defining the range of hues hue_range : list, minimum and maximum of normalization for hue mapping lightness_range : list, minimum and maximum of normalization for hue mapping scale_min : float, minimum perceived lightness (0-100) scale_max : float, maximum perceived lightness (0-100) Returns ------- rgb_maps : array of RGB colors, same shape as quantity ''' if hue_range is None: hue_range = [np.nanmin(hue_quantity), np.nanmax(hue_quantity)] if lightness_range is None: lightness_range = [np.nanmin(lightness_quantity), np.nanmax(lightness_quantity)] if (scale_min < 0 or scale_min > 100): raise Exception('The scale minimum is invalid!') if (scale_max < 0 or scale_max > 100): raise Exception('The scale maximum is invalid!') if (scale_min > scale_max): raise Exception('The scale minimum should be less than ' + 'or equal to the scale maximum.') hue_scale = colors.Normalize(*hue_range) hue_map = cm.ScalarMappable(hue_scale, cmap=hue_cmap).get_cmap() hues = hue_map(hue_quantity) colors_CIElab = np.zeros(np.r_[hues.shape[:-1], 3]) for index in np.ndindex(hues.shape[:-1]): colors_CIElab[index] = colormodels.lab_from_xyz( colormodels.xyz_from_rgb(hues[index][:-1])) lightness = lightness_quantity / \ (np.ptp(lightness_range) / (scale_max - scale_min)) - \ (np.nanmin(lightness_range) - scale_min) lightness[lightness < scale_min] = scale_min lightness[lightness > scale_max] = scale_max colors_CIElab[..., 0] = lightness rgb_maps = np.ones(np.r_[hue_quantity.shape, 4]) for index in np.ndindex(colors_CIElab.shape[:-1]): rgb_maps[index][:3] = [ colormodels.srgb_gamma_invert(c) for c in colormodels.rgb_from_xyz( colormodels.xyz_from_lab(colors_CIElab[index])) ] rgb_maps[rgb_maps < 0] = 0 rgb_maps[rgb_maps > 1] = 1 return rgb_maps
def plot_spectrum(wl, spectrum, wlmin=350, wlmax=750, stellar_spec=None, show_cie=False, xtitle="Wavelength [nm]", ytitle="Intensity", title="", **kwargs): """ Plots intensity [W/m*m/um] vs wavelength [nm] across the visible, shading the background above the curve the color the human eye would perceive, and the entire visible spectrum below the curve. Returns Figure object for saving and further artistry. Parameters ---------- wl : array Wavelength grid [nm] spectrum : array Intensity spectrum [W / m^2 / um] wlmin : float Minimum wavelength plotted [nm] wlmax : float Maximum wavelength plotted [nm] show_cie : bool Adds overplotted CIE eye sensitivity curves for reference xtitle : str x-axis label ytitle : str y-axis label title : str Plot title Returns ------- matplotlib.figure.Figure """ if np.min(wl) > wlmin: wlmin = np.min(wl) if np.max(wl) < wlmax: wlmax = np.max(wl) # Mask wl region mask = (wl >= wlmin) & (wl <= wlmax) wl = wl[mask] spectrum = spectrum[mask] # Filter possible nans ifin = np.isfinite(spectrum) wl = wl[ifin] spectrum = spectrum[ifin] # Read-in solar spectrum if stellar_spec is None: pass elif stellar_spec == "Sun": data = np.genfromtxt("spectra/earth_quadrature_radiance_refl.dat", skip_header=8) wl_solar = data[:,0] * 1000.0 # Convert microns to nm F_solar = data[:,2] # Interpolate sun to CMF F_solar = np.interp(wl, wl_solar, F_solar) # Multiply Albedo and Flux spectrum = spectrum * F_solar else: print("Given stellar_spec is not included.") # Convert Flux to photon counts umnm = 1e-3 hc = 1.986446e-25 # h*c (kg*m**3/s**2) #spectrum = spectrum * umnm * wl / hc # Plot spectrum fig = plt.figure(figsize=(12,8)) gs = gridspec.GridSpec(1,1) ax1 = plt.subplot(gs[0]) ax1.set_xlim([wlmin, wlmax]) num_wl = len(wl) # rgb_colors = rgb_from_wavelength(wl) # spec = np.vstack([wl, spectrum]).T rgb_eye = colormodels.irgb_string_from_rgb ( colormodels.rgb_from_xyz (ciexyz.xyz_from_spectrum (spec))) # draw color patches (thin vertical lines matching the spectrum curve) in color for i in range (0, num_wl-1): # skipping the last one here to stay in range x0 = wl [i] x1 = wl [i+1] y0 = spectrum [i] y1 = spectrum [i+1] poly_x = [x0, x1, x1, x0] poly_y = [0.0, 0.0, y1, y0] color_string = colormodels.irgb_string_from_rgb (rgb_colors[i]) ax1.fill (poly_x, poly_y, color_string, edgecolor=color_string) # plot intensity as a curve ax1.plot ( wl, spectrum, color='k', linewidth=1.0, antialiased=True) # plot CIE response curves if show_cie: plot_response(ax=ax1, wlmin=wlmin, wlmax=wlmax) ax1.set_xlabel(xtitle) ax1.set_ylabel(ytitle) ax1.set_title(title) ax1.set_xlim([wlmin, wlmax]) # Set plot background color to derived rgb color #set_figure_colors(fig, foreground="white", background="black") ax1.patch.set_facecolor(rgb_eye) return fig
def SpectrumToRGB(q, iq): x = np.arange(300, 800, 1) y = np.interp(x, q[::-1], iq[::-1]) spec = np.vstack([x, y]) xyz = xyz_from_spectrum(spec.T) return rgb_from_xyz(xyz_normalize(xyz))
def shark_fin_plot (): '''Draw the 'shark fin' CIE chromaticity diagram of the pure spectral lines (plus purples) in xy space.''' # get array of (approximate) colors for the boundary of the fin xyz_list = ciexyz.get_normalized_spectral_line_colors (brightness=1.0, num_purples=200, dwl_angstroms=2) # get normalized colors xy_list = xyz_list.copy() (num_colors, num_cols) = xy_list.shape for i in range (0, num_colors): colormodels.xyz_normalize (xy_list [i]) # get phosphor colors and normalize red = colormodels.PhosphorRed green = colormodels.PhosphorGreen blue = colormodels.PhosphorBlue white = colormodels.PhosphorWhite colormodels.xyz_normalize (red) colormodels.xyz_normalize (green) colormodels.xyz_normalize (blue) colormodels.xyz_normalize (white) def get_direc_to_white (xyz): '''Get unit vector (xy plane) in direction of the white point.''' direc = white - xyz mag = math.hypot (direc [0], direc [1]) if mag != 0.0: direc /= mag return (direc[0], direc[1]) # plot pylab.clf () # draw best attempt at pure spectral colors on inner edge of shark fin s = 0.025 # distance in xy plane towards white point for i in range (0, len (xy_list)-1): x0 = xy_list [i][0] y0 = xy_list [i][1] x1 = xy_list [i+1][0] y1 = xy_list [i+1][1] # get unit vectors in direction of white point (dir_x0, dir_y0) = get_direc_to_white (xy_list [i]) (dir_x1, dir_y1) = get_direc_to_white (xy_list [i+1]) # polygon vertices poly_x = [x0, x1, x1 + s*dir_x1, x0 + s*dir_x0] poly_y = [y0, y1, y1 + s*dir_y1, y0 + s*dir_y0] # draw (using full color, not normalized value) color_string = colormodels.irgb_string_from_rgb ( colormodels.rgb_from_xyz (xyz_list [i])) pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string) # fill in the monitor gamut with true colors 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 def fill_gamut_slice (v0, v1, v2): '''Fill in a slice of the monitor gamut with the correct colors.''' #num_s, num_t = 10, 10 #num_s, num_t = 25, 25 num_s, num_t = 50, 50 dv10 = v1 - v0 dv21 = v2 - v1 for i_s in range (num_s): s_a = float (i_s) / float (num_s) s_b = float (i_s+1) / float (num_s) for i_t in range (num_t): t_a = float (i_t) / float (num_t) t_b = float (i_t+1) / float (num_t) # vertex coords v_aa = v0 + t_a * (dv10 + s_a * dv21) v_ab = v0 + t_b * (dv10 + s_a * dv21) v_ba = v0 + t_a * (dv10 + s_b * dv21) v_bb = v0 + t_b * (dv10 + s_b * dv21) # poly coords poly_x = [v_aa [0], v_ba [0], v_bb [0], v_ab [0]] poly_y = [v_aa [1], v_ba [1], v_bb [1], v_ab [1]] # average color avg = 0.25 * (v_aa + v_ab + v_ba + v_bb) # convert to rgb and scale to maximum displayable brightness color_string = get_brightest_irgb_string (avg) pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string) fill_gamut_slice (white, blue, green) fill_gamut_slice (white, green, red) fill_gamut_slice (white, red, blue) # draw the curve of the xy values of the spectral lines and purples pylab.plot (xy_list [:,0], xy_list [:,1], color='#808080', linewidth=3.0) # draw monitor gamut and white point pylab.plot ([red [0], green[0]], [red [1], green[1]], 'o-', color='k') pylab.plot ([green[0], blue [0]], [green[1], blue [1]], 'o-', color='k') pylab.plot ([blue [0], red [0]], [blue [1], red [1]], 'o-', color='k') pylab.plot ([white[0], white[0]], [white[1], white[1]], 'o-', color='k') # label phosphors dx = 0.01 dy = 0.01 pylab.text (red [0] + dx, red [1], 'Red', ha='left', va='center') pylab.text (green [0], green [1] + dy, 'Green', ha='center', va='bottom') pylab.text (blue [0] - dx, blue [1], 'Blue', ha='right', va='center') pylab.text (white [0], white [1] + dy, 'White', ha='center', va='bottom') # titles etc pylab.axis ([0.0, 0.85, 0.0, 0.85]) pylab.xlabel (r'CIE $x$') pylab.ylabel (r'CIE $y$') pylab.title (r'CIE Chromaticity Diagram') filename = 'ChromaticityDiagram' print ('Saving plot %s' % (str (filename))) pylab.savefig (filename)
def rgb_from_spectrum(array_1D): retset = np.vstack([idx, array_1D]).T return rgb_from_xyz(xyz_from_spectrum(retset))*np.max(array_1D)
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()
from colorpy import colormodels from math import cos, sin, pi, ceil import csv sti_cols = [] colors = [] rgb_colors = [] for i in xrange(180): L = 70.0 a = cos(i * pi / 90) * 40 + 5 b = sin(i * pi / 90) * 40 xyz = colormodels.xyz_from_lab([L, a, b]) rgb = colormodels.rgb_from_xyz(xyz) irgb = colormodels.irgb_from_rgb(rgb) # convert to psychopy range (-1 - 1) rgb_colors.append(irgb) colors.append(rgb * 2 - 1) if i % 15 == 0: sti_cols.append(rgb * 2 - 1) # Pick X colors at max distance (including 2 slightly jittered version of that color) no_colors = 8 # Number of colors jitter = 12 # how much jitter exp_colors = [] for i in range(0, 180, int(ceil(180.0 / no_colors))): # Left probe