Bitmap/Bresenham's line algorithm: Difference between revisions

imported>Chinhouse
imported>Chinhouse
 
(6 intermediate revisions by 3 users not shown)
Line 1,474:
drawLine(i, 1, 1, 3, 18, makeColor.fromFloat(0,1,1))
i.writePPM(<import:java.io.makeFileOutputStream>(<file:~/Desktop/Bresenham.ppm>))</syntaxhighlight>
=={{header|EasyLang}}==
 
[https://easylang.dev/show/#cod=XZHNboMwEITvPMUeG0W4NrSHSnHehQRHQkoJMiRl3z6zePkrAsv7MTNe2118XKnrw0AjMRkyGRH9Pl4B9Sd9gWEUFsN1IGuK72nITNaJs47V371pobbElkZH7OaUeiRP1aWnD+AcioPQXmjuZNrcxHaCS6r531SkAJ4DWAJYA3gbwBLASwDvAkKMokVO3byoUAv6OiNbLUkDtkhM2m4XqkE16Xxkhwqe7dDchXjZctXW0odf+wgFKiRriUVBzuhkVKIL535tBA8Cjx6noMTs7KedVNxH6XtFnNy8dRtc1HJHhbXk5LUyXbmC6St/7N4AQOV/R7lxOJu9AQ== Run it]
 
{{trans|C}}
 
<syntaxhighlight>
proc pset x y . .
move x / 4 y / 4
rect 0.25 0.25
.
proc drawline x0 y0 x1 y1 . .
dy dx = abs (y2x1 - y1x0)
sx = -1
if x0 < x1
sx = 1
.
dy = abs (y1 - y0)
sy = -1
if y0 < y1
sy = 1
.
err = -dy div 2
if dx > dy
err = dx div 2
.
repeat
pset x0 y0
until x0 = x1 and y0 = y1
e2 = err
if e2 > -dx
err -= dy
x0 += sx
.
if e2 < dy
err += dx
y0 += sy
.
.
.
drawline 200 10 100 200
drawline 100 200 200 390
drawline 200 390 300 200
drawline 300 200 200 10
</syntaxhighlight>
 
 
=={{header|Elm}}==
 
Line 1,534 ⟶ 1,581:
 
</syntaxhighlight>
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
Line 2,788 ⟶ 2,836:
This GUI implementation is for use with [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
Img.linedrawLine = function(x1img, y1x0, x2y0, y2x1, y1, colr)
dxsign = absfunction(x2a, - x1b)
sx if =a -1< *b -(x1then <return x2)1
return -1
dy = abs(y2 - y1)
end function
sy = -1 * -(y1 < y2)
er = -dy
if dx >= dyabs(x1 then- er = dxx0)
ersx = floorsign(erx0, / 2x1)
sydy = -1 * -abs(y1 <- y2y0)
sy = sign(y0, y1)
if dx > dy then
err = dx
else
er err = -dy
end if
err = floor(err / 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>
 
Line 4,272 ⟶ 4,336:
{{libheader|DOME}}
Requires version 1.3.0 of DOME or later.
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, ImageData, Color
import "dome" for Window
 
Line 4,329 ⟶ 4,393:
static draw(alpha) {}
}</syntaxhighlight>
 
=={{header|XPL0}}==
Bresenham line draw is built-in.
Anonymous user