Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

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

  1. #11
    Intern Newbie
    Join Date
    Oct 2014
    Posts
    38
    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. #12
    Junior Member Newbie
    Join Date
    Feb 2018
    Posts
    14
    Thank you very much this code works perfectly and i can finally make endless rainbow effect by examining how it works.

  3. #13
    Junior Member Newbie
    Join Date
    Feb 2018
    Posts
    14
    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.
    Last edited by StabberKnight906; 03-23-2018 at 01:29 AM. Reason: highligthing the code

  4. #14
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,828
    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
  •