I want all RGB colors in Javascript. I have made this schema;
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 made this in Javascript: click
Do I have now all possible combinations with the RGB colors?
Each color channel is expressed from 0 (least saturated) to 255 (most saturated). This means that 16,777,216 different colors can be represented in the RGB color space.
255, 0, 0 is red. 0, 255, 0 is green.
If you want to iterate through all 16,777,216 possible 24-bit RGB colours, this can be achieved quite simply with one 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, at an interval of 100, this will take almost 20 days to run through a single cycle.
If you're okay with fewer colours, try this:
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+")";
}
This will basically reduce your colour range to 4 bits per channel, giving you #000000, #000011, #000022 and so on. Rutime at 100ms interval will be 41 seconds, and span 4,096 colours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With