W3cubDocs

/Nim

Module colors

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

Imports

strutils, algorithm

Types

Color = distinct int
a color stored as RGB

Consts

colAliceBlue = 15792383
colAntiqueWhite = 16444375
colAqua = 65535
colAquamarine = 8388564
colAzure = 15794175
colBeige = 16119260
colBisque = 16770244
colBlack = 0
colBlanchedAlmond = 16772045
colBlue = 255
colBlueViolet = 9055202
colBrown = 10824234
colBurlyWood = 14596231
colCadetBlue = 6266528
colChartreuse = 8388352
colChocolate = 13789470
colCoral = 16744272
colCornflowerBlue = 6591981
colCornsilk = 16775388
colCrimson = 14423100
colCyan = 65535
colDarkBlue = 139
colDarkCyan = 35723
colDarkGoldenRod = 12092939
colDarkGray = 11119017
colDarkGreen = 25600
colDarkKhaki = 12433259
colDarkMagenta = 9109643
colDarkOliveGreen = 5597999
colDarkorange = 16747520
colDarkOrchid = 10040012
colDarkRed = 9109504
colDarkSalmon = 15308410
colDarkSeaGreen = 9419919
colDarkSlateBlue = 4734347
colDarkSlateGray = 3100495
colDarkTurquoise = 52945
colDarkViolet = 9699539
colDeepPink = 16716947
colDeepSkyBlue = 49151
colDimGray = 6908265
colDodgerBlue = 2003199
colFireBrick = 11674146
colFloralWhite = 16775920
colForestGreen = 2263842
colFuchsia = 16711935
colGainsboro = 14474460
colGhostWhite = 16316671
colGold = 16766720
colGoldenRod = 14329120
colGray = 8421504
colGreen = 32768
colGreenYellow = 11403055
colHoneyDew = 15794160
colHotPink = 16738740
colIndianRed = 13458524
colIndigo = 4915330
colIvory = 16777200
colKhaki = 15787660
colLavender = 15132410
colLavenderBlush = 16773365
colLawnGreen = 8190976
colLemonChiffon = 16775885
colLightBlue = 11393254
colLightCoral = 15761536
colLightCyan = 14745599
colLightGoldenRodYellow = 16448210
colLightGrey = 13882323
colLightGreen = 9498256
colLightPink = 16758465
colLightSalmon = 16752762
colLightSeaGreen = 2142890
colLightSkyBlue = 8900346
colLightSlateGray = 7833753
colLightSteelBlue = 11584734
colLightYellow = 16777184
colLime = 65280
colLimeGreen = 3329330
colLinen = 16445670
colMagenta = 16711935
colMaroon = 8388608
colMediumAquaMarine = 6737322
colMediumBlue = 205
colMediumOrchid = 12211667
colMediumPurple = 9662680
colMediumSeaGreen = 3978097
colMediumSlateBlue = 8087790
colMediumSpringGreen = 64154
colMediumTurquoise = 4772300
colMediumVioletRed = 13047173
colMidnightBlue = 1644912
colMintCream = 16121850
colMistyRose = 16770273
colMoccasin = 16770229
colNavajoWhite = 16768685
colNavy = 128
colOldLace = 16643558
colOlive = 8421376
colOliveDrab = 7048739
colOrange = 16753920
colOrangeRed = 16729344
colOrchid = 14315734
colPaleGoldenRod = 15657130
colPaleGreen = 10025880
colPaleTurquoise = 11529966
colPaleVioletRed = 14184595
colPapayaWhip = 16773077
colPeachPuff = 16767673
colPeru = 13468991
colPink = 16761035
colPlum = 14524637
colPowderBlue = 11591910
colPurple = 8388736
colRed = 16711680
colRosyBrown = 12357519
colRoyalBlue = 4286945
colSaddleBrown = 9127187
colSalmon = 16416882
colSandyBrown = 16032864
colSeaGreen = 3050327
colSeaShell = 16774638
colSienna = 10506797
colSilver = 12632256
colSkyBlue = 8900331
colSlateBlue = 6970061
colSlateGray = 7372944
colSnow = 16775930
colSpringGreen = 65407
colSteelBlue = 4620980
colTan = 13808780
colTeal = 32896
colThistle = 14204888
colTomato = 16737095
colTurquoise = 4251856
colViolet = 15631086
colWheat = 16113331
colWhite = 16777215
colWhiteSmoke = 16119285
colYellow = 16776960
colYellowGreen = 10145074

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. Case insensitive.
proc isColor(name: string): bool {...}{.raises: [], tags: [].}
returns true if name is a known color name or a hexadecimal color prefixed with #. Case insensitive.
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–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/colors.html