From ae3cddc01ed9f2835d78a2550be390074aab6b2d Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 4 Mar 2010 23:57:06 +0100 Subject: [PATCH] added colors.intensity --- lib/pure/colors.nim | 11 +++++++++++ web/news.txt | 1 + 2 files changed, 12 insertions(+) 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 diff --git a/web/news.txt b/web/news.txt index 9c9322826..19be8a4bd 100755 --- a/web/news.txt +++ b/web/news.txt @@ -34,6 +34,7 @@ Additions - Added ``system.delete``, ``system.del`` and ``system.insert`` for sequences. - Exported ``system.newException`` template. - Added ``cgi.decodeData(data: string): tuple[key, value: string]``. +- Added ``math.trunc``. - Added ``ropes`` module. - Added ``sockets`` module. - Added ``browsers`` module.