Anonymous user
Bitmap/Bresenham's line algorithm: Difference between revisions
Bitmap/Bresenham's line algorithm (view source)
Revision as of 05:06, 9 November 2023
, 7 months ago→{{header|MiniScript}}
imported>Chinhouse |
imported>Chinhouse |
||
Line 2,837:
<syntaxhighlight lang="miniscript">
Img = new Image
Img.
if c == null then c = color.black
i = Image.create(w,h, c)
j = new Img
j._handle = i._handle
j.width = w
j.height = h
return j
end function
Img.pixelColor = color.white
Img.line = function(x1, y1, x2, y2)
dx = abs(x2 - x1)
sx = -1 * -(x1 < x2)
Line 2,846 ⟶ 2,856:
er = floor(er / 2)
while true
self.setPixel x1, y1,
if x1 == x2 and y1 == y2 then break
e2 = er
Line 2,859 ⟶ 2,869:
end while
end function
img= Img.create(320, 320)
img.line 0,0, 250, 300
gfx.drawImage img, 0, 0
</syntaxhighlight>
|