POV-Ray : Newsgroups : povray.binaries.images : RGB Rainbow Gradient : RGB Rainbow Gradient Server Time
18 Mar 2026 17:49:55 EDT (-0400)
  RGB Rainbow Gradient  
From: Dave Blandston
Date: 15 Mar 2026 22:05:00
Message: <web.69b7649c26fbb42217d879459334df62@news.povray.org>
Greetings Folks,

I'll share this here in case anyone ever finds it useful... The RGB rainbow
gradient is useless for data visualization but it's still popular for artistic
purposes. It has some limitations such as excessively bright points at the pure
yellow, cyan, and purple points, visually unbalanced proportions of the base
colors, and extreme differences in brightness values over the entire gradient
with the blue area being most noticeably dim. Here's a version with non-linear
transitions between the base colors that solves some of the problems. (The blue
part is still dim compared to the rest of the colors.) It also introduces a new
problem, which is that more transition points between the base colors are
required. In my opinion, at least five transition points are necessary to
achieve acceptable results. The maximum that POV-Ray 3.7 will allow is
forty-three.

Have an awesome day everyone!

Kind regards,
Dave Blandston

* * * I hope this "copy-and-pastes" OK!

#local NColorMapEntries = 7;

#local ColorMapEntry = array [NColorMapEntries] {
   <255, 0,   0  >, //0 Red
   <255, 255, 0  >, //1 Yellow
   <0,   255, 0  >, //2 Green
   <0,   255, 255>, //3 Cyan
   <0,   0,   255>, //4 Blue
   <255, 0,   255>, //5 Purple
   <255, 0,   0  >  //6 Red
} //array

#local NTransitionPoints = 43;

#local RainbowGradient_NonLinear = texture {
   pigment {
      radial
      color_map {
         #for (I, 0, NColorMapEntries - 2)
            #for (J, 0, NTransitionPoints - 2)
               #local Ratio = J / (NTransitionPoints - 1); //0 .. 1
               #switch (I)
                  #case (0) //Red to yellow
                     #local A = 270 + Ratio * 90; //Fast to slow
                     #local Ratio = cos (radians (A)); //0 .. 1
                  #break
                  #case (1) //Yellow to green
                     #local A = 180 + Ratio * 90; //Slow to fast
                     #local Ratio = cos (radians (A)) + 1; //0 .. 1
                  #break
                  #case (2) //Green to cyan
                     #local A = 270 + Ratio * 90; //Fast to slow
                     #local Ratio = cos (radians (A)); //0 .. 1
                  #break
                  #case (3) //Cyan to blue
                     #local A = 180 + Ratio * 90; //Slow to fast
                     #local Ratio = cos (radians (A)) + 1; //0 .. 1
                  #break
                  #case (4) //Blue to purple
                     #local A = 270 + Ratio * 90; //Fast to slow
                     #local Ratio = cos (radians (A)); //0 .. 1
                  #break
                  #case (5) //Purple to red
                     #local A = 180 + Ratio * 90; //Slow to fast
                     #local Ratio = cos (radians (A)) + 1; //0 .. 1
                  #break
               #end //#switch
               #local CurrentColor = ColorMapEntry [I] * (1 - Ratio) +
ColorMapEntry [I + 1] * Ratio;
               #local CurrentPoint = (I * NTransitionPoints + J) /
((NColorMapEntries - 1) * NTransitionPoints - 1);
               [CurrentPoint color CurrentColor / 255]
            #end //#for
         #end //#for
      } //color_map
   } //pigment
   rotate -90 * x
   finish {emission .9}
} //texture


Post a reply to this message


Attachments:
Download 'sine wave transition.png' (48 KB)

Preview of image 'sine wave transition.png'
sine wave transition.png


 

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.