0

Is there a library that makes it easy to create, manipulate and view gradients in different color spaces in python? I'm specially interested in interpolating in perceptually-uniform color spaces, such as CIELab or HCL.

aleferna
  • 136
  • 6

1 Answers1

1

Yes, colorir has a gradient module that allows exactly that.

To create a gradient, simply initialize either a Grad or PolarGrad class with the desired colors:

>>> grad = PolarGrad(["#2b70f3", "#f3ae2b"])
>>> print(grad.perc(0.5))  # Print color in the very middle of the gradient
"#fd58be"

swatch(grad) can be used to visualize the gradient in the terminal:

enter image description here

By default, PolarGrad interpolates in the HCLuv (aka LCH) color space, but gradients can be created in many popular systems, such as RGB, HSV, HSL, CIELab, CIELuv etc.

aleferna
  • 136
  • 6