RGB Gradient / Color Map for a Number Set

Hi! I am looking for help getting the rgb color values (assuming 0 is red and 0.5 is yellow and 1 is green) for a range of number from 0-1 similar to how Excel will create a gradient given a set of points.
How do I get the gradient between those colors? Help is appreciated, thanks!

Attached are images to reference.

The most intuitive is to start with a color on the HSL scale (see https://en.wikipedia.org/wiki/HSL_and_HSV for more info on that)

To get nice RGB colours, you should take a saturation value of 1.0 and a lightness value of 0.5. Then choose for the hue range an angle range over which you want to vary the colours, maybe in your case use 0 - 120 degrees (red-to-green). On a scale of 0 - 360, your hue range varies from 0 to 0.33333.

Then use Rhino’s ColorHSL to create the color and call ToArgb() on it to get RGB values.

Interval hueRange = new Interval(0,0.333333333333);

double[] fractions; // these are your numbers

foreach(double f in fractions)
{
  double hue = hueRange.ParameterAt(f);
  ColorHSL hsl = new ColorHSL(hue, 1.0, 0.5);
  Color rgb = hsl.ToArgb(); // here is the color in RGB
}

thanks for the reply - I’m trying to do this in python and I can’t find the hueRange function, any suggestions?

@Kanisha_Patel, @menno,

i use this and love it.

thank you @dale,
c.

This is the method I usually use for mapping a list of floats onto a color gradient using RhinoCommon/Python. MIght help.