% Filename:	campenColorMap.m
% Author:	Curt Blais (adapted from sample by Don Brutzman)
% Created:	11 April 2001
% Revised:	27 September 2001
% Utilized:     11 October 2001 by James Harney for Aden Harbor, Yemen geo.
% Description:	Coloration of Camp Pendleton terrain using color sampling from photo images taken 
%               in Dec 2000 for the beach area, but green to brown coloration for hills.

function rgbValue = colorValue (elevationInMeters, elevationRange);

     spacer = '\t';
     foliage = 0.05; %abundance of greenery in higher elevations

% some helpful color-value definitions available at
% http://www.w3.org/TR/1998/REC-html40-19980424/types.html#idx-color

% The following sampled colors are from photographs by Jeff Weekley, Rolands and Associates, 
% taken at Camp Pendleton, Dec 2000 (red-green-blue values are between 0 and 255)
% Sand 		238 227 213-221
%     		203 201 204
% Dunes		177 172 166
%    		157 141 151
% Hillocks	161 175 184
%   		170 190 191
% Hills
% above Hiway	210 205 209
%       		205 205 205
% Intermediate Bands of
% Greenery	146 162 149
%   		132 151 145
%		    180 192 182
%		    74 107 114
%		    64 90 103
%		    114 81 62
% Mountain Tops	230 221 222
%       		110 81 71
%		        175 172 160

% colors converted to values between 0 and 1
sand(1).r = 0.9333; sand(1).g = 0.8902; sand(1).b = 0.8353;
sand(2).r = 0.9333; sand(2).g = 0.8902; sand(2).b = 0.8667;
sand(3).r = 0.7961; sand(3).g = 0.7882; sand(3).b = 0.8000;
dunes(1).r = 0.6941; dunes(1).g = 0.6745; dunes(1).b = 0.6510;
dunes(2).r = 0.6157; dunes(2).g = 0.5529; dunes(2).b = 0.5922;
hillocks(1).r = 0.6314; hillocks(1).g = 0.6863; hillocks(1).b = 0.7612;
hillocks(2).r = 0.6667; hillocks(2).g = 0.7451; hillocks(2).b = 0.7490;
hills(1).r = 0.8235; hills(1).g = 0.8039; hills(1).b = 0.8196;
hills(2).r = 0.8039; hills(2).g = 0.8039; hills(2).b = 0.8039;
greenery(1).r = 0.5725; greenery(1).g = 0.6353; greenery(1).b = 0.5843;
greenery(2).r = 0.5176; greenery(2).g = 0.5922; greenery(2).b = 0.5686;
greenery(3).r = 0.7059; greenery(3).g = 0.7529; greenery(3).b = 0.7137;
greenery(4).r = 0.2902; greenery(4).g = 0.4196; greenery(4).b = 0.4471;
greenery(5).r = 0.2510; greenery(5).g = 0.3529; greenery(5).b = 0.4039;
greenery(6).r = 0.4471; greenery(6).g = 0.3176; greenery(6).b = 0.2431;
mounts(1).r = 0.9020; mounts(1).g = 0.8667; mounts(1).b = 0.8706;
mounts(2).r = 0.4314; mounts(2).g = 0.3176; mounts(2).b = 0.2784;
mounts(3).r = 0.6863; mounts(3).g = 0.6745; mounts(3).b = 0.6275;
   

    band = ( elevationRange - 20 ) / 6.0; % different shades of green for the different elevation bands
    % retain original shading at shoreline
    if    (elevationInMeters < 0)	rgbValue = ' .2 .5 .7 ';		% blue-green
    elseif (elevationInMeters < 20) % sand
        r = floor(rand*3+0.5)+1;
        if (r > 3) r = 3; end;
        rgbValue = strcat( spacer, num2str(sand(r).r), spacer, num2str(sand(r).g), spacer, num2str(sand(r).b) );
    % use green shades for increasing elevations    
    elseif ( elevationInMeters < 20 + band )
        rgbValue = strcat( spacer, num2str(greenery(1).r), spacer, num2str(greenery(1).g), spacer, num2str(greenery(1).b) );
    elseif ( elevationInMeters < 20 + band*2 )
        rgbValue = strcat( spacer, num2str(greenery(2).r), spacer, num2str(greenery(2).g), spacer, num2str(greenery(2).b) );
    elseif ( elevationInMeters < 20 + band*3 )
        rgbValue = strcat( spacer, num2str(greenery(3).r), spacer, num2str(greenery(3).g), spacer, num2str(greenery(3).b) );
    elseif ( elevationInMeters < 20 + band*4 )
        rgbValue = strcat( spacer, num2str(greenery(4).r), spacer, num2str(greenery(4).g), spacer, num2str(greenery(4).b) );
    elseif ( elevationInMeters < 20 + band*5 )
        rgbValue = strcat( spacer, num2str(greenery(5).r), spacer, num2str(greenery(5).g), spacer, num2str(greenery(5).b) );
    elseif ( elevationInMeters < 60 + band*6 )
        rgbValue = strcat( spacer, num2str(greenery(6).r), spacer, num2str(greenery(6).g), spacer, num2str(greenery(6).b) );
    else % mountain tops
        %r = floor(rand*3+0.5)+1;
        %if (r > 3) r = 3; end;
        moreGreen = greenery(6).g + (1.0 - greenery(6).g)*(elevationInMeters/elevationRange)
        rgbValue = strcat( spacer, num2str(greenery(6).r), spacer, moreGreen, spacer, num2str(greenery(6).b) );
	end;		
    
return;