Bitmap/Bresenham's line algorithm: Difference between revisions

imported>Chinhouse
imported>Chinhouse
(3 intermediate revisions by the same user not shown)
Line 2,836:
This GUI implementation is for use with [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
drawLine = function(img, x0, y0, x1, y1, colr)
Img = new Image
Img.line sign = function(x1a, y1, x2, y2, colrb)
if dxa >< dyb then erreturn = dx1
dx = abs(x2 - x1)
return -1
sx = -1 * -(x1 < x2)
end function
dy = abs(y2 - y1)
sy = -1 * -(y1 < y2)
erdx = abs(x1 -dy x0)
sx = sign(x0, x1)
if dx > dy then er = dx
er = floor(er / 2)
dxdy = abs(x2y1 - x1y0)
dysy = abssign(y2 -y0, y1)
if dx > dy then
err = dx
else
err = -dy
end if
ererr = floor(ererr / 2)
while true
selfimg.setPixel x1x0, y1y0, colr
if x1x0 == x2x1 and y1y0 == y2y1 then break
e2 = ererr
if e2 > -dx then
ererr -= er - dy
x1x0 += x1 + sx
end if
if e2 < dy then
ererr += er + dx
y1y0 += y1 + sy
end if
end while
end function
 
img= Image.create(320, 320)
drawLine img, 0, 0, 250, 300, color.red
gfx.clear
gfx.drawImage img, 0, 0
</syntaxhighlight>
 
Anonymous user