1

I need to do color interpolation of single color(not interpolation from one color to another color). For an example, if the color is yellow (dark yellow) should be interpolated to light yellow within certain duration, which means for each time step color interpolation should happen within the color and after that duration/time step reverse interpolation (light yellow to dark yellow) should start for certain time step, so this cycle continues until the user stops it through request command.

Basically I need to change brightness.

using color_t = std::array<float,3>;
          // we can consider the value from 0-255
color_t yellow{1,1,0}; //as we increase yellow[2], it move towards light yellow
color_t green{0,1,0}; //dark green
// as we increase green[2],it move towards light green
color_t red{1,0,0};
// as we increase red[1],it move towards light red
color_t blue{0,0,1};
// as we increase blue[1],it move towards light blue
timeStepCount = 0;
time_step = 100;
void Linear(std::array<float,3>&color){
            
}   

In the above function, RGB value (let's say for yellow) for color will be passed by reference, so for each time step, I need to get the different RGB values of the same color(as I mentioned above, from dark to light and light to dark).

I need to have the generic linear function, which should work for any color.

I know that I need to find a mathematical equation in order to solve it. But also okay if I get any solution to above mentioned colors.

Cris Luengo
  • 43,236
  • 6
  • 46
  • 92
Suri
  • 19
  • 5
  • Why not transform it into HSV color space and then you only need to change its saturation or value? – stribor14 Jul 13 '20 at 13:21
  • Are you asking about how to decompose your color so that you can vary it's brightness? Or are you asking about the formula for linear interpolation? Or something else? I'm not exactly sure what you know and what you want to know – divinas Jul 13 '20 at 13:22
  • @divinas, your are correct, I need to change the brightness. – Suri Jul 13 '20 at 13:26
  • Try going here http://math.hws.edu/graphicsbook/demos/c2/rgb-hsv.html and set `hue=60`, `saturation=1` and then move the `value` slider left and right to see if that is what you want. Set `hue=0` to try red instead of yellow. If so, have a read here... https://en.m.wikipedia.org/wiki/HSL_and_HSV – Mark Setchell Jul 13 '20 at 13:31
  • @MarkSetchell, thank you, got some hint how to do it. – Suri Jul 13 '20 at 13:34
  • Transform RGB to HSL/HSV colourspace, increase (to lighten) or decrease (to darken) the Value/Lightness component and transform back to RGB. Any decent library will provide the conversion - OpenCV, CImg. – Mark Setchell Jul 13 '20 at 13:38
  • @Suri: "*For an example, if the color is yellow(dark yellow) should be interpolated to light yellow within certain duration*" That is interpolation between two colors: "dark yellow" and "light yellow". – Nicol Bolas Jul 13 '20 at 13:46
  • @stribor14, you also made my day. It is very simple. – Suri Jul 13 '20 at 13:59
  • Check out https://stackoverflow.com/q/141855/5987 – Mark Ransom Jul 13 '20 at 17:12
  • This depends on what is really meant by interpolating yellow to light yellow. For instance RGB(200,200,0) is a highly saturated yellow. RGB(255,255,0) is a brighter yellow that is just as saturated. OTOH, RGB(200,200,100) is a desaturated yellow as is RGB(255,255,150) which is also brighter. These can both be called "light yellow" So it really depends on your specific intent. – doug Jul 13 '20 at 17:34

0 Answers0