How to find all the colors between two colors?
I need to pick two colors, then find X colors (or tones) between th开发者_Python百科em, each one separated with the same 'distance' of the other.
I still don't understand how colors are formed. Should I try using HSV, RGB, or hex?
Unless you really know what kind of colors do you need, this is almost impossible to get all the colors between two colors.
Just look at the representations of the colors - there are wheels with colors like that:
and you can pick colors on some straight line, going clockwise or counter-clockwise and you will get different results.
In case of RGB colors, their number is limites and is equal to 16 777 216 (245^3). But do you really want to pick all of these colors? Choose a method to distinguish colors "between" two other colors and then just apply it and find these intermediate colors. There is no "single and only" best method to pick colors 'between' two different colors.
EDIT:
Alternatively, you can just make use of Color Difference concept and pick all the colors that are closer to both base colors than these base colors are close to each other. But I will leave you all the calculations.
The simplest thing to do is to take the RGB values of the first and the second color and interpolate them together ie.
$b1 = $color1['blue'];
$b2 = $color2['blue'];
for($i=0; $i<$X; $i++){
$b = round($b1 + (1.0 * ($b2 - $b1) * $i / $X));
// Do the same for the red / green values
}
EDIT: You can also use the HSV value instead of the RGB value
I think your best option is to use a HSL representation. Then you can interpolate using the hue value. You will get better results than using a RGB interpolation.
Colors are represented by bits, just like anything else in computers.
#FFFFFF
represents white and #000000
represents black. This is the RGB notation, which is in hex. To get the numeric value for each, convert it to an unsigned integer. Then you have your range that you need to divide up.
Generally, colors between two colors is the colors that are on the line connecting the colors in given color space. So, in RGB color space the colors are different then in other color spaces.
精彩评论