svgen.color package — docs

Skip to main content
`Ctrl`+`K`

# svgen.color package

## Subpackages

- svgen.color.theme package
  - Submodules
  - svgen.color.theme.manager module
    - `ColorThemeManager`
      - `ColorThemeManager.add_themes()`
      - `ColorThemeManager.load_directory()`
      - `ColorThemeManager.size`
  - svgen.color.theme.visualize module
    - `visualize()`
    - `visualize_theme()`
  - Module contents
    - `ColorTheme`
      - `ColorTheme.add()`
      - `ColorTheme.add_mapping()`
      - `ColorTheme.create()`
      - `ColorTheme.data`
      - `ColorTheme.from_path()`
      - `ColorTheme.lookup()`
      - `ColorTheme.resolve()`
      - `ColorTheme.size`
    - `ColorToken`
      - `ColorToken.color`
      - `ColorToken.create()`
      - `ColorToken.token`

## Submodules

## svgen.color.alpha module

svgen - A module for working with alpha channels for colors.

class svgen.color.alpha.Alpha(val: float | int | str)

  Bases: `float`

  A class describing the transparency of a color.

  property hex_str: str

    Convert this alpha value to a hex string.

## svgen.color.conversion module

svgen - A module for converting colors from some form to some other.

svgen.color.conversion.hsl_to_rgb(color: Hsl) → Rgb

  Convert an hsl color to rgb.

svgen.color.conversion.rgb_to_hsl(color: Rgb) → Hsl

  Convert an rgb color to an hsl color.

## svgen.color.hsl module

svgen - Common interfaces for hsl colors. See also:

> https://www.w3schools.com/colors/colors_hsl.asp

class svgen.color.hsl.Hsl(hue: DegreePrimitive, saturation: PercentPrimitive, lightness: PercentPrimitive, alpha: Alpha = 1.0)

  Bases: `NamedTuple`

  A definition of an hsl color.

  alpha: Alpha

    Alias for field number 3

  animate(hue: int = None, saturation: float = None, lightness: float = None, alpha: float = None, delta: bool = False) → Hsl

    Manipulate this color into a new one.

  arc(hue_count: int = 1, hue_divisor: int = 1, saturation_count: int = 1, saturation_divisor: int = 1, lightness_count: int = 1, lightness_divisor: int = 1) → Hsl

    Rotate this angle around the circle.

  static from_ctor(value: str) → Hsl

    Get an hsl color from a constructor string.

  hue: DegreePrimitive

    Alias for field number 0

  lightness: PercentPrimitive

    Alias for field number 2

  saturation: PercentPrimitive

    Alias for field number 1

class svgen.color.hsl.PercentPrimitive(val: int)

  Bases: `int`, `Rotatable`

  A class for integer percentages.

  arc(count: int = 1, divisor: int = 2) → PercentPrimitive

    Rotate this angle around the circle.

  property ratio: float

    Get this percentage as a ratio between 0 and 1.

svgen.color.hsl.hsl(hue: int, saturation: float, lightness: float) → Hsl

  Create a new hsl color.

svgen.color.hsl.hsla(hue: int, saturation: float, lightness: float, alpha: float) → Hsl

  Create a new hsl color with a transparency value.

## svgen.color.numbers module

svgen - A module for working with number primitives.

svgen.color.numbers.css_number_to_ratio(val: float | int | str) → float

  Given a few possible types of input, return a ratio between 0.0 and 1.0.

svgen.color.numbers.parse_ctor(value: str, prefix: str, suffix: str = None, sep: str = ',') → list[str]

  Parse individual arguments out of some color constructor.

## svgen.color.resolve module

A module for resolving colors.

svgen.color.resolve.get_color(key: str | Hsl | Rgb | Color = 'black', manager: ColorThemeManager = None, **kwargs) → Color

  Resolve a color using the theme manager.

## svgen.color.rgb module

svgen - Common interfaces for rgb colors. See also:

> https://www.w3schools.com/colors/colors_rgb.asp

class svgen.color.rgb.Rgb(red: RgbPrimitive, green: RgbPrimitive, blue: RgbPrimitive, alpha: Alpha = 1.0)

  Bases: `NamedTuple`

  A definition of an rgb color.

  alpha: Alpha

    Alias for field number 3

  animate(red: int = None, green: int = None, blue: int = None, alpha: float = None, delta: bool = False) → Rgb

    Animate a color.

  blue: RgbPrimitive

    Alias for field number 2

  static from_ctor(value: str) → Rgb

    Get an rgb color from a constructor string.

  static from_hex(value: str) → Rgb

    Get an rgb color from a hex string.

  green: RgbPrimitive

    Alias for field number 1

  red: RgbPrimitive

    Alias for field number 0

  property rgb: str

    Get this color as an ‘rgb’ constructor.

  property rgba: str

    Get this color as an ‘rgba’ constructor.

class svgen.color.rgb.RgbPrimitive(val: int)

  Bases: `int`

  An integer type for rgb values.

  property ratio: float

    Get this color as a ratio between 0 and 1.

svgen.color.rgb.rgb(red: int, green: int, blue: int) → Rgb

  Create a new RGB color.

svgen.color.rgb.rgba(red: int, green: int, blue: int, alpha: float | int | str) → Rgb

  Create a new RGB color with a transparency value.

## Module contents

svgen - A module for working with colors.

class svgen.color.Color(rgb: Rgb, hsl: Hsl)

  Bases: `NamedTuple`

  A definition of a color.

  animate(hue: int = None, saturation: float = None, lightness: float = None, red: int = None, green: int = None, blue: int = None, alpha: float = None, delta: bool = False) → T

    Animate this color based on HSL properties.

  classmethod create(value: str | Hsl | Rgb | Color) → T

    Create a color from a variety of possible sources.

  classmethod from_ctor(value: str) → T

    Create a color from an hsl or rgb constructor string.

  classmethod from_hex(value: str) → T

    Create a color from a hex value.

  classmethod from_hsl(color: Hsl) → T

    Create a color from an hsl object.

  classmethod from_rgb(color: Rgb) → T

    Create a color from an rgb object.

  hsl: Hsl

    Alias for field number 1

  hsl_arc(**kwargs) → Color

    Get a new color based on some rotation in HSL space.

  rgb: Rgb

    Alias for field number 0