Skip to content

MaxGradient.color.Color Reference

A class to represent a color that inherits and expands rich.rich.Color to include X11 named colors as well as multiple formats of hex and rgb colors.

Initialize

class Color (self, color: Any) -> None:

Parameters

Name Type Description
color Union[str, tuple, Color] The color to be represented.
The color may be:
  • the color name
    • color names (red, orange, yellow, green, cyan, lightblue, blue, purple, violet, magenta)
    • hex color codes (3-digit -> #f0f, 6-digit -> #ff00ff)
    • rgb color codes
    • X11 named colors
    • as well as any colors from rich's standard library.
  • the hex color code
  • the rgb color code
  • the rgb color tuple
  • a maxgradient.color.Color object

Attributes

Name Type Description
original str The original color passed to the constructor.
red int The red value of the color.
green int The green value of the color.
blue int The blue value of the color.
name str The name of the color. If the color is not a named color, this will default to the hex color code.
hex str The hex color code of the color.
rgb str The rgb color code of the color.
rgb_tuple tuple The rgb color tuple of the color.
style rich.style.Style A style object with the color as the foreground color.
bg_style rich.style.Style A style object with the color as the background color.

Methods

  • get_contrast(self) -> str:

    Generate the color of the foreground if the color is the background. Ie. lighter colors with return black, and darker colors will return white.

  • lighten(self, percent: float = 0.5) -> str:

    Generate a tint of the color.
         - percent (float): The amount of white to add to the color.

  • darken(self, percent: float = 0.5) -> str:

    Generate a tint of the color.
        - percent (float): The amount of black to add to the color.