Xiaolin Wu's line algorithm: Difference between revisions

Content added Content deleted
(Add task to ARM assembly Raspberry pi)
(→‎{{header|Python}}: Fixed a bug related to endpoint drawing. Removed list concatenation to allow e.g. numpy arrays as inputs.)
Line 2,678: Line 2,678:
def draw_line(img, p1, p2, color):
def draw_line(img, p1, p2, color):
"""Draws an anti-aliased line in img from p1 to p2 with the given color."""
"""Draws an anti-aliased line in img from p1 to p2 with the given color."""
x1, y1, x2, y2 = p1 + p2
x1, y1 = p1
x2, y2 = p2
dx, dy = x2-x1, y2-y1
dx, dy = x2-x1, y2-y1
steep = abs(dx) < abs(dy)
steep = abs(dx) < abs(dy)
Line 2,696: Line 2,697:
xgap = _rfpart(x + 0.5)
xgap = _rfpart(x + 0.5)
px, py = int(xend), int(yend)
px, py = int(xend), int(yend)
putpixel(img, (px, py), color, _rfpart(yend) * xgap)
putpixel(img, p(px, py), color, _rfpart(yend) * xgap)
putpixel(img, (px, py+1), color, _fpart(yend) * xgap)
putpixel(img, p(px, py+1), color, _fpart(yend) * xgap)
return px
return px