In the previousArticleGiven a color, the color value is calculated as follows:
It can be seen from the formula that the calculation of the color phase is divided into six situations, and the calculation is slightly complicated. Is there a simple calculation method? Let's take a look at the figure below.
The above figure shows the color distribution of the solid color. The solid color is divided into six parts. Observe carefully, the solid color of each part has a uniform feature, for example, in the upper right corner, r = 255, B = 0, g changes from 0 to 255. In the right part, G = 255, B = 0, r changes from 255 to 0. Each part is a component of 255, a component is 0, and a component changes between 0 and 255.
After careful observation, we suddenly found that the angle between any solid color (R, G, B) and the red color can be expressed using the following formula:
Gauge = (| R-255 | + | G-0 | + | B-0 |)/255x60
After removing the absolute value symbol, it is simplified
Limit = (255-r + G + B)/255 × 60
In this case, the value range of period is [0,180].
Observe the figure above again and find that the solid color of the three Shadow parts on the right has a common feature, that is, the value of component G is greater than or equal to the value of component B, the solid color of the three blank parts on the left also has a common feature, that is, the value of component B is greater than or equal to the value of component G.
Therefore, the color values of any solid color can be expressed using the following formula.
When G is greater than or equal to B, H = (255-r + G + B)/255 × 60
When G <B, H = 360-(255-r + G + B)/255 × 60
According to evolutionary derivation, the formula for calculating the color phases of any color (R', G', B ') is as follows:
Max is the maximum value of the three components, and Min is the minimum value of the three components.
If max = min, it indicates a gray color. h = 0
If max = min, there are two scenarios:
When G is greater than or equal to B, H = (max-R' + G'-min + B '-min)/(max-min) × 60
When G <B, H = 360-(Max-r '+ G'-min + B'-min)/(max-min) × 60
Note: Add two formulas, which will be used later
Solid color (R, G, B), and red Angle
Limit = (255-r + G + B)/255 × 60
And green Angle
Ceiling = (255 + R-G + B)/255x60
And the blue Angle
Cost = (255 + R + G-B)/255x60