W3cubDocs

/Nim

Module colors

This module implements color handling for Nim. It is used by the graphics module.

Imports

strutils

Types

Color = distinct int
a color stored as RGB

Consts

colAliceBlue = 0x00F0F8FF
colAntiqueWhite = 0x00FAEBD7
colAqua = 0x0000FFFF
colAquamarine = 0x007FFFD4
colAzure = 0x00F0FFFF
colBeige = 0x00F5F5DC
colBisque = 0x00FFE4C4
colBlack = 0x00000000
colBlanchedAlmond = 0x00FFEBCD
colBlue = 0x000000FF
colBlueViolet = 0x008A2BE2
colBrown = 0x00A52A2A
colBurlyWood = 0x00DEB887
colCadetBlue = 0x005F9EA0
colChartreuse = 0x007FFF00
colChocolate = 0x00D2691E
colCoral = 0x00FF7F50
colCornflowerBlue = 0x006495ED
colCornsilk = 0x00FFF8DC
colCrimson = 0x00DC143C
colCyan = 0x0000FFFF
colDarkBlue = 0x0000008B
colDarkCyan = 0x00008B8B
colDarkGoldenRod = 0x00B8860B
colDarkGray = 0x00A9A9A9
colDarkGreen = 0x00006400
colDarkKhaki = 0x00BDB76B
colDarkMagenta = 0x008B008B
colDarkOliveGreen = 0x00556B2F
colDarkorange = 0x00FF8C00
colDarkOrchid = 0x009932CC
colDarkRed = 0x008B0000
colDarkSalmon = 0x00E9967A
colDarkSeaGreen = 0x008FBC8F
colDarkSlateBlue = 0x00483D8B
colDarkSlateGray = 0x002F4F4F
colDarkTurquoise = 0x0000CED1
colDarkViolet = 0x009400D3
colDeepPink = 0x00FF1493
colDeepSkyBlue = 0x0000BFFF
colDimGray = 0x00696969
colDodgerBlue = 0x001E90FF
colFireBrick = 0x00B22222
colFloralWhite = 0x00FFFAF0
colForestGreen = 0x00228B22
colFuchsia = 0x00FF00FF
colGainsboro = 0x00DCDCDC
colGhostWhite = 0x00F8F8FF
colGold = 0x00FFD700
colGoldenRod = 0x00DAA520
colGray = 0x00808080
colGreen = 0x00008000
colGreenYellow = 0x00ADFF2F
colHoneyDew = 0x00F0FFF0
colHotPink = 0x00FF69B4
colIndianRed = 0x00CD5C5C
colIndigo = 0x004B0082
colIvory = 0x00FFFFF0
colKhaki = 0x00F0E68C
colLavender = 0x00E6E6FA
colLavenderBlush = 0x00FFF0F5
colLawnGreen = 0x007CFC00
colLemonChiffon = 0x00FFFACD
colLightBlue = 0x00ADD8E6
colLightCoral = 0x00F08080
colLightCyan = 0x00E0FFFF
colLightGoldenRodYellow = 0x00FAFAD2
colLightGrey = 0x00D3D3D3
colLightGreen = 0x0090EE90
colLightPink = 0x00FFB6C1
colLightSalmon = 0x00FFA07A
colLightSeaGreen = 0x0020B2AA
colLightSkyBlue = 0x0087CEFA
colLightSlateGray = 0x00778899
colLightSteelBlue = 0x00B0C4DE
colLightYellow = 0x00FFFFE0
colLime = 0x0000FF00
colLimeGreen = 0x0032CD32
colLinen = 0x00FAF0E6
colMagenta = 0x00FF00FF
colMaroon = 0x00800000
colMediumAquaMarine = 0x0066CDAA
colMediumBlue = 0x000000CD
colMediumOrchid = 0x00BA55D3
colMediumPurple = 0x009370D8
colMediumSeaGreen = 0x003CB371
colMediumSlateBlue = 0x007B68EE
colMediumSpringGreen = 0x0000FA9A
colMediumTurquoise = 0x0048D1CC
colMediumVioletRed = 0x00C71585
colMidnightBlue = 0x00191970
colMintCream = 0x00F5FFFA
colMistyRose = 0x00FFE4E1
colMoccasin = 0x00FFE4B5
colNavajoWhite = 0x00FFDEAD
colNavy = 0x00000080
colOldLace = 0x00FDF5E6
colOlive = 0x00808000
colOliveDrab = 0x006B8E23
colOrange = 0x00FFA500
colOrangeRed = 0x00FF4500
colOrchid = 0x00DA70D6
colPaleGoldenRod = 0x00EEE8AA
colPaleGreen = 0x0098FB98
colPaleTurquoise = 0x00AFEEEE
colPaleVioletRed = 0x00D87093
colPapayaWhip = 0x00FFEFD5
colPeachPuff = 0x00FFDAB9
colPeru = 0x00CD853F
colPink = 0x00FFC0CB
colPlum = 0x00DDA0DD
colPowderBlue = 0x00B0E0E6
colPurple = 0x00800080
colRed = 0x00FF0000
colRosyBrown = 0x00BC8F8F
colRoyalBlue = 0x004169E1
colSaddleBrown = 0x008B4513
colSalmon = 0x00FA8072
colSandyBrown = 0x00F4A460
colSeaGreen = 0x002E8B57
colSeaShell = 0x00FFF5EE
colSienna = 0x00A0522D
colSilver = 0x00C0C0C0
colSkyBlue = 0x0087CEEB
colSlateBlue = 0x006A5ACD
colSlateGray = 0x00708090
colSnow = 0x00FFFAFA
colSpringGreen = 0x0000FF7F
colSteelBlue = 0x004682B4
colTan = 0x00D2B48C
colTeal = 0x00008080
colThistle = 0x00D8BFD8
colTomato = 0x00FF6347
colTurquoise = 0x0040E0D0
colViolet = 0x00EE82EE
colWheat = 0x00F5DEB3
colWhite = 0x00FFFFFF
colWhiteSmoke = 0x00F5F5F5
colYellow = 0x00FFFF00
colYellowGreen = 0x009ACD32

