cachai.utilities.alpha_color

cachai.utilities.alpha_color(color, alpha=1.0, bg=(1.0, 1.0, 1.0))[source]

Simulates transparency by blending an RGB color with a background color.

Parameters
colortuple or array-like

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

alphafloat

Transparency level (0.0 to 1.0).

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")

# Set the transparency to 30%
new_color = chu.alpha_color(my_color,alpha=0.3)

print("my_color:",my_color)
print("new_color:",new_color)
my_color: (0.9333333333333333, 0.5098039215686274, 0.9333333333333333)
new_color: (0.98, 0.8529411764705882, 0.98)