What makes this mysterious color method? What does he return?

Maybe I had too much coffee, maybe I worked for too long, despite the fact that I do not understand what this method does, or rather, why and how it does it, can someone shed some light on me? What is nextColor?

public Color nextColor() {
   int max = 0, min = 1000000000, cr = 0, cg = 0, cb = 0;
   for (int r = 0; r < 256; r += 4) {
      for (int g = 0; g < 256; g += 4) {
         for (int b = 0; b < 256; b += 4) {
            if (r + g + b < 256 || r + g + b > 512) {
               continue;
            }
            min = 1000000000;
            for (Color c : colorTable) {
               int dred   = r - c.getRed();
               int dgreen = g - c.getGreen();
               int dblue  = b - c.getBlue();
               int dif = dred * dred + dgreen * dgreen + dblue * dblue;
               if (min > dif) {
                  min = dif;
               }
            }
            if (max < min) {
               max = min;
               cr  = r;
               cg  = g;
               cb  = b;
            }
         }
      }
   }

   return new Color(cr, cg, cb, 0x90);
}

UPDATE

Thanks for all the answers. Considering the context of the method inside the program, it is clear that their goal was to really return the new color, which is "most removed" from the set of existing colors.

Thanks to Sparr for posting followup on this question, I would definitely rewrite the above with your advice.

RGB. , ""? , , 1, , ? , , RGB ?

+1
4

, , colorTable, "", nextColor , nextColor. , colorTable, . , , ( , nextColor ), .

, , , nextColor, - , 1/64- , . , , , 25 .

. , (24 , ), .

nextColor, , " " , "", . , . , 8- 8 colorTable, 16 colorTable. 8 4 ( ), 12 .

, 1/64- ( 4) , , ​​ . , .

, . , , , ( colorTable , ?).

0

, colortable, .

, , 4 " " " ".

, , , "" .

, , , 2-.

+3

Color colorTable, , * , , :

, , 4 + + 256 512

*: "" .

, , , , colorTable. colorTable 5 colorTable, , .

+1

a) .

b) .

0

All Articles