Procs

proc `==`(a, b: Color): bool {.borrow.}
compares two colors.
proc `+`(a, b: Color): Color {.raises: [], tags: [].}
adds two colors: This uses saturated artithmetic, so that each color component cannot overflow (255 is used as a maximum).
proc `-`(a, b: Color): Color {.raises: [], tags: [].}
subtracts two colors: This uses saturated artithmetic, so that each color component cannot overflow (255 is used as a maximum).
proc extractRGB(a: Color): tuple[r, g, b: range[0 .. 255]] {.raises: [], tags: [].}
extracts the red/green/blue components of the color a.
proc intensity(a: Color; f: float): Color {.raises: [], tags: [].}
returns a with intensity f. f should be a float from 0.0 (completely dark) to 1.0 (full color intensity).
proc `$`(c: Color): string {.raises: [], tags: [].}
converts a color into its textual representation. Example: #00FF00.
proc parseColor(name: string): Color {.raises: [ValueError], tags: [].}
parses name to a color value. If no valid color could be parsed EInvalidValue is raised.
proc isColor(name: string): bool {.raises: [], tags: [].}
returns true if name is a known color name or a hexadecimal color prefixed with #.
proc rgb(r, g, b: range[0 .. 255]): Color {.raises: [], tags: [].}
constructs a color from RGB values.

Templates

template mix(a, b: Color; fn: untyped): untyped
uses fn to mix the colors a and b. fn is invoked for each component R, G, and B. This is a template because fn should be inlined and the compiler cannot inline proc pointers yet. If fn's result is not in the range[0..255], it will be saturated to be so.

© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/colors.html