Hi guys,
I just updated my draft library to run with Love2D version 0.9.2.
I thought I would share it with the community!
The library extends the graphic primitives offered by Love2D (line, rectangle, polygon, etc..).
It makes it easy to draw such shapes as a trapezoid, a rhombus, a gem, a diamond, a kite, a bow, a dome, and many more...
One of the most powerful functions is the compass. draft:compass. It can be used to draw all kinds of curved shapes. You can even draw luxurious shapes with it, i.e. draft:star, draft:egg. Check it out!
Also, there are four functions called linkers which are quite powerful. They link a shape's vertice points to each other. For example, you could draw two independent shapes then have all their points interconnect with a linker.
The code lives on github: https://github.com/pelevesque/draft
It is completely free. If you use it, I just ask that you star the github repo. Thank you!
draft - a powerful drawing library
draft - a powerful drawing library
Last edited by pel on Wed Aug 19, 2015 2:07 am, edited 1 time in total.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: draft - a powerful drawing library
One thing,
You can make use of [wiki]love.math.triangulate[/wiki] to decompose convex polygons into triangles, then draw those filled; a few more draw calls, but it works!github wrote:Due to LÖVE 2D drawing limitations, the draft:star function fails in fill mode. This is because LÖVE 2D is unable to properly fill concave polygons.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: draft - a powerful drawing library
Thanks, I'll try that. Is it a new function in 0.9.2? I wrote this library a while back, like 2012, and just started updating it recently for the new version. Eager to try your triangulate idea. Gonna see if I can find some time today!
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: draft - a powerful drawing library
It's actually a 0.9.0 function (also, the wiki does tell you when a function was introduced / deprecated)
glad to have helped
glad to have helped
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: draft - a powerful drawing library
Thank you again!
I fixed the drawing of concave polygons with the love.math.isConvex() and love.math.triangulate() methods.
As you said, rather easy.
Now I'm wondering why Love 2D doesn't simply do this inside the native polygon method?
Before
After
I fixed the drawing of concave polygons with the love.math.isConvex() and love.math.triangulate() methods.
As you said, rather easy.
Now I'm wondering why Love 2D doesn't simply do this inside the native polygon method?
Before
Code: Select all
--[[
Draws a polygon
@param table vertices {x1, y1, x2, y2, ...}
@param mixed drawMode (fill, line, false) [def: self.mode]
@return table vertices {x1, y1, x2, y2, ...}
--]]
function draft:polygon(vertices, mode)
if mode == nil then mode = self.mode end
if mode then
love.graphics.polygon(mode, vertices)
end
return vertices
end
Code: Select all
--[[
Draws a polygon
@param table vertices {x1, y1, x2, y2, ...}
@param mixed drawMode (fill, line, false) [def: self.mode]
@return table vertices {x1, y1, x2, y2, ...}
--]]
function draft:polygon(vertices, mode)
if mode == nil then mode = self.mode end
if mode then
if (mode == 'fill' and not love.math.isConvex(vertices)) then
local triangles = love.math.triangulate(vertices)
for _, v in pairs(triangles) do
love.graphics.polygon('fill', v)
end
else
love.graphics.polygon(mode, vertices)
end
end
return vertices
end
Re: draft - a powerful drawing library
I've wondered the same thing too. See here.pel wrote:Now I'm wondering why Love 2D doesn't simply do this inside the native polygon method?
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- AntonioModer
- Party member
- Posts: 202
- Joined: Fri Jun 15, 2012 5:31 pm
- Location: Belarus
- Contact:
Re: draft - a powerful drawing library
Right, of course, screenshots!
BTW - I updated my repo. While making these two screenshots, I realized there was a bug in my triangle drawing routines. So, thank you! Should be bug free now.
Here is a screen shot of the test.lua file running. It runs all the methods in draft, so it gives a good overview of possible shapes.
Here is a screenshot of the example_linker.lua file running. You should run it yourself since it evolves over time!
Basically, I draw the egg shape so large that outside of the egg is outside the screen. Then I use draft:linkWeb to link all the points of the polygon to each other creating a tangled web of lines. You can do some pretty crazy stuff with the linkers. You should really try it.
Seriously, the draft:compass method is really powerful for drawing arcs and other curved shapes. And, as I stated above, the linkers are also very powerful.
I suggest you read the code. It's pretty clear.
Try it out!
BTW - I updated my repo. While making these two screenshots, I realized there was a bug in my triangle drawing routines. So, thank you! Should be bug free now.
Here is a screen shot of the test.lua file running. It runs all the methods in draft, so it gives a good overview of possible shapes.
Here is a screenshot of the example_linker.lua file running. You should run it yourself since it evolves over time!
Basically, I draw the egg shape so large that outside of the egg is outside the screen. Then I use draft:linkWeb to link all the points of the polygon to each other creating a tangled web of lines. You can do some pretty crazy stuff with the linkers. You should really try it.
Seriously, the draft:compass method is really powerful for drawing arcs and other curved shapes. And, as I stated above, the linkers are also very powerful.
I suggest you read the code. It's pretty clear.
Try it out!
Re: draft - a powerful drawing library
A quick extra note on the draft:compass method.
It's powerful because the scale argument accepts a function. This means you can change the size of the compass's arm as it circles around doing its drawing. Essentially, this means you are changing the size of the radius. That's how I draw the egg and the star shapes.
It's like the Spirograph game for kids.
You can do all sorts of drawings with it.
The library is worth it for this method alone.
It's based on this code: http://slabode.exofire.net/circle_draw.shtml
It's powerful because the scale argument accepts a function. This means you can change the size of the compass's arm as it circles around doing its drawing. Essentially, this means you are changing the size of the radius. That's how I draw the egg and the star shapes.
It's like the Spirograph game for kids.
You can do all sorts of drawings with it.
The library is worth it for this method alone.
It's based on this code: http://slabode.exofire.net/circle_draw.shtml
- AntonioModer
- Party member
- Posts: 202
- Joined: Fri Jun 15, 2012 5:31 pm
- Location: Belarus
- Contact:
Who is online
Users browsing this forum: No registered users and 3 guests