function colormapConstantHue = obtainColormapMonochrome(nColor, baseColorRgb, varargin)
% obtain a colormap with constant hue, based on a given RGB color

% the original implementation was too complicated, changed it.

%% take over input color
baseColorHsvVector = rgb2hsv(baseColorRgb);
baseColorHue = baseColorHsvVector(1);
baseColorSaturation = baseColorHsvVector(2);
baseColorValue = baseColorHsvVector(3);

if nargin == 3
    powerDark = varargin{1}(1);
    powerLight = varargin{1}(2);
else
    powerDark = 1;
    powerLight = 1;
end

% the general idea is:
%  1) input color is ALWAYS in the middle
%  2) the first part starts from saturation 0 to input saturation
%  3) the second part goes from input value (blackness) to 
%     value=0 (=black)
saturationVector = min(linspace(0,2,nColor).^powerLight, 1) * baseColorSaturation;
valueVector = min(linspace(2,0,nColor).^powerDark, 1) * baseColorValue;
hueVector = valueVector*0 + baseColorHue;

% Old code:
% saturationVector = min(linspace(0,2,nColor), 1) * baseColorSaturation;
% valueVector = min(linspace(2,0,nColor), 1) * baseColorValue;
% hueVector = valueVector*0 + baseColorHue;

% construct colormap
colormapConstantHue = hsv2rgb(...
    [hueVector', saturationVector', valueVector']);
colormapConstantHue = colormapConstantHue(end:-1:1, :);

% correct colormap to avoid "pure black"
colormapConstantHue(1,:) = colormapConstantHue(1,:) + 0.001;
%colormapConstantHue(end,:) = colormapConstantHue(end,:) + 0.001;
