Page 1 of 1

Rounded-cornered rectangles with borders

Posted: Fri Feb 12, 2010 2:52 pm
by kikito
I just wanted to share this function for drawing rounded cornered rectangles.

http://code.google.com/p/love-passion/s ... tangle.lua

I use it internally in PÄSSION, but you can change that file quite easily in case you want rounded corners - just remove the 'require' at the beggining and the passion.graphics from the function declaration. The first lines of your file should be:

Code: Select all

-- removed require from here
local math_round = function (num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end
function roundedRectangle(style, x, y, width, height, r)
...
This function is able to draw "filled" rectangles (using this algorithm in the wiki) and also "line" ones. I had to do some graphical trickery in order to have nice looking arcs, since they aren't provided by LÖVE.

Re: Rounded-cornered rectangles with borders

Posted: Fri Feb 12, 2010 3:56 pm
by Robin
One caveat: it doesn't work so well with alpha anything other than 255 (or 0 ;)).