Rounded-cornered rectangles with borders

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Rounded-cornered rectangles with borders

Post 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.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Rounded-cornered rectangles with borders

Post by Robin »

One caveat: it doesn't work so well with alpha anything other than 255 (or 0 ;)).
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 55 guests