[css-easing] The `midpoint` easing function
Nobody has claimed this yet.
- Dominant language
- Bikeshed
- Stars
- 4.9k
- Forks
- 816
- PR merge metrics
- PR metrics pending
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the CSS Images 4 color-stop fixup section and the linked issues 3931 and 1332 to understand the existing interpolation-hint and easing proposals. Evaluate the midpoint(x) definition and its edge cases with the CSS Working Group; done requires an agreed specification change, not just an implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100