Bitmap/Bresenham's line algorithm: Difference between revisions

m
→‎ksh: fix category
m (→‎ksh: fix category)
Line 2,412:
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|Korn Shellksh}}==
<syntaxhighlight lang="textksh">function line {
typeset x0=$1; y0=$2 x1=$3; y1=$4
 
if (( x0 > x1 ))
then
((dx = x0 - x1)); ((sx = -1))
Line 2,424:
fi
 
if (( y0 > y1 ))
then
((dy = y0 - y1)); ((sy = -1))
Line 2,431:
fi
 
if (( dx > dy ))
then
((err = dx))
Line 2,439:
((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}}
559

edits