This module implements color handling for Nim, namely color mixing and parsing the CSS color names.
Consts
colAliceBlue = 15792383
- Source Edit
colAntiqueWhite = 16444375
- Source Edit
colAquamarine = 8388564
- Source Edit
colBlanchedAlmond = 16772045
- Source Edit
colBlueViolet = 9055202
- Source Edit
colBurlyWood = 14596231
- Source Edit
colCadetBlue = 6266528
- Source Edit
colChartreuse = 8388352
- Source Edit
colChocolate = 13789470
- Source Edit
colCornflowerBlue = 6591981
- Source Edit
colCornsilk = 16775388
- Source Edit
colCrimson = 14423100
- Source Edit
colDarkBlue = 139
- Source Edit
colDarkCyan = 35723
- Source Edit
colDarkGoldenRod = 12092939
- Source Edit
colDarkGray = 11119017
- Source Edit
colDarkGreen = 25600
- Source Edit
colDarkGrey = 11119017
- Source Edit
colDarkKhaki = 12433259
- Source Edit
colDarkMagenta = 9109643
- Source Edit
colDarkOliveGreen = 5597999
- Source Edit
colDarkorange = 16747520
- Source Edit
colDarkOrchid = 10040012
- Source Edit
colDarkRed = 9109504
- Source Edit
colDarkSalmon = 15308410
- Source Edit
colDarkSeaGreen = 9419919
- Source Edit
colDarkSlateBlue = 4734347
- Source Edit
colDarkSlateGray = 3100495
- Source Edit
colDarkSlateGrey = 3100495
- Source Edit
colDarkTurquoise = 52945
- Source Edit
colDarkViolet = 9699539
- Source Edit
colDeepPink = 16716947
- Source Edit
colDeepSkyBlue = 49151
- Source Edit
colDimGray = 6908265
- Source Edit
colDimGrey = 6908265
- Source Edit
colDodgerBlue = 2003199
- Source Edit
colFireBrick = 11674146
- Source Edit
colFloralWhite = 16775920
- Source Edit
colForestGreen = 2263842
- Source Edit
colFuchsia = 16711935
- Source Edit
colGainsboro = 14474460
- Source Edit
colGhostWhite = 16316671
- Source Edit
colGoldenRod = 14329120
- Source Edit
colGreenYellow = 11403055
- Source Edit
colHoneyDew = 15794160
- Source Edit
colHotPink = 16738740
- Source Edit
colIndianRed = 13458524
- Source Edit
colLavender = 15132410
- Source Edit
colLavenderBlush = 16773365
- Source Edit
colLawnGreen = 8190976
- Source Edit
colLemonChiffon = 16775885
- Source Edit
colLightBlue = 11393254
- Source Edit
colLightCoral = 15761536
- Source Edit
colLightCyan = 14745599
- Source Edit
colLightGoldenRodYellow = 16448210
- Source Edit
colLightGray = 13882323
- Source Edit
colLightGreen = 9498256
- Source Edit
colLightGrey = 13882323
- Source Edit
colLightPink = 16758465
- Source Edit
colLightSalmon = 16752762
- Source Edit
colLightSeaGreen = 2142890
- Source Edit
colLightSkyBlue = 8900346
- Source Edit
colLightSlateGray = 7833753
- Source Edit
colLightSlateGrey = 7833753
- Source Edit
colLightSteelBlue = 11584734
- Source Edit
colLightYellow = 16777184
- Source Edit
colLimeGreen = 3329330
- Source Edit
colMagenta = 16711935
- Source Edit
colMediumAquaMarine = 6737322
- Source Edit
colMediumBlue = 205
- Source Edit
colMediumOrchid = 12211667
- Source Edit
colMediumPurple = 9662683
- Source Edit
colMediumSeaGreen = 3978097
- Source Edit
colMediumSlateBlue = 8087790
- Source Edit
colMediumSpringGreen = 64154
- Source Edit
colMediumTurquoise = 4772300
- Source Edit
colMediumVioletRed = 13047173
- Source Edit
colMidnightBlue = 1644912
- Source Edit
colMintCream = 16121850
- Source Edit
colMistyRose = 16770273
- Source Edit
colMoccasin = 16770229
- Source Edit
colOldLace = 16643558
- Source Edit
colOliveDrab = 7048739
- Source Edit
colOrangeRed = 16729344
- Source Edit
colPaleGoldenRod = 15657130
- Source Edit
colPaleGreen = 10025880
- Source Edit
colPaleTurquoise = 11529966
- Source Edit
colPaleVioletRed = 14381203
- Source Edit
colPapayaWhip = 16773077
- Source Edit
colPeachPuff = 16767673
- Source Edit
colPowderBlue = 11591910
- Source Edit
colRebeccaPurple = 6697881
- Source Edit
colRosyBrown = 12357519
- Source Edit
colRoyalBlue = 4286945
- Source Edit
colSaddleBrown = 9127187
- Source Edit
colSandyBrown = 16032864
- Source Edit
colSeaGreen = 3050327
- Source Edit
colSeaShell = 16774638
- Source Edit
colSkyBlue = 8900331
- Source Edit
colSlateBlue = 6970061
- Source Edit
colSlateGray = 7372944
- Source Edit
colSlateGrey = 7372944
- Source Edit
colSpringGreen = 65407
- Source Edit
colSteelBlue = 4620980
- Source Edit
colThistle = 14204888
- Source Edit
colTurquoise = 4251856
- Source Edit
colWhiteSmoke = 16119285
- Source Edit
colYellowGreen = 10145074
- Source Edit
Procs
proc extractRGB(a: Color): tuple[r, g, b: range[0 .. 255]] {....raises: [], tags: [], forbids: [].}
-
Extracts the red/green/blue components of the color a.
Example:
var a = Color(0xff_00_ff) b = Color(0x00_ff_cc) type Col = range[0..255] # assert extractRGB(a) == (r: 255.Col, g: 0.Col, b: 255.Col) # assert extractRGB(b) == (r: 0.Col, g: 255.Col, b: 204.Col) echo extractRGB(a) echo typeof(extractRGB(a)) echo extractRGB(b) echo typeof(extractRGB(b))
Source Edit proc intensity(a: Color; f: float): Color {....raises: [], tags: [], forbids: [].}
-
Returns a with intensity f. f should be a float from 0.0 (completely dark) to 1.0 (full color intensity).
Example:
var a = Color(0xff_00_ff) b = Color(0x00_42_cc) assert a.intensity(0.5) == Color(0x80_00_80) assert b.intensity(0.5) == Color(0x00_21_66)
Source Edit proc parseColor(name: string): Color {....raises: [ValueError], tags: [], forbids: [].}
-
Parses name to a color value.
If no valid color could be parsed ValueError is raised. Case insensitive.
Example:
var a = "silver" b = "#0179fc" c = "#zzmmtt" assert parseColor(a) == Color(0xc0_c0_c0) assert parseColor(b) == Color(0x01_79_fc) doAssertRaises(ValueError): discard parseColor(c)
Source Edit
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. If fn's result is not in the range[0..255], it will be saturated to be so.
Example:
var a = Color(0x0a2814) b = Color(0x050a03) proc myMix(x, y: int): int = 2 * x - 3 * y assert mix(a, b, myMix) == Color(0x05_32_1f)
Source Edit