mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-24 08:15:25 +00:00
bugfix: macro evaluation; added colors.extractRGB
This commit is contained in:
@@ -150,7 +150,7 @@ proc drawLine*(sur: PSurface, p1, p2: TPoint, color: TColor) =
|
||||
setPix(video, pitch, x0, y0, color)
|
||||
|
||||
proc drawHorLine*(sur: PSurface, x, y, w: Natural, Color: TColor) =
|
||||
## draws a horizontal line from (x,y) to (x+w-1, h).
|
||||
## draws a horizontal line from (x,y) to (x+w-1, y).
|
||||
var video = cast[PPixels](sur.s.pixels)
|
||||
var pitch = sur.s.pitch div ColSize
|
||||
for i in 0 .. w-1: setPix(video, pitch, x + i, y, color)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user