1 |
function [c] = cm_landwater(n,varargin) |
2 |
% [c] = cm_landwater(n) |
3 |
% [c] = cm_landwater(n,f) |
4 |
% |
5 |
% n - is size of color map |
6 |
% f is scalar fraction that should be water (default=0.5) |
7 |
% or vector [hmin hmax] from which f will be calculated |
8 |
% |
9 |
% e.g. |
10 |
% >> cm_landwater(64,caxis); |
11 |
% |
12 |
% Green-yellor land/blue water colormap |
13 |
|
14 |
if nargin==1 |
15 |
f=0.5; |
16 |
else |
17 |
f=varargin{1}; |
18 |
end |
19 |
|
20 |
if prod(size(f))==2 |
21 |
hmin=f(1);hmax=f(2); |
22 |
f=-hmin/(hmax-hmin); |
23 |
f=max(0,f);f=min(1,f); |
24 |
end |
25 |
|
26 |
if mod(n,2)==0 |
27 |
nb=round(n*f(1)); |
28 |
ng=n-nb; |
29 |
nw=0; |
30 |
else |
31 |
nb=floor(n*f(1)); |
32 |
nw=1; |
33 |
ng=n-nb-nw; |
34 |
end |
35 |
b=bluewater(nb); |
36 |
g=greenland(ng); |
37 |
w=ones(nw,1)*[1 1 0.55]; |
38 |
|
39 |
c=[b' w' g']'; |
40 |
if nargout==0 |
41 |
colormap(c); |
42 |
end |
43 |
|
44 |
%subplot(211) |
45 |
%plot((0:(n-1))/(n-1),c(:,3:-1:1)) |
46 |
%subplot(212) |
47 |
%pcol([-1:.1/n:1]) |
48 |
%axis off |
49 |
|
50 |
% ---------------------------------------------------- |
51 |
function [c] = bluewater(n) |
52 |
% Blue colormap |
53 |
|
54 |
x=(0:n-1)'/(n-1); |
55 |
c=((.7-.7*x)*[1 1 0]+max(0,(1-.65*x))*[0 0 1]); |
56 |
c=c(end:-1:1,:); |
57 |
%colormap(c); |
58 |
% ---------------------------------------------------- |
59 |
function [c] = greenland(n) |
60 |
% Green land colormap |
61 |
|
62 |
x=(0:n-1)'/(n-1); |
63 |
r=max(0,(-.25+1.8*x)); |
64 |
g=.4*(1+2.5*x); |
65 |
b=0.5*max(0,(-.25+2.0*x)); |
66 |
i=find(r>1); |
67 |
r(i)=max( 1.7-1*x(i), b(i)); |
68 |
i=find(g>1); |
69 |
g(i)=max( 1.5-1*x(i), b(i)); |
70 |
c=r*[1 0 0]+g*[0 1 0]+b*[0 0 1]; |
71 |
c=min(max(0,c),1); |
72 |
%colormap(c); |
73 |
% ---------------------------------------------------- |