summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-desktop>2010-03-04 23:57:06 +0100
committerAndreas Rumpf <andreas@andreas-desktop>2010-03-04 23:57:06 +0100
commitae3cddc01ed9f2835d78a2550be390074aab6b2d (patch)
tree7f84a113fd021f905622f3ccfbf956bfc514e43c /lib/pure
parentf45a2f23b04aa1d37b482ba3d07980b73ce6a75d (diff)
downloadNim-ae3cddc01ed9f2835d78a2550be390074aab6b2d.tar.gz
added colors.intensity
Diffstat (limited to 'lib/pure')
-rwxr-xr-xlib/pure/colors.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/colors.nim b/lib/pure/colors.nim
index 406a2f184..6a86a43c4 100755
--- a/lib/pure/colors.nim
+++ b/lib/pure/colors.nim
@@ -59,6 +59,17 @@ proc extractRGB*(a: TColor): tuple[r, g, b: range[0..255]] =
   result.g = a.int shr 8 and 0xff
   result.b = a.int and 0xff
   
+proc intensity*(a: TColor, f: float): TColor = 
+  ## returns `a` with intensity `f`. `f` should be a float from 0.0 (completely
+  ## dark) to 1.0 (full color intensity).
+  var r = toInt(toFloat(a.int shr 16 and 0xff) * f)
+  var g = toInt(toFloat(a.int shr 8 and 0xff) * f)
+  var b = toInt(toFloat(a.int and 0xff) * f)
+  if r >% 255: r = 255
+  if g >% 255: g = 255
+  if b >% 255: b = 255
+  result = rawRGB(r, g, b)
+  
 template mix*(a, b: TColor, fn: expr): expr =
   ## 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