Well, this probably not thé best way, but it is á way.
'p' contains the three corner-points.
p = {{ 3, 3 }, { 19, 8 }, { 12, 17 }}
x, y = term.getSize()
matrix = {}
for i = 1, x do
matrix[i] = {}
for j = 1, y do
matrix[i][j] = 0
end
end
function drawLine( startX, startY, endX, endY)
local minX = math.min( startX, endX )
if minX == startX then
minY = startY
maxX = endX
maxY = endY
else
minY = endY
maxX = startX
maxY = startY
end
local xDiff = maxX - minX
local yDiff = maxY - minY
if xDiff > math.abs(yDiff) then
local y = minY
local dy = yDiff / xDiff
for x=minX,maxX do
matrix[x][math.floor( y + 0.5 )] = 1
y = y + dy
end
else
local x = minX
local dx = xDiff / yDiff
if maxY >= minY then
for y=minY,maxY do
matrix[math.floor( x + 0.5 )][y] = 1
x = x + dx
end
else
for y=minY,maxY,-1 do
matrix[math.floor( x + 0.5 )][y] = 1
x = x - dx
end
end
end
end
drawLine(p[1][1], p[1][2], p[2][1], p[2][2])
drawLine(p[1][1], p[1][2], p[3][1], p[3][2])
drawLine(p[2][1], p[2][2], p[3][1], p[3][2])
for i = 1, x do
s, p1, p2 = 0, -1, -1
for j = 1, y do
if matrix[i][j] == 1 then
if s == 0 then
s = 1
p1 = j
elseif s == 2 then
s = 3
p2 = j
end
else
if s == 1 then
s = 2
end
end
if s == 3 then
for k = p1, p2 do
matrix[i][k] = 1
end
break
end
end
end
for i = 1, x do
for j = 1, y do
if matrix[i][j] == 1 then
term.setCursorPos(i, j)
write("#")
end
end
end
I must say, that i have 'borrowed' a piece of the paintutils api, so also credits to the creator of it :)/>