c - How to interpolate a HSV color? -


i creating application in win32 api, use progress bar. progress bar, should change color. red (left end) green(right), , in middle yellow.

i searched little, , found out, should use hsv achieve this. don't know how? found in this link, 2 functions, convert color, rgb hsv , back.

but should if color has been converted hsv?

like rgb coordinates, hsv coordinates define point in 3 dimensional space.

you may find trajectory form 1 point (x0, 1 color) second (x1) formula like:

x = x0 + alpha * (x1-x0) 

with alpha varying form 0.0 1.0

you can 3 components simultaneaously.

with trajectory green red in hsv space modify h (hue) value. if want see yellow in middle of path (and not violett) need define second or third color , walk

green -> yellow -> red  


edit: example

int hue0 = 0; // red int hue2 = 120; // green  // find 100 colors between red , green for(double alpha = 0; alpha <= 1.0; alpha += 0.01) {      huex = hue0 + alpha * (hue1 - hue0);      // same value, saturation:      // valx = val0 + alpha * (val1 - val0)      // ...      // plot color } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -