GopherAtl, on 08 September 2012 - 05:28 AM, said:
Just threw together a basic line drawing function in terminal, and a program to use it to do a basic dancing line. Time so far: ~45 minutes. Later will make a logo API with penUp/Down, penChar, turn, turnTo, forward, and moveTo functions.
http://pastebin.com/iJYzitra
works with any size monitors if you run it as "monitor <side> dancingLine" (or whatever you named it in the pastebin get)
stop with ctrl-T
:edit:
after a break went back and spent another 45 mins or so of effort. Now have logo API...
http://pastebin.com/vn5B8ZUg (save as "logo" for the sample program to load and use it properly)
and the sample program...
http://pastebin.com/QyCQAhqP
I'll be fair, you did actually go and do it, and in that situation vector graphics are better,
but when I tried the following:
function line(x1,y1,x2,y2)
local distX=x2-x1
local distY=y2-y1
if math.abs(distX)>math.abs(distY) then
--step over x
local stepx=1
if x2<x1 then
stepx=-1
end
local stepy=stepx*distY/distX
local y=y1
for x=x1,x2,stepx do
term.setCursorPos(x,y)
term.write("x")
y=y+stepy
end
else
--step over y
local stepy=1
if y2<y1 then
stepy=-1
end
local stepx=stepy*distX/distY
local x=x1
for y=y1,y2,stepy do
term.setCursorPos(x,y)
term.write("x")
x=x+stepx
end
end
end
term.clear()
line(3,9,2,2)
line(3,9,7,4)
line(7,4,2,2)
term.setCursorPos(12,12)
The results weren't exactly the 3 lines expected, so needless to say it needs a bit of work.
The whole 'real line' to 'pixel line' thing is the main reason I say vector graphics aren't as simple as you would first expect.
Not saying they aren't useful, but there are reasons that they have yet to replace raster graphics, and I doubt it's merely because raster graphics are more user friendly, because as any programmer knows, with the right user interface, even complex tasks can look simple.
I do however encourage you to keep doing what you are doing and hopefully figure out why some of these little obscurities occur and how to get around them.











