167 posts
Posted 28 October 2014 - 02:29 AM
Anti Aliased line.. only works on a black background. It's the thought that counts though, right?
(click image to enlarge)
pixelWithAlpha = function(x,y,a) -- Pseudo Alpha channel. Only works with black background (for obvious reasons)
alphaStep = 255 / 4
if a > 255 - alphaStep then
term.setBackgroundColor(colors.white)
elseif a > 255 - alphaStep * 2 then
term.setBackgroundColor(colors.lightGray)
elseif a > 255 - alphaStep * 3 then
term.setBackgroundColor(colors.gray)
else
term.setBackgroundColor(colors.black)
return
end
term.setCursorPos(x,y)
term.write(" ")
end
aaLine = function(x0, y0, x1, y1)
dx = math.abs(x1-x0)
if x0<x1 then sx = 1 else sx = -1 end
dy = math.abs(y1-y0)
if y0<y1 then sy = 1 else sy = -1 end
err = dx-dy
if dx + dy == 0 then
ed = 1
else
ed = math.sqrt(dx*dx+dy*dy)
end
while true do
pixelWithAlpha(x0,y0, 255 - (255 * math.abs(err-dx+dy)/ed));
e2 = err
x2 = x0
if (2*e2 >= -dx) then
if (x0 == x1) then break end
if (e2+dy < ed) then pixelWithAlpha(x0,y0+sy, 255 - (255*(e2+dy)/ed)) end
err = err - dy;
x0 = x0 + sx;
end
if (2*e2 <= dy) then
if (y0 == y1) then break end
if (dx-e2 < ed) then pixelWithAlpha(x2+sx,y0, 255 - (255*(dx-e2)/ed)) end
err = err + dx;
y0 = y0 + sy;
end
end
end
term.setBackgroundColor(colors.black)
term.clear()
aaLine(0,0,10,19)
paintutils.drawLine(5,0,15,19,colors.white)
or
http://pastebin.com/BwbmMTmQ
Edited on 28 October 2014 - 04:11 PM
139 posts
Posted 28 October 2014 - 02:33 AM
Is the monitor scale 0.5? it doesnt looks like it
167 posts
Posted 28 October 2014 - 02:35 AM
It is.
2151 posts
Location
Auckland, New Zealand
Posted 28 October 2014 - 05:50 AM
Pretty neat, you could also look in to using characters rather than colours.
7083 posts
Location
Tasmania (AU)
Posted 28 October 2014 - 06:54 AM
"Characters other than spaces", I guess you mean?
2151 posts
Location
Auckland, New Zealand
Posted 28 October 2014 - 07:10 AM
8543 posts
Posted 28 October 2014 - 02:28 PM
Moved to Programs.
167 posts
Posted 28 October 2014 - 03:59 PM
Moved to Programs.
I hadn't put it in programs because it's not a program, It's just two functions.
598 posts
Location
The United States
Posted 28 October 2014 - 04:21 PM
Moved to Programs.
I hadn't put it in programs because it's not a program, It's just two functions.
Agreed. It would be better in APIs/Utilities or back in its home in General.
8543 posts
Posted 28 October 2014 - 04:47 PM
It's kind of ambiguous. It's a demo with working code (similar to Gopher's fire demo), but not necessarily a complete program as written. Hmm. It makes more sense being in the Programs section, as it will be more easily searchable if someone is looking for code. General might be better for short-term attention and visibility, but Programs or a subsection thereof is better for long term ease of seachability and visibility. I'll move it once more, wherever you'd prefer (within reason! :P/> ), but then it stays where it's at. Your choice.
167 posts
Posted 28 October 2014 - 05:04 PM
Heh, Don't worry about it Lyqyd. I'll just add a couple lines to make it runnable. :)/>