diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-07-08 00:01:34 -0400 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-07-08 00:01:34 -0400 |
commit | 03730c1a202462c87a7e345f911d459483cc3220 (patch) | |
tree | b4048fe825046ab3e70a59d27bf964f5aac9ed12 | |
parent | d2eb39214dfd2acf957a69e58bba21f06e2bda84 (diff) | |
download | wgmr-03730c1a202462c87a7e345f911d459483cc3220.tar.gz wgmr-03730c1a202462c87a7e345f911d459483cc3220.zip |
color from base color gradient function
-rw-r--r-- | color_gradient.m | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/color_gradient.m b/color_gradient.m new file mode 100644 index 0000000..310ff99 --- /dev/null +++ b/color_gradient.m @@ -0,0 +1,31 @@ +function rgb= color_gradient( pos, base_color_rgb, Ncolors ) +%% returns rgb=[R,G,B] components from the brightness gradient of the base color +% base_color_rgb - [R,G,B] of the base color +% Ncolors - number of positions in gradient + + %% color map as gradient of particular color + % starting values + hsv_s=rgb2hsv(base_color_rgb); + hue_f = hsv_s(1); + sat_f = hsv_s(2); + val_f = hsv_s(3); + % stop values + hue_s = hue_f; + sat_s = 0; + val_s = 1; + hue=linspace(hue_s,hue_f, Ncolors); + sat=linspace(sat_s,sat_f, Ncolors); + val=linspace(val_s,val_f, Ncolors); + cmap = hsv2rgb([hue', sat', val']); + + %% check that pos is with in the reach + pos = floor(pos); + if( pos < 1 ) + pos=1; + end + if( pos > Ncolors ) + pos=Ncolors; + end + + rgb = cmap(pos,:); +end |