1

I need to pick two colors, then find X colors (or tones) between them, 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?

HappyDeveloper
  • 12,480
  • 22
  • 82
  • 117

5 Answers5

2

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:

enter image description here

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.

Tadeck
  • 132,510
  • 28
  • 152
  • 198
1

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

GWW
  • 43,129
  • 11
  • 115
  • 108
  • But in case of rgb(0,0,0) (black) and rgb(255,255,255) it will find all the colors (more than 16 million). Similar thing will happen if you choose some light color as the first one and some dark color as the second one. The OP really has to think what colors does he need. – Tadeck May 17 '11 at 00:51
  • @Tadeck: It will not find all of the colors, it's limited by the number of values of interest in this case `$X`. Furthermore, black to white will produce a bunch of grays – GWW May 17 '11 at 00:56
  • Your solution was unclear, maybe you are right. `$X` is number of colors to be found in between? If so, this solution is also not the best one - just because there is no single method of determining which colors are between two different colors (see my answer). – Tadeck May 17 '11 at 01:03
  • @Tadeck: HE said he wanted to find `X` tones between two colors hence the variable `X`. – GWW May 17 '11 at 01:32
  • I am saying there are many different ways to get these colors and there is no single and only correct way to do that. Unless he tells us what is the purpose of getting these colors and then we can think more about that. – Tadeck May 17 '11 at 01:38
0

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.

Santiago V.
  • 1,088
  • 8
  • 24
0

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.

zsalzbank
  • 9,685
  • 1
  • 26
  • 39
0

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.

Ross
  • 2,079
  • 2
  • 22
  • 26