Algorithmically Darken Colors

Description

Takes one or multiple colors and adjust them sucht hat they apper darkened. See also: lighten.

Usage

darken(col, amount=0.1, method='relative',
space='HCL', fixup=True)

Arguments

col
color (or colors) to be manipulated. Can be a color object, a palette object, or a str/list of str with valid hex colors.
amountfloat
value between [0., 1.] with the amount the colors should be lightened. Defaults to 0.1.
methodstr
either "relative" (default) or "absolute".
spacestr
one of "HCL" or "HSV". Defaults to "HCL".
fixupbool
should colors which fall outside the defined RGB space be fixed (corrected)? Defaults to True.

Examples

from colorspace import darken, lighten, swatchplot
original = "#ff3322"
lighter  = lighten(original, amount = 0.3, method = "relative", space = "HCL")
darker   = darken(original,  amount = 0.3, method = "relative", space = "HCL")
swatchplot([lighter, original, darker],
           show_names = False, figsize = (6, 1));

Raises

  • TypeError: If method is not str.
  • ValueError: If method is not one of "absolute" or "relative".
  • TypeError: If space is not str.
  • ValueError: If space is not one of "HCL" or "HSV".
  • TypeError: If 'col' is not among the one of the recognized objects.
  • TypeError: If fixup is not bool.