1D RGB color gradient
1D (univariate) continous ( smooth) color gradients ( colormaps) implemented in c and gnuplot for:
and how to manipulate them ( invert, join, turned into a cyclic or wrapped color gradient )
Why Should Engineers and Scientists Be Worried About Color? by Rogowitz & Treinish 1996
What should and what should not do colormap/gradient in scientific visualisation?
Gradient function:
double ModifyPosition(const double position, const GradientJoiningType GradientJoining){
// input position should be in [0,1] range
double p = position; // p = local copy of position
// if position > 1 then we have repetition of colors = periodic function = wave
switch(GradientJoining){
case no : {break;} // return input position witout modifications
// periodic waves with different joinings
case steps : { p = p * segments; // periodic = change range
p = frac(p);
break;}
case tubes : { p = p * segments; // periodic = change range
int ip = (int)p;
p = p-ip; // fractional part
if (ip % 2) {p = 1.0-p;} // reverse gradient
break;}
default:{}
}
return p; // output in [0,1] range
}
Examples
Example videos by Maths Town:
Examples by hue:
Multihue = rainbows
NoHue = Gray
single hue
// d.c
// multihue
case RainbowHSV: {GiveRGB_RainbowHSV(p, rgb); break;}
case Linas: {GiveRGB_Linas(p, rgb); break;}
case Linas2: {GiveRGB_Linas2(p, rgb); break;}
case RainbowFractalizer:{GiveRGB_RainbowFractalizer(p, rgb); break;} //
case OrangeBlueFractalizer: {GiveRGB_OrangeBlueFractalizer(p, rgb); break;}
case Magma: {GiveRGB_Magma(p, rgb); break;}
case Cubehelix: {GiveRGB_Cubehelix(p, rgb); break;}
case RainbowHSP: {GiveRGB_RainbowHSP(p, rgb); break;}
case HSP: {GiveRGB_HSP(p, rgb); break;}
// diverging
case CoolWarm: {GiveRGB_CoolWarm(p, rgb); break;}
// single hue
case GreenCubic: {GiveRGB_GreenCubic(p, rgb); break;}
case GreenCubicInv: {GiveRGB_GreenCubicInv(p, rgb); break;}
case GreenCubicRoot: {GiveRGB_GreenCubicRoot(p, rgb); break;}
case BlueCubicInv: {GiveRGB_BlueCubicInv(p, rgb); break;}
case RedCubicInv: {GiveRGB_RedCubicInv(p, rgb); break;}
case GreenSin: {GiveRGB_GreenSin(p, rgb); break;}
// no hue = gray, one function for all gray gradients
case Linear:
case Quadratic:
case Cubic:
case CubicInv:
case Sqrt:
case Root:
case Gamma:
case Sin:
case LSin:
case SinExp:
case Smooth:
Tanh : {GiveRGB_Gray(p, ColorTransferFunction, rgb); break;}
Rainbow
Compare with gnuplot image
Features of rainbow gradient:
set palette model HSV functions gray,1,1
or in C#
for(double i = 0; i < 1; i+=0.01)
{
ColorRGB c = HSL2RGB(i, 0.5, 0.5);
//do something with the color
}
Description by Laurence Gonsalves
>
It can be done directly in RGB space by a linear interpolation (in RGB) between each consecutive pair in this sequence:
Note that only one component changes for each interpolation, which simplifies things.
>
linear-gradient(to right, red,orange,yellow,green,blue,indigo,violet);
or python:
def rainbow():
r, g, b = 255, 0, 0
for g in range(256):
yield r, g, b
for r in range(255, -1, -1):
yield r, g, b
for b in range(256):
yield r, g, b
for g in range(255, -1, -1):
yield r, g, b
for r in range(256):
yield r, g, b
for b in range(255, -1, -1):
yield r, g, b
var spaces = [
{
name: "Rainbow (HSL)",
color: function(t) {
return d3.hsl(t * 360, 1, .5);
}
},
{
name: "Rainbow (HCL)",
color: function(t) {
return d3.hcl(t * 360, 100, 55);
}
},
{
name: "Rainbow (Cubehelix)",
color: d3.scale.cubehelix()
.domain([0, .5, 1])
.range([
d3.hsl(-100, 0.75, 0.35),
d3.hsl( 80, 1.50, 0.80),
d3.hsl( 260, 0.75, 0.35)
])
}
];
Your new colormap is different and ugly-ish. The line between red-and-yellow is much much worse than before. the red-yellow discontinuity is … confusing, annoying. .. to me, at least. Linas
Features of Linas gradient:
0.743333 210 166 0
0.746667 210 166 0
0.750000 210 166 0
0.753333 210 166 0
0.756667 210 150 0
0.760000 210 150 0
0.763333 210 148 0
0.766667 211 146 0
0.770000 212 144 1
0.773333 213 142 1
0.776667 213 142 1
0.780000 213 140 1
so R jumps from 166 to 150
I have chaged it manually :
0.000000 0 0 0
0.250000 0 0 177
0.500000 0 175 0
0.750000 210 156 0
1.000000 252 36 19
or in the 0-1 normalized 4 columns form:
0.000000 0.000000 0.000000 0.000000
0.250000 0.000000 0.000000 0.458823
0.500000 0.000000 0.686274 0.000000
0.750000 0.823529 0.611764 0.000000
1.000000 0.988235 0.141176 0.074509
which can be used by gnuplot command:
load "linas.pal"
and then check:
show palette gradient
0. gray=0.0000, (r,g,b)=(0.0000,0.0000,0.0000), #000000 = 0 0 0
1. gray=0.2500, (r,g,b)=(0.0000,0.0000,0.4588), #000075 = 0 0 117
2. gray=0.5000, (r,g,b)=(0.0000,0.6863,0.0000), #00af00 = 0 175 0
3. gray=0.7500, (r,g,b)=(0.8235,0.6118,0.0000), #d29c00 = 210 156 0
4. gray=1.0000, (r,g,b)=(0.9882,0.1412,0.0745), #fc2413 = 252 36 19
Now one can compute: 4 functions for each color channel ( 12 functions) using polysolve by P. Lutus.
Result:
C code for Linas gradient:
Examples of use: Linas art gallery - my version of Linas programs with old gradient
modifications:
c function = GiveMagmaColor from p.c file
lightness is monotone
Steps:
Tubes:
It is rainbow gradient from the Fractalizer program.
It has 7 segments and black color
lightness is non monotone
c function = GiveRainbowFractalizer from d.c file
Steps:
Tubes:
See also:
It is orange-blue gradient from the Fractalizer program.
Features:
c function = GiveOrangeBlueFractalizer from d.c file
Steps:
Tubes:
See also:
Linear function
c function:
Effect of joining gradients ( segments of the same gradient combined):
Steps:
Tubes:
Example image with use of such gradient:
code and description is in the commons
only ascending wave ( f = 1/2)
Adam Sakareassen : “The colours simply fade from black to white in a cycle. This wave is generated with the sin function. This method is useful when blending layers to create light to dark contrasts.”
Steps:
Tubes:
c function = GiveRGB_Gray from d.c file
Similar to
/* SmoothStep
it needs position in range [0.0, 1.0]
*/
double d = (3.0 -2.0*position)* position*position;
Examples of use :
It is based on the The Colour Map Test Image by Peter Kovesi
c function = GiveGrayColorLSine from d.c file
Steps:
Tubes:
An exponential chirp waveform; a sinusoidal wave that increases in frequency exponentially over time
c function = GiveGrayColorLSineExp from d.c file
See als:
Steps:
Tubes:
see also:
Steps:
Tubes:
Steps:
Tubes:
Steps:
Tubes:
Nonlinear gamma-corrected black and white palette
It is from gnuplot:
gamma = 2.2
color(gray) = gray**(1./gamma)
set palette model RGB functions color(gray), color(gray), color(gray) # A gamma-corrected black and white palette
Steps:
Tubes:
Steps:
Gradient can be inverted and joined, which converts “boring rectangle to into a stunning three dimensional glossy pipe”:
Steps:
Tubes:
More is here:
Features of the green colormap ( gradient):
// from green to black =
void GiveColorGreen(double position, double c[]){
double X = 1.0- (position*position*position);
// change range
c[0] = 0; //R
c[1] = X; // G
c[2] = 0; // B
}
Steps:
Tubes:
Steps:
Tubes:
Description by Kenneth Moreland
code:
Steps:
Tubes:
Description by Kenneth Moreland
colour scheme developed by Dave Green:
the colour scheme spirals (as a squashed helix) around the diagonal of the RGB colour cube
Steps:
Tubes:
See also:
cubehelix' colour schemes below, and optionally produce a
look-up-table’ file in several formats. The GRID-Arendal Maps & Graphics Library is an on-going project to collect and catalogue all graphic products that have been prepared for publications and web-sites from the last 15 years in a wide range of themes related to environment and sustainable development
One can see here:
See:
It seem that is a multi purpose gradient
It was made from default.map with gnuplot code:
set palette file "default.map" using ($1/255):($2/255):($3/255)
set terminal png
set output "fractint.png"
test palette
See:
simple one file c programs which
How to compile and run is described in the comments of c files
All my images here are made with
to make all images go to src directory and:
make
c console programs:
gnuplot programs
python programs
make files
pal files ( files with gnuplot code, use load command )
json files in src dir for colormeasure
I’m not an expert in the color, so many errors can be here. If you will find them let me know: issues or wikibooks
Program uses code from:
Program uses idea from :
Contributors are wellcome.
How to do it ( after darktable ) :
See also:
cd existing_folder
git add .
git commit -m "Initial commit"
git push -u origin main
git clone git@github.com:adammaj1/1D-RGB-color-gradient.git
Subdirectory
mkdir images
git add *.png
git mv *.png ./images
git commit -m "move"
git push -u origin main
then link the images:

to overwrite
git mv -f
local repo : ~/1D-RGB-color-gradient