Bitmap/Bresenham's line algorithm: Difference between revisions

Content added Content deleted
imported>Chinhouse
imported>Chinhouse
Line 2,837: Line 2,837:
<syntaxhighlight lang="miniscript">
<syntaxhighlight lang="miniscript">
Img = new Image
Img = new Image
Img.line = function(x1, y1, x2, y2, colr)
Img.create = function(w,h,c)
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)
dx = abs(x2 - x1)
sx = -1 * -(x1 < x2)
sx = -1 * -(x1 < x2)
Line 2,846: Line 2,856:
er = floor(er / 2)
er = floor(er / 2)
while true
while true
self.setPixel x1, y1, colr
self.setPixel x1, y1, self.pixelColor
if x1 == x2 and y1 == y2 then break
if x1 == x2 and y1 == y2 then break
e2 = er
e2 = er
Line 2,859: Line 2,869:
end while
end while
end function
end function

img= Img.create(320, 320)
img.line 0,0, 250, 300
gfx.drawImage img, 0, 0

</syntaxhighlight>
</syntaxhighlight>