Find the percentage of color between two known colors

What is the best way to determine the percentage of color between two given values. In other words, what is the best way to calculate% position of color C?

Color A - 0x0000FF Color B - 0x00CCFF Color C - 0x00FFFF

Thanks!

+6
flash actionscript-3 hex
source share
1 answer

Well, this is not so straightforward, because it depends on how you decide to quantize the color.

You can do this via HSB, which is a more correct way, in my opinion (although this is not necessarily a fact) or just use a hexadecimal value.

this is most quickly possible using hax values

var colour:uint = 0x9900CC; var r:uint = colour >> 16; var g:uint = colour >> 8 & 0xFF; var b:uint = colour & 0xFF; 

. This will give you the value of each channel (c) (ABC is the colors)

then do the math for each channel (c)

 (cB - cA)/(cC - cA) 

then after you get each of these channels, you can add them together and divide by 3.

there is one problem though, if the colors A and C are always the same for any channel, you need to add an exception (because cC and CA are zero and you cannot divide by zero), at this point you also need to decide how to handle that difference.

+6
source share

All Articles