From 1a1498b82c664dbdfd8da45cb9e6816a816e8dbf Mon Sep 17 00:00:00 2001 From: Steven Williams Date: Wed, 3 Feb 2021 07:17:27 +0000 Subject: [PATCH] Moved colorBrewer so it can be accessed from command line and added the missing function colorspec2rgb, relating to Issue #24 --- private/colorBrewer.m => colorBrewer.m | 0 private/colorspec2rgb.m | 54 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) rename private/colorBrewer.m => colorBrewer.m (100%) create mode 100644 private/colorspec2rgb.m diff --git a/private/colorBrewer.m b/colorBrewer.m similarity index 100% rename from private/colorBrewer.m rename to colorBrewer.m diff --git a/private/colorspec2rgb.m b/private/colorspec2rgb.m new file mode 100644 index 0000000..5cbc6a3 --- /dev/null +++ b/private/colorspec2rgb.m @@ -0,0 +1,54 @@ +function rgb = colorspec2rgb(c) +% COLORSPEC2RGB converts a colorspec to truecolor. +% Usage: +% rgb = colorspec2rgb(c) +% Where: +% c is a color - either rgb or any of the letters in 'rgbwcmyk' +% +% COLORSPEC2RGB converts a character colorspec into a truecolor rgb +% representation. If c is not a character then it is returned as rgb - so +% that it will not affect index or truecolor variables that are input. +% +% Author: Nick Linton (2011) +% Modifications - + + +rgbspec = [1 0 0;0 1 0;0 0 1;1 1 1;0 1 1;1 0 1;1 1 0;0 0 0]; +cspec = 'rgbwcmyk'; + +% Deal with string color specifications. +if ischar(c), + k = find(cspec==c(1)); + if isempty(k) + error('COLORSPEC2RGB: Unknown color string.'); + end + if k~=3 || length(c)==1, + rgb = rgbspec(k,:); + elseif length(c)>2, + if strcmpi(c(1:3),'bla') + rgb = [0 0 0]; + elseif strcmpi(c(1:3),'blu') + rgb = [0 0 1]; + else + error('COLORSPEC2RGB: Unknown color string.'); + end + end +elseif isreal(c) && size(c,2)==3 + rgb = c; +else + error('COLORSPEC2RGB: Unknown color format.'); +end + + + + + + + + + + + + + +