All RGB color combinations in Javascript

I want all RGB colors in Javascript. I made this circuit;

R   G   B
0   0   0
255 255 255
0   255 255
255 0   255
255 255 0
0   255 0
0   0   255
255 0   0

And I did it in Javascript: click

Do I have all possible combinations with RGB colors?

+4
source share
2 answers

If you want to iterate through all 16,777,216 possible 24-bit RGB colors, this can be achieved quite simply with a single loop:

for( i=0; i < 1<<24; i++) {
    r = (i>>16) & 0xff;
    g = (i>>8) & 0xff;
    b = i & 0xff;
    colour = "rgb("+r+","+g+","+b+")";
}

In your code, with an interval of 100, it will take almost 20 days to go through one cycle.

If you're fine with fewer colors, try the following:

for( i=0; i < 1<<12; i++) {
    r = ((i>>8) & 0xf) * 0x11;
    g = ((i>>4) & 0xf) * 0x11;
    b = (i & 0xf) * 0x11;
    colour = "rgb("+r+","+g+","+b+")";
}

4 , # 000000, # 000011, # 000022 .. Rutime 100 41 4096 .

+4

, 1786 . (256 ^ 3) == 16777216 .

, , , 0 255. , , , R, G B, "" 0/255.

, !

0

Source: https://habr.com/ru/post/1539939/


All Articles