cachai.utilities.mod_color

cachai.utilities.mod_color(color, light=1.0, sat=1.0, alpha=1.0, alpha_bg=(1.0, 1.0, 1.0))[source]

Applies multiple color modifications (lightness, saturation, transparency) to an RGB color.

Parameters
colortuple or array-like

Triplet with the three RGB values (in arithmetic notation, i.e. 0.0 to 1.0)

lightfloat

Lightness factor. 1.0 means no change.

satfloat

Saturation factor. 1.0 means no change.

alphafloat

Transparency level (0.0 to 1.0).

alpha_bgtuple or array-like

Background color. Since transparency isn’t actually achieved, a background color is set. The color is combined with the background color. Default is white.

Returns

tuple : RGB color

Examples

import cachai.utilities as chu
import matplotlib.colors as mcolors

# matplotlib.colors.to_rgb also supports HEX codes
my_color = mcolors.to_rgb("violet")

# Make it 50% darker, saturate to 150% and set the transparency to 30%
new_color = chu.mod_color(my_color,light=0.5,sat=1.5,alpha=0.3)

print("my_color:",my_color)
print("new_color:",new_color)
my_color: (0.9333333333333333, 0.5098039215686274, 0.9333333333333333)
new_color: (0.8558823529411764, 0.7605882352941176, 0.8558823529411764)