The script itself can be found here:
https://github.com/FeynmanTech/TPT-Vector-Graphics (it's main.lua).
This library can be used by anyone, no credit needed, in a script or by itself.
UPCOMING:
Automatic calculating of gap at each step - I've found the algorithms, I just need to implement them. - Done for ellipse
Better line function, that works lower-level than repeated calling of a point function
The main functions are:
aa.point
Usage: aa.point ( x coordinate , y coordinate )
aa.line
Usage: aa.line ( start x , start y , end x , end y )
aa.star
Usage: aa.star ( dist. between lines (degrees) , radius )
This was just added for testing different line algorithms
aa.ellipse
Usage: aa.ellipse ( x , y , width , height [, accuracy [, gap between points ]] )
Gap takes some experimenting to find a good level.
aa.bezier
Usage: aa.bezier ( x1 , y1 , x2 , y2 , control x1 , control y1 , control x2 , control y2
aa.bezrandom
Usage: aa.bezrandom ( )
This was just used for testing various Bézier curve algorithms
Note: the point and line functions both have rasterized, aliased counterparts in the 'ra' table.
I will be posting detailed instructions for it soon.
Please Note: The ellipse and bezier functions are still not working perfectly - they sometimes draw with poor antialiasing or with gaps between drawn lines. The ellipse is more or less usable, but the Bézier curves are still under development.
You can find examples of the library in this save:
yummy. Sort of art-plotting, but very low level. I like it.
Ok, so you've done this before. So what? I'm not doing this to compete with you.
Thanks :)
By the way, yeah, I know he's saying stuff that could be useful, but when he throws in, "I've dont this exact thing before, and it was way more antialiased than yours", that sort of sends a mixed message...
local function ellipticdist(rx, ry, d)
return sqrt((rx * sin(d)) ^ 2 + (ry * cos(d)) ^ 2)
end
function vec.ellipse(x, y, rx, ry, c)
local off = atan2(ry, rx) -- make sure we don't start at 0 if rx is small
local d = off
while d < 2 * pi + off do
vec.pixel(x + rx * sin(d), y + ry * cos(d), c)
-- 2 elements is pretty much enough
local step = 1 / ellipticdist(ry, rx, d)
step = 1 / ellipticdist(ry, rx, d + step / 2)
d = d + step
end
end
Do you mind if I use your algorithms? They do seem to work much better than mine.
(And the swapping of end points in my line function was left over from my old algorithm, I should delete it)
Great, thanks! I'll make sure to give you credit.