PDA

View Full Version : rainbow spectrum -> RGB?



jmg
06-23-2000, 07:12 PM
i'm trying to write a function that takes a value from 0 to 1 (0 representing that i want red, 1 that i want violet. you know roygbiv) and sets glColor3f() accordingly to give me those colors. so far, i've tried (unsuccessfully):

void PhysimGLView::setCurrentColor(GLfloat r)
{
if ( r < 0.50 )
{
//glColor3f(1.0, 0.0, 0.0);
glColor3f( ( 0.50 - r )/0.50, r/0.50, 0.00 );
}
else
{
if ( r >= 0.50 && r < 0.501 )
{
glColor3f(0.0, 1.0, 0.0);
}
else
{
glColor3f( 0.00, ( 0.50 - (r - 0.50) )/0.50, (r - 0.50) /0.50 );
}
}

}

any ideas?

thanks.

jmg
06-23-2000, 07:18 PM
ouch. sorry about the formatting. i'll use spaces next time instead of tabs.

j

Thr33d
06-23-2000, 10:08 PM
If i recall nehe had some rainbow stuff in his partice engine, tutorial 19 or something.

check this (http://nehe.gamedev.net/opengl.asp)
hope it helps

-Thr33d


[This message has been edited by Thr33d (edited 06-24-2000).]

jmg
06-24-2000, 12:23 PM
thanks thr33d,

that tutorial had some discreet color values for the colors of the rainbow:

{
{1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f },{0.75f,1.0f,0.5f},
{0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f },{0.5f,0.75f,1.0f},
{0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f },{1.0f,0.5f,0.75f}
};

looks like a good place to start.