We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I'm trying to create a background that has all of the colors, with color mode as RGB. I found Processing.org's colorMode page but can't seem to figure out why Blue isn't showing up?
void setup(){
size(500,500);
colorMode(RGB, 255);
}
void draw(){
rainbowBG();
}
void rainbowBG() {
noStroke();
for (int i = 0; i <= width; i++) {
for (int j = 0; j <= width; j++) {
stroke(i, j, 0);
point(i, j);
}
}
}
even if I change "i [and j] <= 255" it still doesn't show up...any ideas?
Comments
B is allways 0 in your code...
:|
...wow. I was doing that way too much yesterday and I didn't even catch that. Sorry about such a silly question.
However, how can I get it to be the "rainbow" of colors I'm expecting? I changed it to
stroke(i,j,j);
and it added blue, but not the whole spectrum of colors.I also revised it to
To no avail. I just have trouble looking at loops - I wish I could go step by step to see what's happening. (kind of like in VB when you can view code and advance one line at a time with F8).
I will ponder this and report back if I find the solution - in the mean time any hints would be appreciated.
@piethon==
as for me your (last) code works, slowly but that is normal; the result is not a "rainbow" & that also is normal, reason is the nested loop: your first loop starts at 0, then (second loop) also to 0, then all values for blue, till 255, so the first value(i=0, j= 0) will be R= 0, G= 0, B = 255, pure blue; now second loop will be R= 0, G= 1, B, 255 and so on till R=0, G=255, B =255, that is i=0, j = 255, this the left down corner of the window (supposed to be 255 sized); now continue... when you are at the end of R (255), G will be also at 255 and Blue also:: result:: white, at i=255, j= 255...
The screen is far too small to see all of the colors. A 255 x 255 screen can see all of the combinations of two channels. In order to see the combinations of three channels you would need 16,581,375 pixels (255 x 255 x 255). Edit: The square root of 16,581,375 is about 4,072 so a 4,072 x 4,072 screen would be needed to see all the colors
The sketch below uses a 800 x 800 screen and skips a lot of colors because there are not enough pixels to see them all. Try making the 26 a 27 instead and see what happens, it will start to loop over the colors again:
Also pixels[] is much faster than point()
@ asimes==
that is a rainbow???? not at all because you use hex and not rgb so i think that it s nececessary to create some color[()] before (well, skipping some of them because the complete spectrum is impossible to show in a size(800,600) or ... window) i ll try that to morrow! right: load pixels is more fast but it is not the problem...
@akenaton, using hexadecimal does not mean I am not using RGB, it is RGB. Hexadecimal is just a base 16 number system rather than decimal which is base 10. Using hexadecimal can be easier due to how Processing stores colors, they are stored like this:
Binary: AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB
Hexadecimal: AARRGGBB
The A's are alpha, they should all be 1 in binary or Fs in hexadecimal (F is 15). The R, G, and Bs make up all possible colors, hexadecimal is just a short hand to decimal. Here is an example:
Breaking down the hex notation above, I have 0xffff8040:
- The first two ff are for full alpha (255)
- The next two ff are for full red (255)
- The 80 is for half green (128)
- The 40 is for quarter blue (64)
Here, maybe what I was doing will make more sense like this, very similar to the first one I posted but it uses color(i, j, k):
@asimes::: you are absolutely right about hex: but looking to the result which has nothing to see with rainbow gradient effect i stupidly thought that was the reason. Not at all: the reason is using pixels & loc : you get rows & cols, not gradient. With or without +26 the result is better with points. Of course the problem remains because the range values cannot be other than they are, that s why i persist to think that the best way is to create (coding) some array with colors...
@asimes:: creating array from colors. could be better if respecting some chromatic wheel... But it looks like a rainbow! -Problem is that i cannot see anyway to make it bigger... Perhaps using lines...
@akenaton, I think we have different goals here
What you have is something that looks like a rainbow, but it does not have an equal distribution of all RGB values. For example, the colors (128, 128, 128), (255, 64, 128), (192, 64, 128), etc. would never appear
I was not trying to make a rainbow, I was trying to display an equal distribution of all possible RGB values. Organizing that to look like a rainbow is a different problem. Because I can't show all of them, I skipped around by a small constant amount that isn't divisible by 256
I noticed earlier that some of my math was off, I should have been saying 256 instead of 255, but the general idea I had above still shows an equal distribution
Also, there is no particular advantage to using points() over pixels[], I use pixels[] because it is faster. Below is your sketch using pixels[]:
i agree... but at the beginning the question was "a rainbow"...
Wow, thanks for all of y'all's posts!