Rounded Rectangles
Posted: Mon Feb 17, 2014 4:32 pm
So due to boredom i decided to try and make rounded rectangles in löve. And then i did. And here it is.
The way it works is very simple, It draws a couple rectangles in this formation:
Then fills in the corners using arcs
Put it all together and you get this:
These were drawn with the "line" mode for illustration purposes.
Syntax is like a normal rectangle except it has an extra "radius" argument which is the corner radius (How round the rectangle is).
I attached a little demo as well, You can create rounded rectangles by clicking and dragging. first click should be the top left corner, and where you let go should be the bottom right corner, does not work properly the other way around cause i'm lazy.
But yeah, Perhaps someone, somewhere, some day will find this useful.
Code: Select all
function round_rectangle(x, y, width, height, radius)
--RECTANGLES
love.graphics.rectangle("fill", x + radius, y + radius, width - (radius * 2), height - radius * 2)
love.graphics.rectangle("fill", x + radius, y, width - (radius * 2), radius)
love.graphics.rectangle("fill", x + radius, y + height - radius, width - (radius * 2), radius)
love.graphics.rectangle("fill", x, y + radius, radius, height - (radius * 2))
love.graphics.rectangle("fill", x + (width - radius), y + radius, radius, height - (radius * 2))
--ARCS
love.graphics.arc("fill", x + radius, y + radius, radius, math.rad(-180), math.rad(-90))
love.graphics.arc("fill", x + width - radius , y + radius, radius, math.rad(-90), math.rad(0))
love.graphics.arc("fill", x + radius, y + height - radius, radius, math.rad(-180), math.rad(-270))
love.graphics.arc("fill", x + width - radius , y + height - radius, radius, math.rad(0), math.rad(90))
end
Then fills in the corners using arcs
Put it all together and you get this:
These were drawn with the "line" mode for illustration purposes.
Syntax is like a normal rectangle except it has an extra "radius" argument which is the corner radius (How round the rectangle is).
I attached a little demo as well, You can create rounded rectangles by clicking and dragging. first click should be the top left corner, and where you let go should be the bottom right corner, does not work properly the other way around cause i'm lazy.
But yeah, Perhaps someone, somewhere, some day will find this useful.