Bitmap/Bresenham's line algorithm: Difference between revisions
Content deleted Content added
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> |
||
⚫ | |||
⚫ | |||
<syntaxhighlight lang=" |
<syntaxhighlight lang="ksh">function line { |
||
x0=$1 |
typeset x0=$1 y0=$2 x1=$3 y1=$4 |
||
if (( |
if ((x0 > x1)) |
||
then |
then |
||
((dx = x0 - x1)); ((sx = -1)) |
((dx = x0 - x1)); ((sx = -1)) |
||
Line 2,424: | Line 2,424: | ||
fi |
fi |
||
if (( |
if ((y0 > y1)) |
||
then |
then |
||
((dy = y0 - y1)); ((sy = -1)) |
((dy = y0 - y1)); ((sy = -1)) |
||
Line 2,431: | Line 2,431: | ||
fi |
fi |
||
if (( |
if ((dx > dy)) |
||
then |
then |
||
((err = dx)) |
((err = dx)) |
||
Line 2,439: | Line 2,439: | ||
((err /= 2)); ((e2 = 0)) |
((err /= 2)); ((e2 = 0)) |
||
while |
while : |
||
do |
do |
||
echo $x0 $y0 |
echo $x0 $y0 |
||
(( |
((x0 == x1 && y0 == y1)) && return |
||
((e2 = err)) |
((e2 = err)) |
||
(( |
((e2 > -dx)) && { ((err -= dy)); ((x0 += sx)) } |
||
(( |
((e2 < dy)) && { ((err += dx)); ((y0 += sy)) } |
||
done |
done |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
⚫ | |||
⚫ | |||
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</ |
3 4</pre> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{trans|C}} |
{{trans|C}} |