Bitmap/Bresenham's line algorithm: Difference between revisions

mNo edit summary
imported>Chinhouse
(10 intermediate revisions by 5 users not shown)
Line 773:
END start
</pre>
=={{header|ATS}}==
See [[Bresenham_tasks_in_ATS]].
 
=={{header|AutoHotkey}}==
 
Line 794 ⟶ 797:
}
}</syntaxhighlight>
 
=={{header|AutoIt}}==
 
Line 1,470 ⟶ 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 . .
dx = abs (x1 - x0)
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,530 ⟶ 1,581:
 
</syntaxhighlight>
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
Line 2,408 ⟶ 2,460:
Gray{Float64}(255.0) Gray{Float64}(255.0) Gray{Float64}(255.0) Gray{Float64}(0.0) Gray{Float64}(255.0)
Gray{Float64}(255.0) Gray{Float64}(255.0) Gray{Float64}(255.0) Gray{Float64}(255.0) Gray{Float64}(0.0) </pre>
=={{header|Korn Shell}}==
 
=={{header|ksh}}==
<syntaxhighlight lang="text">function line {
<syntaxhighlight lang="ksh">function line {
x0=$1; y0=$2 x1=$3; y1=$4
typeset x0=$1 y0=$2 x1=$3 y1=$4
 
if (( x0 > x1 ))
then
((dx = x0 - x1)); ((sx = -1))
Line 2,420 ⟶ 2,472:
fi
 
if (( y0 > y1 ))
then
((dy = y0 - y1)); ((sy = -1))
Line 2,427 ⟶ 2,479:
fi
 
if (( dx > dy ))
then
((err = dx))
Line 2,435 ⟶ 2,487:
((err /= 2)); ((e2 = 0))
 
while /bin/true:
do
echo $x0 $y0
(( x0 == x1 && y0 == y1 )) && return
((e2 = err))
(( e2 > -dx)) && { ((err -= dy )); (( x0 += sx )) }
(( e2 < dy)) && { ((err += dx )); (( y0 += sy )) }
 
done
}</syntaxhighlight>
Output from the statement:
 
Output from the statement:-
line 0 0 3 4
(which could be piped to another program)
<pre>0 0
<syntaxhighlight lang="text">0 0
1 1
1 2
2 3
3 4</syntaxhighlightpre>
 
=={{header|Lua}}==
{{trans|C}}
Line 2,781 ⟶ 2,832:
}
}</syntaxhighlight>
 
=={{header|MiniScript}}==
This GUI implementation is for use with [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
drawLine = function(img, x0, y0, x1, y1, colr)
sign = function(a, b)
if a < b then return 1
return -1
end function
dx = abs(x1 - x0)
sx = sign(x0, x1)
dy = abs(y1 - y0)
sy = sign(y0, y1)
if dx > dy then
err = dx
else
err = -dy
end if
err = floor(err / 2)
while true
img.setPixel x0, y0, colr
if x0 == x1 and y0 == y1 then break
e2 = err
if e2 > -dx then
err -= dy
x0 += sx
end if
if e2 < dy then
err += dx
y0 += 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>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import bitmap
Line 4,241 ⟶ 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,298 ⟶ 4,393:
static draw(alpha) {}
}</syntaxhighlight>
 
=={{header|XPL0}}==
Bresenham line draw is built-in.
Anonymous user