Home > atmlab > handy > list_colors.m

list_colors

PURPOSE ^

LIST_COLORS Creates a cell of rgb vectors

SYNOPSIS ^

function vectcolors = list_colors(varargin)

DESCRIPTION ^

 LIST_COLORS Creates a cell of rgb vectors

 PURPOSE:
         From a cell of string arguments create a cell of rgb vectors for the
         corresponding colors from the following table. Can also pass rogue rgb
         vectors amongst color markers. e.g
         strcolors = {'r',[.1 .1 .1],'k','b'}
 
 IN      1) Either requested number of colors is given: list_colors('Ncolors',n)
         
         2) Or the colors are given in short string arguments. e.g 
               list_colors('Colors',{'r','b'}), but the colors most be in the
               colors list. see bellow for available colors
 
 OUT     vector of rgb colors
 
 Available colors (add more?)
 longname  | shortname | vector
           |           |
 black     | 'k'       | [0,0,0]
 green     | 'g'       | [0,1,0]
 red       | 'r'       | [1,0,0]
 blue      | 'b'       | [0,0,1]
 cyan      | 'c'       | [0,1,1]
 magenta   | 'm'       | [1,0,1]
 yellow    | 'y'       | [1,1,0]
 white     | 'w'       | [1,1,1]
 red-purple| 'rp'      | [.8 .5 .8]
 grey      | 'gr'      | [.5 .5 .5]
 purple    | 'p'       | [.8 0 1]
 orange    | 'o'       | [1 .7 0]
 caucasian | 'ca'      | [1 .5 .5]
 pink      | 'pi'      | [1 .5 1]
 
 default loop of colors: colors={'k','g','r','b','c','m','y','rp','gr','p','o','ca','pi'};
 
 Created by Salomon Eliasson
 $Id: list_colors.m 6901 2011-05-02 07:40:00Z seliasson $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

list_colors.m

SOURCE CODE ^

0001 function vectcolors = list_colors(varargin)
0002 % LIST_COLORS Creates a cell of rgb vectors
0003 %
0004 % PURPOSE:
0005 %         From a cell of string arguments create a cell of rgb vectors for the
0006 %         corresponding colors from the following table. Can also pass rogue rgb
0007 %         vectors amongst color markers. e.g
0008 %         strcolors = {'r',[.1 .1 .1],'k','b'}
0009 %
0010 % IN      1) Either requested number of colors is given: list_colors('Ncolors',n)
0011 %
0012 %         2) Or the colors are given in short string arguments. e.g
0013 %               list_colors('Colors',{'r','b'}), but the colors most be in the
0014 %               colors list. see bellow for available colors
0015 %
0016 % OUT     vector of rgb colors
0017 %
0018 % Available colors (add more?)
0019 % longname  | shortname | vector
0020 %           |           |
0021 % black     | 'k'       | [0,0,0]
0022 % green     | 'g'       | [0,1,0]
0023 % red       | 'r'       | [1,0,0]
0024 % blue      | 'b'       | [0,0,1]
0025 % cyan      | 'c'       | [0,1,1]
0026 % magenta   | 'm'       | [1,0,1]
0027 % yellow    | 'y'       | [1,1,0]
0028 % white     | 'w'       | [1,1,1]
0029 % red-purple| 'rp'      | [.8 .5 .8]
0030 % grey      | 'gr'      | [.5 .5 .5]
0031 % purple    | 'p'       | [.8 0 1]
0032 % orange    | 'o'       | [1 .7 0]
0033 % caucasian | 'ca'      | [1 .5 .5]
0034 % pink      | 'pi'      | [1 .5 1]
0035 %
0036 % default loop of colors: colors={'k','g','r','b','c','m','y','rp','gr','p','o','ca','pi'};
0037 %
0038 % Created by Salomon Eliasson
0039 % $Id: list_colors.m 6901 2011-05-02 07:40:00Z seliasson $
0040 
0041 colors={'k','g','r','b','c','m','y','rp','gr','p','o','ca','pi'};
0042 if ~nargin
0043     varargin = {'Ncolors',length(colors)};
0044 end
0045 
0046 
0047 %% LOAD CUSTOM OPTIONS:
0048 for iopt = 1 : 2 : length(varargin)
0049     optname  = varargin{iopt};
0050     optvalue = varargin{iopt+1};
0051     switch lower(optname)
0052         case 'colors'
0053             strcolors=optvalue;
0054         case 'ncolors'
0055             k=1;
0056             strcolors=cell(optvalue,1);
0057             for ii=1:optvalue
0058                 strcolors{ii}=colors{k};
0059                 k=k+1;
0060                 if k==length(colors),k=1;end
0061             end
0062     end
0063 end
0064 
0065 
0066 vectcolors=cell(length(strcolors),1);
0067 for i=1:length(strcolors)                                                       % Create vectors of colors
0068     if ~ischar(strcolors{i})
0069         vectcolors{i}=strcolors{i};
0070     else
0071         switch strcolors{i}
0072             case 'k', vectcolors{i}=[0 0 0];   % black
0073             case 'g', vectcolors{i}=[0 1 0];   % green
0074             case 'r', vectcolors{i}=[1 0 0];   % red
0075             case 'b', vectcolors{i}=[0 0 1];   % blue
0076             case 'c', vectcolors{i}=[0 1 1];   % cyan
0077             case 'm', vectcolors{i}=[1 0 1];   % magenta
0078             case 'y', vectcolors{i}=[1 1 0];   % yellow
0079             case 'w', vectcolors{i}=[1 1 1];   % white
0080             case 'rp',vectcolors{i}=[.8 .5 .8];% redish purple
0081             case 'gr',vectcolors{i}=[.5 .5 .5];% grey
0082             case 'p', vectcolors{i}=[.8 0 1];  % purple
0083             case 'o', vectcolors{i}=[1 .7 0];  % orange
0084             case 'ca',vectcolors{i}=[1 .5 .5]; % caucasian
0085             case 'pi',vectcolors{i}=[1 .5 1];  % pink
0086             otherwise
0087                 error('color: %s not in list. add color to mfile?',strcolors{i})
0088         end
0089     end
0090 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005