nodesnim/core/color

Types

ColorObj = object
  r*, g*, b*, a*: float
ColorRef = ref ColorObj

Procs

proc Color(r, g, b, a: float): ColorRef {...}{.raises: [], tags: [].}
Creates a new Color from RGBA. r, g, b and a is a numbers ranges 0.0..1.0.
proc Color(r, g, b: float): ColorRef {...}{.inline, raises: [], tags: [].}
Creates a new Color from RGB. r, g and b is a numbers ranges 0.0..1.0.
proc Color(r, g, b, a: uint8): ColorRef {...}{.raises: [], tags: [].}
Creates a new Color from RGBA. r, g, b and a is a numbers ranges 0..255.
proc Color(r, g, b: uint8; a: float): ColorRef {...}{.raises: [], tags: [].}
Creates a new Color from RGBA. r, g, b and a is a numbers ranges 0..255.
proc Color(r, g, b: uint8): ColorRef {...}{.inline, raises: [], tags: [].}
Creates a new Color from RGB. r, g and b is a numbers ranges 0..255.
proc Color(src: uint32): ColorRef {...}{.raises: [], tags: [].}

Translate AARRGGBB uint32 color to the Color object.

0xFF00FF00 -> Color(0, 1, 0, 1)

Example:

var
  clr1 = Color(0xFFCCAAFF'u32)
  clr2 = Color(0xFFAACCFF'u32)
  clr3 = Color(0xAACCFFFF'u32)
  clr4 = Color(0xAAFFCCFF'u32)
echo clr1
echo clr2
echo clr3
echo clr4
proc Color(src: string): ColorRef {...}{.raises: [ValueError, RegexError], tags: [].}
Parses color from string. src should be a string, begins with "#", "0x" or "0X" and have a AARRGGBB color value.

Example:

var
  clr1 = Color("#FFCCAAFF")
  clr2 = Color("0xFFAACCFF")
  clr3 = Color("0XAACCFFFF")
  clr4 = Color("#AAFFCCFF")
echo clr1
echo clr2
echo clr3
echo clr4
proc Color(): ColorRef {...}{.inline, raises: [], tags: [].}
Creates a new Color object with RGBA value (0, 0, 0, 0)
proc Color(clr: ColorRef): ColorRef {...}{.inline, raises: [], tags: [].}
proc getBrightness(self: ColorRef): float {...}{.inline, raises: [], tags: [].}
proc normalize(n: float): uint32 {...}{.inline, raises: [], tags: [].}
Returns number in range 0..255.
proc normalize(n, min, max: float): float {...}{.inline, raises: [], tags: [].}
Returns number in range 0.0..1.0.
proc normalizeColor(color: float): float {...}{.inline, raises: [], tags: [].}
Returns number in range 0..255.
proc toUint32BE(color: ColorRef): uint32 {...}{.inline, raises: [], tags: [].}
Converts Color object to uint32 with big endian.
proc toUint32LE(color: ColorRef): uint32 {...}{.inline, raises: [], tags: [].}
Converts Color object to uint32 with little endian.
proc toFloatTuple(color: ColorRef): tuple[r, g, b, a: float] {...}{.inline,
    raises: [], tags: [].}
Converts Color object to the tuple.
proc toUint32Tuple(color: ColorRef): tuple[r, g, b, a: uint32] {...}{.inline,
    raises: [], tags: [].}
Converts Color object to the tuple.
proc toUint32BEWithoutAlpha(color: ColorRef): uint32 {...}{.inline, raises: [],
    tags: [].}
Converts Color object to uint32 without alpha-channel with big endian.
proc toUint32LEWithoutAlpha(color: ColorRef): uint32 {...}{.inline, raises: [],
    tags: [].}
Converts Color object to uint32 without alpha-channel with little endian.
proc lerp(r1, g1, b1, a1, r2, g2, b2, a2: uint32; lerpv: float): uint32 {...}{.
    raises: [], tags: [].}

linear interpolate color.

Arguments:

  • self and other - Color objects.
  • lerpv - linear interpolate value
proc lerp(self, other: ColorRef; lerpv: float): uint32 {...}{.raises: [], tags: [].}
proc copyColorTo(dest, src: ColorRef) {...}{.raises: [], tags: [].}
proc glColor(clr: ColorRef) {...}{.raises: [GLerror], tags: [].}
proc `$`(color: ColorRef): string {...}{.raises: [], tags: [].}
proc `+`(x, y: ColorRef): ColorRef {...}{.raises: [], tags: [].}
proc `-`(x, y: ColorRef): ColorRef {...}{.raises: [], tags: [].}
proc `*`(x, y: ColorRef): ColorRef {...}{.raises: [], tags: [].}
proc `/`(x, y: ColorRef): ColorRef {...}{.raises: [], tags: [].}
proc `+=`(x: var ColorRef; y: ColorRef) {...}{.raises: [], tags: [].}
proc `-=`(x: var ColorRef; y: ColorRef) {...}{.raises: [], tags: [].}
proc `*=`(x: var ColorRef; y: ColorRef) {...}{.raises: [], tags: [].}
proc `/=`(x: var ColorRef; y: ColorRef) {...}{.raises: [], tags: [].}
proc `==`(x, y: ColorRef): bool {...}{.raises: [], tags: [].}