Anonymous user
Bitmap/Bresenham's line algorithm: Difference between revisions
Bitmap/Bresenham's line algorithm (view source)
Revision as of 17:41, 9 November 2023
, 6 months ago→{{header|MiniScript}}
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 . .
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">
return -1
▲ dy = abs(y2 - y1)
end function
sy = -1 * -(y1 < y2)▼
er = -dy▼
sy = sign(y0, y1)
if dx > dy then
err = dx
else
end if
err = floor(err / 2)
while true
if
e2 =
if e2 > -dx then
end if
if e2 < dy then
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="
import "dome" for Window
Line 4,329 ⟶ 4,393:
static draw(alpha) {}
}</syntaxhighlight>
=={{header|XPL0}}==
Bresenham line draw is built-in.
|