Bitmap/Bresenham's line algorithm: Difference between revisions

imported>Chinhouse
imported>Chinhouse
 
Line 2,836:
This GUI implementation is for use with [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
Img.linedrawLine = function(img, x0, y0, x1, y1, colr)
Img = new Image
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.line = function(x0, y0, x1, y1, colr)
sign = function(a, b)
if a < b then return 1
Line 2,866 ⟶ 2,856:
while true
selfimg.setPixel x0, y0, colr
if x0 == x1 and y0 == y1 then break
e2 = err
Line 2,878 ⟶ 2,868:
end if
end while
self.setPixel x0, y0, colr
end function
 
img= ImgImage.create(320, 320)
drawLine img.line, 0, 0, 250, 300, color.red
gfx.clear
gfx.drawImage img, 0, 0
Anonymous user