Skip to content

Instantly share code, notes, and snippets.

@gvx
Created February 18, 2014 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvx/9072860 to your computer and use it in GitHub Desktop.
Save gvx/9072860 to your computer and use it in GitHub Desktop.
Rounded rectangles
function love.graphics.roundrect(mode, x, y, width, height, xround, yround)
local points = {}
local precision = (xround + yround) * .1
local tI, hP = table.insert, .5*math.pi
if xround > width*.5 then xround = width*.5 end
if yround > height*.5 then yround = height*.5 end
local X1, Y1, X2, Y2 = x + xround, y + yround, x + width - xround, y + height - yround
local sin, cos = math.sin, math.cos
for i = 0, precision do
local a = (i/precision-1)*hP
tI(points, X2 + xround*cos(a))
tI(points, Y1 + yround*sin(a))
end
for i = 0, precision do
local a = (i/precision)*hP
tI(points, X2 + xround*cos(a))
tI(points, Y2 + yround*sin(a))
end
for i = 0, precision do
local a = (i/precision+1)*hP
tI(points, X1 + xround*cos(a))
tI(points, Y2 + yround*sin(a))
end
for i = 0, precision do
local a = (i/precision+2)*hP
tI(points, X1 + xround*cos(a))
tI(points, Y1 + yround*sin(a))
end
love.graphics.polygon(mode, unpack(points))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment