catppuccin/chroma

  Source   Edit

Standalone types/methods ported from treeform/chroma.

See chroma LICENSE.

Types

Color = object
  r*: float32                ## red (0-1)
  g*: float32                ## green (0-1)
  b*: float32                ## blue (0-1)
  a*: float32                ## alpha (0-1, 0 is fully transparent)
  
Main color type, float32 points   Source   Edit
ColorHSL = object
  h*: float32                ## hue 0 to 360
  s*: float32                ## saturation 0 to 100
  l*: float32                ## lightness 0 to 100
  
HSL attempts to resemble more perceptual color models   Source   Edit
ColorRGB = object
  r*: uint8                  ## Red 0-255
  g*: uint8                  ## Green 0-255
  b*: uint8                  ## Blue 0-255
  
Color stored as 3 uint8s   Source   Edit
ColorRGBA = object
  r*: uint8                  ## Red 0-255
  g*: uint8                  ## Green 0-255
  b*: uint8                  ## Blue 0-255
  a*: uint8                  ## Alpha 0-255
  
Color stored as 4 uint8s   Source   Edit
InvalidColor = object of ValueError
  Source   Edit

Procs

proc `$`(c: Color): string {....raises: [], tags: [].}
Returns colors as "(r, g, b, a)".   Source   Edit
proc asColor(c: SomeColor): Color {.inline.}
  Source   Edit
proc asHsl(c: SomeColor): ColorHSL {.inline.}
  Source   Edit
proc asRgb(c: SomeColor): ColorRGB {.inline.}
  Source   Edit
proc color(c: Color): Color {.inline, ...raises: [], tags: [].}
  Source   Edit
proc color(c: ColorHSL): Color {....raises: [], tags: [].}
convert ColorHSL to Color   Source   Edit
proc color(c: ColorRGB): Color {.inline, ...raises: [], tags: [].}
Convert ColorRGB to Color   Source   Edit
proc color(c: ColorRGBA): Color {.inline, ...raises: [], tags: [].}
Convert ColorRGBA to Color   Source   Edit
proc color(r, g, b: float32; a: float32 = 1.0): Color {.inline, ...raises: [],
    tags: [].}
Creates from floats like:
  • color(1,0,0) -> red
  • color(0,1,0) -> green
  • color(0,0,1) -> blue
  • color(0,0,0,1) -> opaque black
  • color(0,0,0,0) -> transparent black
  Source   Edit
func hash(c: Color): Hash {....raises: [], tags: [].}
Hashes a Color - used in tables.   Source   Edit
func hash(c: ColorHSL): Hash {....raises: [], tags: [].}
Hashes a ColorHSL - used in tables.   Source   Edit
func hash(c: ColorRGB): Hash {....raises: [], tags: [].}
Hashes a ColorRGB - used in tables.   Source   Edit
func hash(c: ColorRGBA): Hash {....raises: [], tags: [].}
Hashes a ColorRGB - used in tables.   Source   Edit
proc hsl(c: Color): ColorHSL {....raises: [], tags: [].}
convert Color to ColorHSL   Source   Edit
proc hsl(h, s, l: float32): ColorHSL {.inline, ...raises: [], tags: [].}
  Source   Edit
proc rgb(c: Color): ColorRGB {.inline, ...raises: [], tags: [].}
Convert Color to ColorRGB   Source   Edit
proc rgb(r, g, b: uint8): ColorRGB {.inline, ...raises: [], tags: [].}
Creates from uint8s like:
  • rgba(255,0,0) -> red
  • rgba(0,255,0) -> green
  • rgba(0,0,255) -> blue
  Source   Edit
proc rgba(c: Color): ColorRGBA {.inline, ...raises: [], tags: [].}
Convert Color to ColorRGBA   Source   Edit
proc rgba(r, g, b, a: uint8): ColorRGBA {.inline, ...raises: [], tags: [].}
Creates from uint8s like:
  • rgba(255,0,0,255) -> red
  • rgba(0,255,0,255) -> green
  • rgba(0,0,255,255) -> blue
  • rgba(0,0,0,255) -> opaque black
  • rgba(0,0,0,0) -> transparent black
  Source   Edit
proc to[T: SomeColor](c: SomeColor; toColor: typedesc[T]): T {.inline.}
Allows conversion of transformation of a color in any color space into any other color space.   Source   Edit
proc toHex(c: Color): string {....raises: [], tags: [].}
Formats color as hex (upper case):
  • red -> FF0000
  • blue -> 0000FF
  • white -> FFFFFF
  Source   Edit
proc toHexAlpha(c: Color): string {....raises: [], tags: [].}
Formats color as hex (upper case):
  • red -> FF0000FF
  • blue -> 0000FFFF
  • white -> FFFFFFFF
  • opaque black -> 000000FF
  • transparent black -> 00000000
  Source   Edit
proc toHtmlHex(c: Color): string {....raises: [], tags: [].}
Formats color as HTML hex (upper case):
  • red -> #FF0000
  • blue -> #0000FF
  • white -> #FFFFFF
  Source   Edit
proc toHtmlHexTiny(c: Color): string {....raises: [], tags: [].}
Formats color as HTML 3 hex numbers (upper case):
  • red -> #F00
  • blue -> #00F
  • white -> #FFF
  Source   Edit
proc toHtmlRgb(c: Color): string {....raises: [], tags: [].}
Parses colors in html's rgb format:
  • red -> rgb(255, 0, 0)
  • blue -> rgb(0,0,255)
  • white -> rgb(255,255,255)
  Source   Edit
proc toHtmlRgba(c: Color): string {....raises: [], tags: [].}
Parses colors in html's rgb format:
  • red -> rgb(255, 0, 0)
  • blue -> rgb(0,0,255)
  • white -> rgb(255,255,255)
  Source   Edit