Bitmap/Bresenham's line algorithm: Difference between revisions

Content added Content deleted
m (→‎ksh: fix category)
Line 2,412: 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}(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>
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 ))
if ((x0 > x1))
then
then
((dx = x0 - x1)); ((sx = -1))
((dx = x0 - x1)); ((sx = -1))
Line 2,424: Line 2,424:
fi
fi


if (( y0 > y1 ))
if ((y0 > y1))
then
then
((dy = y0 - y1)); ((sy = -1))
((dy = y0 - y1)); ((sy = -1))
Line 2,431: Line 2,431:
fi
fi


if (( dx > dy ))
if ((dx > dy))
then
then
((err = dx))
((err = dx))
Line 2,439: Line 2,439:
((err /= 2)); ((e2 = 0))
((err /= 2)); ((e2 = 0))


while /bin/true
while :
do
do
echo $x0 $y0
echo $x0 $y0
(( x0 == x1 && y0 == y1 )) && return
((x0 == x1 && y0 == y1)) && return
((e2 = err))
((e2 = err))
(( e2 > -dx)) && { ((err -= dy )); (( x0 += sx )) }
((e2 > -dx)) && { ((err -= dy)); ((x0 += sx)) }
(( e2 < dy)) && { ((err += dx )); (( y0 += sy )) }
((e2 < dy)) && { ((err += dx)); ((y0 += sy)) }

done
done
}</syntaxhighlight>
}</syntaxhighlight>
Output from the statement:

Output from the statement:-
line 0 0 3 4
line 0 0 3 4
(which could be piped to another program)
(which could be piped to another program)
<pre>0 0
<syntaxhighlight lang="text">0 0
1 1
1 1
1 2
1 2
2 3
2 3
3 4</syntaxhighlight>
3 4</pre>

=={{header|Lua}}==
=={{header|Lua}}==
{{trans|C}}
{{trans|C}}