mix_colors

visualife.core.mix_colors(color1: str, color2: str, fraction: float) → str

Creates a color that is a mixture of two colors.

After this call color1 retains a fraction of color1 and shifts by 1-fraction value towards the color2

from browser import document
from visualife.core.styles import mix_colors

def update_color(evt = None):
    color1 = document["color1"].value
    color2 = document["color2"].value
    mix = float(document["fraction"].value)
    document["output"].style.backgroundColor = mix_colors(color1, color2, mix)
    document["fract"].innerHTML = mix

document["color1"].bind("change", update_color)
document["color2"].bind("change", update_color)
document["fraction"].bind("change", update_color)

update_color()
0.9
Parameters:
  • color1 – the first color to be mixed
  • color2 (str HEX format or color name) – the second color to be mixed
  • fraction (float) – fraction of the first color
Returns:

a hex string representing the mixed color