Bitmap/Bresenham's line algorithm: Difference between revisions

Added "import bitmap", adding pixel parameter (color), adding example and output.
(→‎{{header|Wart}}: Separated Wren from Wart entry and fixed an error.)
(Added "import bitmap", adding pixel parameter (color), adding example and output.)
Line 2,622:
 
=={{header|Nim}}==
<lang nim>import mathbitmap
 
proc linedrawLine(img: var Image,; p, q: Point; pixel: Pixel) =
let
dx = abs(q.x - p.x)
Line 2,638:
 
while true:
img[p.x, p.y] = Blackpixel
if p == q:
break
Line 2,647:
if e2 < dy:
err += dx
p.y += sy</lang>
 
when isMainModule:
var img = initImage(16, 16)
img.fill(White)
img.drawLine((0, 7), (7, 15), Black)
img.drawLine((7, 15), (15, 7), Black)
img.drawLine((15, 7), (7, 0), Black)
img.drawLine((7, 0), (0, 7), Black)
img.print()</lang>
 
{{out}}
<pre>.......H........
......H.H.......
.....H...H......
....H.....H.....
...H.......HH...
..H..........H..
.H............H.
H..............H
.H............H.
..H..........H..
...H........H...
...H.......H....
....H.....H.....
.....H...H......
......H.H.......
.......H........</pre>
 
=={{header|OCaml}}==
Anonymous user