PDA

View Full Version : How to make random colors?

programmer17
01-03-2012, 09:58 AM
How to make a set of 4 random RGB colours? In freeglut or glut. Or opengl.

carsten neumann
01-03-2012, 10:39 AM
Generate 4 random float values in [0, 1] and pass them to glColor4f().

programmer17
01-03-2012, 01:15 PM
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.

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?

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};
}

Zyx_2000
01-03-2012, 01:28 PM
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?

programmer17
01-03-2012, 03:16 PM
Sorry about that. I suck at making posts.
could you please tell me in detail how to do that?

awhig
01-03-2012, 03:29 PM
could you please tell me in detail how to do that?

Ref: http://www.cplusplus.com/reference/clibrary/cstdlib/rand/

Kopelrativ
01-05-2012, 08:52 AM
Or you can use the built-in noise function in the shader language.