Skip to content

color

color

Colors: named constants, constructors and small helpers.

A Color is the (r, g, b, a) byte tuple used everywhere in nim2d, so these are conveniences over that tuple, not a separate type. You can write a color by name (red), from bytes (rgb(255, 120, 60)), from a hex string (color("#ff7a3c")), or as a level of gray (gray(128)), and pass any of them anywhere a Color is wanted, including setColor and the window background. Channels are 0 to 255.

rgb

func rgb(r, g, b: int): Color

A solid color from three 0-to-255 bytes.

Parameters

  • r (int)
  • g (int)
  • b (int)

Returns

Color

rgba

func rgba(r, g, b, a: int): Color

A color from four 0-to-255 bytes.

Parameters

  • r (int)
  • g (int)
  • b (int)
  • a (int)

Returns

Color

gray

func gray(v: int; a = 255): Color

A shade of gray, 0 black to 255 white.

Parameters

  • v (int)
  • a (auto)

Returns

Color

withAlpha

func withAlpha(c: Color; a: int): Color

The same color with a different alpha, 0 to 255.

Parameters

  • c (Color)
  • a (int)

Returns

Color

lerp

func lerp(a, b: Color; t: float): Color

Blend from a to b by t (0 to 1), channel by channel.

Parameters

  • a (Color)
  • b (Color)
  • t (float)

Returns

Color

color

proc color(hex: string): Color

Parse a hex color: "#rgb", "#rrggbb" or "#rrggbbaa", with the # optional.

Parameters

  • hex (string)

Returns

Color

white

const white = rgb(255, 255, 255)

black

const black = rgb(0, 0, 0)

transparent

const transparent = rgba(0, 0, 0, 0)

red

const red = rgb(230, 60, 60)

green

const green = rgb(70, 200, 95)

blue

const blue = rgb(60, 120, 230)

yellow

const yellow = rgb(245, 215, 65)

orange

const orange = rgb(245, 150, 50)

cyan

const cyan = rgb(65, 210, 220)

magenta

const magenta = rgb(220, 70, 200)

purple

const purple = rgb(150, 80, 210)

pink

const pink = rgb(245, 130, 180)

brown

const brown = rgb(150, 95, 55)

lightgray

const lightgray = rgb(200, 205, 215)

darkgray

const darkgray = rgb(60, 64, 72)

sky

const sky = rgb(120, 200, 255)
const navy = rgb(30, 45, 90)

lime

const lime = rgb(170, 230, 70)

teal

const teal = rgb(50, 170, 165)

gold

const gold = rgb(235, 195, 80)
Generated with mkdocstrings-nim