Results 1 to 7 of 7

Thread: How to make random colors?

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    27

    How to make random colors?

    How to make a set of 4 random RGB colours? In freeglut or glut. Or opengl.

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: How to make random colors?

    Generate 4 random float values in [0, 1] and pass them to glColor4f().

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    27

    Re: How to make random colors?

    well it is not so straight forward.
    I have 6 colors.
    blue, green, yellow, light blue, white and red.
    I want to create a set of 4 colors from them.

    Code :
    colours array[6] = {sblue, sgreen, slblue, syellow, sred, swhite}
    ;

    I got this. All the members are the objects of my structure colours whose members are R, G, B.
    How can I do it?
    Code :
    struct colours
    {                        
           int red;
           int green;
           int blue;
     
    }sblue, sgreen, slblue, syellow, sred, swhite;
    //--------------------------------------------------------------------------------------------------------------------
    int createrandomcolors()
    {
        sblue.red = 0; sblue.green = 0; sblue.blue = 255;
        sgreen.red = 0; sgreen.green = 100; sgreen.blue = 0;
        slblue.red= 0; slblue.green = 255; slblue.blue =255;
        syellow.red =265; syellow.green = 140; syellow.blue = 0;
        sred.red =1; sred.green = 0; sred.blue = 0;
        swhite.red=1; swhite.green = 1; swhite.blue =1;
        colours array[6] = {sblue, sgreen, slblue, syellow, sred, swhite};   
    }

  4. #4
    Member Contributor
    Join Date
    Sep 2010
    Posts
    74

    Re: How to make random colors?

    So what you want to do is to pick 4 out of those colours at random? That was completely impossible to guess from your original post.

    Just generate 4 random integers, to use as indices for an array of colours?

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    27

    Re: How to make random colors?

    Sorry about that. I suck at making posts.
    could you please tell me in detail how to do that?

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: How to make random colors?

    Quote Originally Posted by programmer17
    could you please tell me in detail how to do that?
    Ref: http://www.cplusplus.com/reference/c.../cstdlib/rand/

  7. #7
    Senior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214

    Re: How to make random colors?

    Or you can use the built-in noise function in the shader language.

Similar Threads

  1. Replies: 3
    Last Post: 06-19-2016, 08:11 AM
  2. Replies: 2
    Last Post: 06-15-2015, 03:26 AM
  3. FreeGLUT make all, make install commands
    By Kaili47 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-24-2014, 05:12 AM
  4. Random, unique colors that are completely different
    By nightmarez77 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-04-2014, 10:54 AM
  5. Vertex Array drawing random points and colors
    By Beiufin in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-04-2012, 10:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean