def mix(color, color1, weight=Pr(50)): """Mixes two colors together""" p = weight.value / 100.0 w = p * 2 - 1 a = color.a - color1.a w1 = ((w if w * a == -1 else (w + a) / (1 + w * a)) + 1) / 2.0 w2 = 1 - w1 r = color.r * w1 + color1.r * w2 g = color.g * w1 + color1.g * w2 b = color.b * w1 + color1.b * w2 a = color.a * p + color1.a * (1 - p) return Color(r, g, b, a)
def grayscale(color): """Converts a color to grayscale.""" color = Color(color) color.s = 1 return color
def spinin(color, value=Pr(10)): """Changes the hue of a color.""" color = Color(color) color.h += value return color
def hsla(h, s, l, a): """Converts an Hsla(h, s, l) quadruplet into a color.""" return Color.from_hsl(h, s, l, a)
def hsl(h, s, l): """Converts an Hsl(h, s, l) triplet into a color.""" return Color.from_hsl(h, s, l)
def rgba(r, g, b, a): """Converts an Rgba(r, g, b, a) quadruplet into a color.""" return Color(r, g, b, a)
def complement(color): """Returns the complement of a color.""" color = Color(color) return color
def darken(color, value=Pr(10)): """Makes a color darker.""" color = Color(color) color.l -= value return color
def fadeout(color, value=Pr(10)): """Add or change an alpha layer for any color value.""" color = Color(color) color.a -= value return color
def desaturate(color, value=Pr(10)): """Makes a color less saturated.""" color = Color(color) color.s -= value return color
def rgb(r, g, b): """Converts an Rgb(r, g, b) triplet into a color.""" return Color(r, g, b)
def saturate(color, value=Pr(10)): """Makes a color more saturated.""" color = Color(color) color.s += value return color
def invert(color): """Returns the inverse of a color.""" color = Color(color) return color
def lighten(color, value=Pr(10)): """Makes a color lighten.""" color = Color(color) color.l += value return color