Bitmap/Midpoint circle algorithm: Difference between revisions

Content added Content deleted
m (added whitespace.)
(Replaced "initImage" by "newImage" (change in "bitmap.nim" interface).)
Line 1,455: Line 1,455:
<lang Nim>import bitmap
<lang Nim>import bitmap


proc setPixel(img: var Image; x, y: int; color: Color) {.inline.} =
proc setPixel(img: Image; x, y: int; color: Color) {.inline.} =
# Set a pixel at a given color.
# Set a pixel at a given color.
# Ignore if the point is outside of the image.
# Ignore if the point is outside of the image.
Line 1,462: Line 1,462:




proc drawCircle(img: var Image; center: Point; radius: Natural; color: Color) =
proc drawCircle(img: Image; center: Point; radius: Natural; color: Color) =
## Draw a circle using midpoint circle algorithm.
## Draw a circle using midpoint circle algorithm.


Line 1,498: Line 1,498:


when isMainModule:
when isMainModule:
var img = initImage(16, 16)
var img = newImage(16, 16)
img.fill(White)
img.fill(White)
img.drawCircle((7, 7), 5, Black)
img.drawCircle((7, 7), 5, Black)