Hello,

I want to generate 11 basic colors in RGB(8bit and excluding black and white) automatically. Any pre defined algoritham is there for that or any logic.

Thanks

Printable View

- Apr 9th 2009, 02:50 AMkumarColors
Hello,

I want to generate 11 basic colors in RGB(8bit and excluding black and white) automatically. Any pre defined algoritham is there for that or any logic.

Thanks - Apr 9th 2009, 03:52 PMMedia_Man
Are you talking about:

for(i=0; i<11; i++)

{

red=(int) 255*Math.rand();

green=(int) 255*Math.rand();

blue=(int) 255*Math.rand();

color[i]= new Color(red, green, blue);

}

???

What exactly do you mean by "basic" and "automatic"? Can you clarify the problem at hand? - Apr 9th 2009, 10:45 PMkumar
Thanks for your reply.

Samething only I want. but I can't use rand function. Because it will return different values eachtime. whenever I run that It should always return same colors for each interval(1 means red, 2 means blue like that, this should not vary). for this any pre defined algorithm is there? I want to generate any 11 different colors.

Thanks - Apr 10th 2009, 06:04 AMMedia_ManCircle Method
I understand. Why can't you choose your favorite 11 colors and hard code them?

Here is an algorithm that will work (in java):

int n=11;

int c[]={127,127,127};

int x[]={85,-85,-85};

int y[]={-85,85,-85};

Color color[]= new Color[n];

int r,g,b;

double theta;

for (int i=0; i<n; i++){

theta=i*360.0/n;

r=(int)(c[0]+Math.cos(theta)*x[0]+Math.sin(theta)*y[0]);

g=(int)(c[1]+Math.cos(theta)*x[1]+Math.sin(theta)*y[1]);

b=(int)(c[2]+Math.cos(theta)*x[2]+Math.sin(theta)*y[2]);

color[i]= new Color(r,g,b);

}

Let me know if this produces your desired result. The only disadvantage is you cannot pick your own colors. Also keep in mind that this requires 14 lines of code, and has to be re-calculated every time the program runs. Even though hard-coding your favorite 11 colors is not as mathematically "pretty," it saves computing time and gives you more control. - Apr 10th 2009, 06:32 AMkumar
Same colors should not repeat Accoring to that logic some colors are repeating and tint colors are also coming. for example first color is green, then lightgreen(means nearest green) should not come in the 11 colors because afterthat I have to do tint of that 11 colors and I want know that algorithm name.

Thanks - Apr 10th 2009, 07:03 AMMedia_ManMaximum number of tints
I see. If by "tint" you mean which color is most prominent, second most prominent, least prominent, then there really are only 6 "tints" corresponding to the possible orders of colors from "darkest" to "lightest." You could add a little bit of variation by assuming certain ones were equal:

R<G<B R<G=B

R<B<G R=B<G

B<R<G B<R=G

B<G<R B=G<R

G<B<R G<B=R

G<R<B G=R<B

ARE YOU NOT ALLOWED TO HARD CODE THESE?

int lo=42,md=127,hi=212;

Color color[]= new Color[11];

color[0]= new Color(lo,md,hi);

color[1]= new Color(lo,md,md);

color[2]= new Color(lo,hi,md);

color[3]= new Color(lo,lo,md);

color[4]= new Color(hi,lo,md);

etc... - Apr 13th 2009, 05:34 AMkumar
If any algorithm is there, I have to use that, Otherwise I can implement any logic. First I want to know any algorithm is there or not for generating 11 different colors using different rgb values.