Bitmap: Difference between revisions

Changed Image from object to ref object to allocate it on the heap.
(Replaced "Pixel" by "Color" and "px" by "color".)
(Changed Image from object to ref object to allocate it on the heap.)
Line 2,757:
r, g, b: Luminance
 
Image* = ref object
w*, h*: Index
pixels*: seq[Color]
Line 2,774:
White* = color(255, 255, 255)
 
proc initImagenewImage*(width, height: int): Image =
## Create an image with given width and height.
new(result)
result.w = width
result.h = height
Line 2,790 ⟶ 2,791:
img.pixels[y * img.w + x]
 
proc `[]=`*(img: var Image; x, y: int; c: Color) =
## Set a pixel RGB value to given color.
img.pixels[y * img.w + x] = c
 
proc fill*(img: var Image,; color: Color) =
## Fill the image with a color.
for x, y in img.indices:
Line 2,808 ⟶ 2,809:
 
when isMainModule:
var img = initImagenewImage(100, 20)
img.fill color(255, 255, 255)
img[1, 2] = color(255, 0, 0)
Anonymous user