# Thread: How does one create animated rgb rainbow effect on objects(lines,quads,triangles)?

1. Just want to mention that my previous post was somehow messed up. I fixed it and you should probably reread it if you already read it before (and got confused).

Greetings and good night!

2. Thank you very much this code works perfectly and i can finally make endless rainbow effect by examining how it works.

3. Code :
```	if(r==255&&g<255&&b==0){
g++;
}
if(r>0&&g==255&&b==0){
r--;
}
if(r==0&&g==255&&b<255){
b++;
}
if(r==0&&g>0&&b==255){
g--;
}
if(r<255&&g==0&&b==255){
r++;
}
if(r==255&&g==0&&b>0){
b--;
}```

Rgb cycle loop.
regular HSV method.

4. Note that incremental updates are less than ideal if you want the ability to control the transition speed. For a closed-form solution:

Code :
```void rainbow(double k)
{
double t = fmod(k*6, 6.0);
int which = (int) floor(t);
t -= which;
switch (which) {
case 0: glColor3f(  1,  t,   0); break; // r->y
case 1: glColor3f(1-t,  1,   0); break; // y->g
case 2: glColor3f(  0,  1,   t); break; // g->c
case 3: glColor3f(  0,1-t,   1); break; // c->b
case 4: glColor3f(  t,  0,   1); break; // b->m
case 5: glColor3f(  1,  0, 1-t); break; // m->r
}
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•