Bitmap: Difference between revisions
Content added Content deleted
(Update to work with version 1.2.x.) |
m (→{{header|Nim}}) |
||
Line 2,751: | Line 2,751: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim> |
<lang nim> |
||
import unsigned |
|||
type |
type |
||
Luminance = uint8 |
|||
Index = int |
|||
Pixel = tuple |
|||
r, g, b: Luminance |
|||
Image = object |
|||
w, h: Index |
|||
pixels: seq[Pixel] |
|||
Point = tuple |
|||
x, y: Index |
|||
proc px(r, g, b): Pixel = |
|||
result.r = r.uint8 |
|||
result.g = g.uint8 |
|||
result.b = b.uint8 |
|||
proc img(w, h: int): Image = |
|||
result.w = w |
|||
result.h = h |
|||
result.pixels.newSeq(w * h) |
|||
const |
|||
Black = px( 0, 0, 0) |
|||
White = px(255, 255, 255) |
|||
iterator indices(img: Image): tuple[x, y: int] = |
|||
for x in 0 .. < img.w: |
|||
for y in 0 .. < img.h: |
|||
yield (x,y) |
|||
proc `[]`(img: Image, x, y: int): Pixel = |
|||
img.pixels[y * img.w + x] |
|||
proc `[]=`(img: var Image, x, y: int, c: Pixel) = |
|||
img.pixels[y * img.w + x] = c |
|||
proc fill(img: var Image, color: Pixel) = |
|||
for x,y in img.indices: |
|||
img[x,y] = color |
|||
proc print(img: Image) = |
|||
using stdouttype |
|||
Luminance* = uint8 |
Luminance* = uint8 |
||
Index* = int |
Index* = int |