Does anyone know the formula used by CGGradientCreateWithColors to calculate the intermediate colours at each point along the gradient? I want to reproduce the colour for a given point - e.g. with CGGradientCreateWithColors using only 2 colours set to locations = 0 and 1, what would be the colour on the gradient at point 0.2 or any other defined point between 0 and 1? I use CGContextDrawLinearGradient to draw the background of one UIView with the full gradient, but I also want to colour a second UIView with the colour for a specific distance along the gradient, which would vary according to a value mapped to the 0..1 scale.
Any suggestions how to get this blend of the two colours to match the colour at a fixed point along the CGGradient wouild be greatly appreciated. Thanks
Larme's formula does the trick for me, where the proportion of the second colour (colour at location 1.0 in CGGradientCreateWithColors) that you want expressed (i.e. the "distance" between colour at 0.0 and colour at 1.0) is P in the formula below. The proportion of colour 0 expressed then becomes (1 - P). P is a value between 0..1, so (to state the obvious) 75% of colour 1 gives P = 0.75, and this means colour 0 has 25% expression (1 - 0.75).