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