-
Notifications
You must be signed in to change notification settings - Fork 756
Description
Insofar as easing functions make it into the CSS gradient syntax, I would like to propose a new easing function, tentatively called midpoint(x), for smooth interpolation between color stops, without the drawbacks of the interpolation hints syntax.
- In the
css-images-4spec, interpolation hints seem to affect how color stops are positioned, and at least current browser interpretations adhere to that reading of the spec. - The proposal to add easing functions to gradients (in particular, the syntax analogous to adding hints between color stops) promises to disentangle the interpolation functions from color stop position computations.
To enable authors to obtain an intuitive effect from interpolation hints without the drawbacks outlined in (1) and without retroactively redefining the behavior of interpolation hints, we can piggy-back on the easings proposal (2) to present authors with similar functionality.
The midpoint easing function takes a single argument x ∈ [0, 1] that controls the relative position of the midpoint between the two color stops A and B. The resulting color is computed (by following the interpolation hint definition) as follows:
- if
x = 0, return color B for any point between the two color stops (equivalent tostep-start) - if
x = 1, return color A for any point between the two color stops (equivalent tostep-end) - if
x ∈ (0, 1):- compute the position
t ∈ [0, 1]of the point, relative to the two color stops - obtain the weighting between color stops C = tlogx(.5)
- the color at the point is then a linear blend between the colors of the two color stops, blending (1 - C) of the first stop and C of the second stop.
- compute the position
- the particular case
x = 0.5is equivalent tolinear
These two definitions are equivalent:
linear-gradient: (to right, red, 25%, green);
linear-gradient: (to right, red, midpoint(0.25), green);I have opted for x ∈ [0, 1] instead of x ∈ [0%, 100%] to make it clear that the value is local to the easing function, and not a position along the gradient line.