Click to See Complete Forum and Search --> : Combination of colors
kanji2150
August 22nd, 2005, 10:29 PM
Hey guys, I just wanted everyones opinion on a solution to this problem. What I am trying to do, using opengl, is to show all the possible combination of colors in a 5 x 5 square, so 25 pixels. I enlarged the pixels so it's visible, however I am having some difficulty in trying to write a loop to accomplish this. As of now I have a nested loop where the outmost loop chooses a red value from -1.00 to 1.00. The next two inner loops choose green and blue values. Then the last inner two loops choose an x and y value for the pixels from 0 to 4. Is this a good method for finding all possible combinations? I outputted the coordinates and color values to a text file, and looking at it it seems that the way it's written the loop will just set all the pixels to whatever color is generated by the outer three loops. Here is the nested loop:
for(float r=-1.00; r<=1.00; r+=0.01)
{
for(float g=-1.00; g<=1.00; g+=0.01)
{
for(float b=-1.00; b<=1.00; b+=0.01)
{
for(int y=0; y<5; y++)
{
for(int x=0; x<5; x++)
{
//set color
//plot point
}
}
}
}
}
is this right? Any suggestions? Thanks in advance!
Jason Palmer
Digital-Play Web Designs
http://webdesign.digital-play.com/
torfil
August 23rd, 2005, 12:18 AM
Your question is confusing. How can you show "all combinations of colors" in only 25 pixels? What do you mean by "all the possible combination of colors"?
kanji2150
August 23rd, 2005, 01:52 AM
In the end it will be a loop of say 1024x768 but for now I wanted to test it out on a smaller loop of 25 pixels. Every color value can be represented in opengl by assigning a red value of (-1.00 to 1.00) and the same goes for green and blue. So I want to make a loop that will go through and assign every possible combination of colors to the pixel set. So the loop will start off with all the pixels black and end with all the pixels white.
torfil
August 23rd, 2005, 02:17 AM
Well, you need to figure out how much to step each of the r, g, b values, in order to cover the whole range of colours over your exact number of pixels.
If you get rid of your two inner loops, then you'll have three loops, one for each colour. In the inner loop ncrement a number that represents your "current pixel", and draw the color. The trick is to calculate, given the number of pixels, how much to increment each colour value each time, such that it all works out exactly, and you've cycled through every possible colour once your "current pixel" reaches the end (24 in your test case, and (768 * 1024 - 1) for your final case, or whatever the screen resolution is.
kanji2150
August 23rd, 2005, 12:05 PM
I'm not sure I understand. The colors are incremented by 0.01+ each iteration of the loop as written in the for loop code. So now I just need code to apply the color to a pixel/pixels in such a way that the loop shows every possible combination of the colors. Thank you.
torfil
August 23rd, 2005, 01:36 PM
Are you trying to show all color combinations on screen at the same time (each pixel is a different color)? That's what my algorithim will do. (If you increment by 0.01, you'll have 8 million different colours to stuff into 25 pixels - how are you going to do that?)
Or are you trying to set all pixels to the same color, and cycle (over time) through all different colors? That's what the original code you posted will do. Except it will probably be so fast you'll need a timer or something.
Marc G
August 23rd, 2005, 01:38 PM
[ moved thread ]
Marc G
August 23rd, 2005, 01:39 PM
I think you could also let opengl do the interpolation for you.
kanji2150
August 23rd, 2005, 01:48 PM
Is that possible? If so, is there any documentation I could look at to find out how to do this? Thanks a lot for the help so far guys!
Jason Palmer
Digital-Play Web Designs
http://webdesign.digital-play.com/
Marc G
August 23rd, 2005, 01:52 PM
Is that possible? If so, is there any documentation I could look at to find out how to do this? Thanks a lot for the help so far guys!
Yes. Search for "color interpolation with opengl" on google.
For example: http://www.cs.trinity.edu/~jhowland/ccsc97j/jglpaper/node3.html
kanji2150
August 24th, 2005, 05:22 PM
I hate to ask so many questions, and I really appreciate the responses so far, but I'm not sure how to integrate this color interpolation with the idea that I have. I googled it and read several articles about it, however most of them were talking about problems with interpolation and such.. I did not find anything to show me how to use it properly. The only other way I could think of producing something similar to what I'm looking for is generating random colors. However, this is not what I am looking for. I want a loop that will show every single possible combination of colors in a 1024x768 area.. all 16 trillion colors or whatever the latest is.
Marc G
August 25th, 2005, 01:57 PM
I hate to ask so many questions, and I really appreciate the responses so far, but I'm not sure how to integrate this color interpolation with the idea that I have. I googled it and read several articles about it, however most of them were talking about problems with interpolation and such.. I did not find anything to show me how to use it properly.
See http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=03
The only other way I could think of producing something similar to what I'm looking for is generating random colors. However, this is not what I am looking for. I want a loop that will show every single possible combination of colors in a 1024x768 area.. all 16 trillion colors or whatever the latest is.
Note that you will never be able to display all colors. You only have 1024x768 = 786432 pixels. So you can't possibly display 16 trillion colors on less than a million pixels. And btw: where did you get that 16 trillion number from? 24 bit images only have 16 million possible values. You can have 10 bit per component images which result in 1 billion colors. A far cry from your 16 trillion ;)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.