rainbow spectrum -> RGB?

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.

ouch. sorry about the formatting. i’ll use spaces next time instead of tabs.

j

If i recall nehe had some rainbow stuff in his partice engine, tutorial 19 or something.

check this
hope it helps

-Thr33d

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

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.