diff options
author | Andreas Rumpf <andreas@andreas-desktop> | 2010-03-04 23:42:19 +0100 |
---|---|---|
committer | Andreas Rumpf <andreas@andreas-desktop> | 2010-03-04 23:42:19 +0100 |
commit | f45a2f23b04aa1d37b482ba3d07980b73ce6a75d (patch) | |
tree | 5761b1d5dfea492f14052b3d2d640a374e49a454 /lib/pure | |
parent | 048811b2be4ac05415e0ef67777dfd297f7be4d6 (diff) | |
download | Nim-f45a2f23b04aa1d37b482ba3d07980b73ce6a75d.tar.gz |
bugfix: macro evaluation; added colors.extractRGB
Diffstat (limited to 'lib/pure')
-rwxr-xr-x | lib/pure/colors.nim | 10 | ||||
-rwxr-xr-x | lib/pure/math.nim | 2 | ||||
-rwxr-xr-x | lib/pure/strutils.nim | 4 |
3 files changed, 10 insertions, 6 deletions
diff --git a/lib/pure/colors.nim b/lib/pure/colors.nim index c0f7ad043..406a2f184 100755 --- a/lib/pure/colors.nim +++ b/lib/pure/colors.nim @@ -6,8 +6,8 @@ # distribution, for details about the copyright. # -## This module implements graphical output for Nimrod; the current -## implementation uses Cairo under the surface. +## This module implements color handling for Nimrod. It is used by +## the ``graphics`` module. import strutils @@ -53,6 +53,12 @@ proc `-`*(a, b: TColor): TColor = ## component cannot overflow (255 is used as a maximum). colorOp(satMinus) +proc extractRGB*(a: TColor): tuple[r, g, b: range[0..255]] = + ## extracts the red/green/blue components of the color `a`. + result.r = a.int shr 16 and 0xff + result.g = a.int shr 8 and 0xff + result.b = a.int and 0xff + 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/lib/pure/math.nim b/lib/pure/math.nim index cf4b6d95c..8e3dd4bdb 100755 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -172,6 +172,8 @@ when not defined(ECMAScript): proc randomize() = srand(gettime(nil)) proc random(max: int): int = return int(rand()) mod max + proc trunc*(x: float): float {.importc: "trunc", nodecl.} + else: proc mathrandom(): float {.importc: "Math.random", nodecl.} proc mathfloor(x: float): float {.importc: "Math.floor", nodecl.} diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 6459cfbd7..724d00ee9 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -162,15 +162,11 @@ iterator split*(s: string, seps: set[char] = Whitespace): string = ## produces the same output. var last = 0 assert(not ('\0' in seps)) - #echo "cam here 1", s while last < len(s): while s[last] in seps: inc(last) var first = last - #echo "A first: ", first, " last: ", last while last < len(s) and s[last] not_in seps: inc(last) # BUGFIX! - #echo "B first: ", first, " last: ", last if first <= last-1: - echo copy(s, first, last-1) yield copy(s, first, last-1) iterator split*(s: string, sep: char): string = |