Non-Linear color interpolation?

前端 未结 5 1126
天涯浪人
天涯浪人 2021-01-11 18:47

If I have a straight line that mesures from 0 to 1, then I have colorA(255,0,0) at 0 on the line, then at 0.3 I have colorB(20,160,0) then at 1 on the line I have colorC(0,0

5条回答
  •  情书的邮戳
    2021-01-11 19:09

    Try to convert this to another color-representation, e.g. HSV (see http://en.wikipedia.org/wiki/HSL_and_HSV).

    • Color A has a Hue of 0, a Saturation of 1 and a Value of 1.
    • Color C has a Hue of ?, a Saturation of ? and a Value of 0.

    ? means that it actually doesn't matter (since color C is simply black).

    Now also convert color B to an HSV (can't do this out of my head, sorry), then choose nice values for the Hue and Saturation of color C so that the Hue, Value and Saturation are on one line in the HSV space. Then deduct the color at 0.7 from it.

    EDIT: Using the RGB-HSV calculator at http://www.csgnetwork.com/csgcolorsel4.html I calculated the following:

    • Color A: H: 0, V: 100, S: 100
    • Color B: H: 113, V: 100, S: 63

    Now we calculate the H and V of color C like this:

    • H: 113/0.3 = 376.6
    • V: 100 (since both A and B have a V or 100)

    This gives us for the color at 0.7:

    • H = 376.66*0.7 = 263.66
    • V = 100
    • S = somewhere around 30

    Unfortunately, this doesn't fit completely for the Saturation, but if you interpolate this way, you will get something that's very close to what you want.

提交回复
热议问题