added colors.intensity

This commit is contained in:
Andreas Rumpf
2010-03-04 23:57:06 +01:00
parent f45a2f23b0
commit ae3cddc01e
2 changed files with 12 additions and 0 deletions

View File

@@ -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

View File

@@ -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.