My goal is to generate some unique random colors that can be easily seen by people. It means i try to avoid having both of ocean blue and sky blue. I prefer having violet red and ocean blue.
I think i need to have a variable that will be a "gap" between any generated RGB. For example, if the gap is 60 then the first and second color cant be RGB(12,27,38) and RGB(45,102,177) because the difference in red value is lesser than 60. (45-12=33).
This is what i tried so far :
int temp;
for(int i = 0; i < size; i++)
{
Rectangle r = new Rectangle();
temp = COLOR_LIMIT - colourGap;
if(i == 0 || temp <= 0)
colour = Color.argb(255, randomColour.nextInt(COLOR_LIMIT), randomColour.nextInt(COLOR_LIMIT), randomColour.nextInt(COLOR_LIMIT));
else
colour = Color.argb(255, randomColour.nextInt(temp), randomColour.nextInt(temp), randomColour.nextInt(temp));
temp-=colourGap;
}
With the above code, i realize the color generated is more unique compared to the basic random. However, my code above is not flexible and just a temporary fix (i need to play with the iteration size and gap variable every time). I believe there should be any clever way to do this. Basically, i just keep decreasing the limit by 60 and if the limit is lesser or equal to 0 then i just generate a basic random color.
Any help is appreciated, and sorry English is not my mother language.
Thanks very much.