Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you get the same easing / gradient as the browser? #250

Closed
NullVoxPopuli opened this issue Nov 27, 2024 · 3 comments
Closed

How do you get the same easing / gradient as the browser? #250

NullVoxPopuli opened this issue Nov 27, 2024 · 3 comments

Comments

@NullVoxPopuli
Copy link

NullVoxPopuli commented Nov 27, 2024

For example, I have:

background-image: linear-gradient(
  in oklch to right,
  var(--start),
  var(--end)
);

and then in javascript:

const interpolator = interpolate([this.start, this.end], 'lch');
const colors = samples(5).map(interpolator);

return colors;

which generates something like this:
image

the color bands are obvious here -- but they should be pretty invisible, even though they are a couple rem wide.

the end-colors on the very left and very right are perfect, so it's the interpolation of the middle 3 colors that seems wrong.

Is there an existing easing function that matches the browser behavior?

I've deployed this here:

And my code is here:

@danburzo
Copy link
Collaborator

Hi @NullVoxPopuli, the problem might be produced by the fact that the browser gradient is in Oklch and the Culori JS code uses lch = CIELCH. Switching to oklch in interpolate() should give you a more consistent result.

@NullVoxPopuli
Copy link
Author

thanks! ya, I forgot that oklch isn't lch.

I now an barely see my lines (as expected)

image

thanks!

There is also a bit of an illusion, where, even though these lines are solid colors, they still look like they have gradients -- unless I turn my screen sideways.

image

@danburzo
Copy link
Collaborator

There is also a bit of an illusion, where, even though these lines are solid colors, they still look like they have gradients -- unless I turn my screen sideways.

I definitely see it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants