https://kotlinlang.org logo
#compose
Title
# compose
m

Marcin Wisniowski

10/07/2023, 5:54 PM
How can I get a Color that is x% on the way between Color A and Color B? I want the same behavior as
animateColorAsState()
except there is no animation, I just want a fixed value that would be there, say, 50% through the animation.
same name as every the linear interpolator function on every other compose type
m

Marcin Wisniowski

10/07/2023, 6:09 PM
Just as I finished implementing my own 😄 I looked for "lerp" on the Color class, didn't know it would just be a global function, thanks!
z

Zach Klippenstein (he/him) [MOD]

10/08/2023, 2:31 AM
If you’re using your own, make sure to use the oklab color space
a

ascii

10/08/2023, 3:49 AM
Any reason why the default srgb shouldn't be used? Might as well change defaults then.
r

romainguy

10/08/2023, 4:56 AM
sRGB doesn't interpolate colors very well, notably losing luminance
Linear sRGB is an improvement but still shows luminance/hue skews that OkLab improves upon
It's not perfect either but much much better
Compose's lerp () will use OkLab
Here's a good example:
Image from iOS.jpg
mind blown 3
a

ascii

10/08/2023, 5:05 AM
Oh that's very interesting. Thanks!
6 Views