Bitmap: Difference between revisions

589 bytes removed ,  3 years ago
m
Replace "col" by "x" and "row" by "y".
(Changed "x" and "y" by "col" and "row"; modified "print"; added "print" in example.)
m (Replace "col" by "x" and "row" by "y".)
Line 2,750:
 
=={{header|Nim}}==
<lang nim>type
type
Luminance* = uint8
Index* = int
Line 2,764 ⟶ 2,763:
Point* = tuple
x, y: Index
 
proc px*(r, g, b: SomeInteger): 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.setLen(w * h)
 
const
Black* = px( 0, 0, 0)
White* = px(255, 255, 255)
 
iterator indices*(img: Image): Point =
for x in 0 ..< img.w:
for y in 0 ..< img.h:
yield (x, y)type
Luminance* = uint8
Index* = int
 
Pixel* = tuple
r, g, b: Luminance
 
Image* = object
w*, h*: Index
pixels*: seq[Pixel]
 
Point* = tuple
col, row: Index
 
proc px*(r, g, b: SomeInteger): Pixel =
Line 2,814 ⟶ 2,782:
iterator indices*(img: Image): Point =
## Return a tuple
for rowy in 0 ..< img.h:
for colx in 0 ..< img.w:
yield (colx, rowy)
 
proc `[]`*(img: Image, colx, rowy: int): Pixel =
img.pixels[rowy * img.w + colx]
 
proc `[]=`*(img: var Image, colx, row: int, c: Pixel) =
img.pixels[row * img.w + colx] = c
 
proc fill*(img: var Image, color: Pixel) =
for colx, rowy in img.indices:
img[colx, rowy] = color
 
proc print*(img: Image) =
for colx, rowy in img.indices:
if colx mod img.w == 0:
stdout.write '\n'
stdout.write if img[colx, rowy] == White: '.' else: 'H'
stdout.write '\n'
 
Line 2,840 ⟶ 2,808:
img[1, 2] = px(255, 0, 0)
img[3, 4] = img[1, 2]
img.print</lang>
</lang>
 
=={{header|OCaml}}==
Anonymous user