Bitmap/Bresenham's line algorithm: Difference between revisions
Content added Content deleted
m (minor tweaks to make more usable elsewhere on rc) |
|||
Line 2,316: | Line 2,316: | ||
end, |
end, |
||
get = function(self, x, y) |
get = function(self, x, y) |
||
x, y = x+1, y+1 |
x, y = math.floor(x+1), math.floor(y+1) |
||
if ((x>=1) and (x<=self.width) and (y>=1) and (y<=self.height)) then |
if ((x>=1) and (x<=self.width) and (y>=1) and (y<=self.height)) then |
||
return self.pixels[y][x] |
return self.pixels[y][x] |
||
Line 2,324: | Line 2,324: | ||
end, |
end, |
||
set = function(self, x, y, c) |
set = function(self, x, y, c) |
||
x, y = x+1, y+1 |
x, y = math.floor(x+1), math.floor(y+1) |
||
if ((x>=1) and (x<=self.width) and (y>=1) and (y<=self.height)) then |
if ((x>=1) and (x<=self.width) and (y>=1) and (y<=self.height)) then |
||
self.pixels[y][x] = c or 0x00000000 |
self.pixels[y][x] = c or 0x00000000 |
||
Line 2,341: | Line 2,341: | ||
local err = math.floor((dx>dy and dx or -dy)/2) |
local err = math.floor((dx>dy and dx or -dy)/2) |
||
while(true) do |
while(true) do |
||
self:set(x1, y1, 0xFFFFFFFF) |
self:set(x1, y1, c or 0xFFFFFFFF) |
||
if (x1==x2 and y1==y2) then |
if (x1==x2 and y1==y2) then |
||
break |
break |