Skip to content

Instantly share code, notes, and snippets.

@nucleartide
Last active May 5, 2020 14:21
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 nucleartide/ff012ece80b576ab7b1575b5ee014c77 to your computer and use it in GitHub Desktop.
Save nucleartide/ff012ece80b576ab7b1575b5ee014c77 to your computer and use it in GitHub Desktop.
rounded rectfill for pico8
function rrectfill(x0, y0, x1, y1, col, corners)
local tl = corners and corners.tl
local tr = corners and corners.tr
local bl = corners and corners.bl
local br = corners and corners.br
local new_x0 = x0 + max(tl, bl)
local new_y0 = y0 + max(tl, tr)
local new_x1 = x1 - max(tr, br)
local new_y1 = y1 - max(bl, br)
rectfill(new_x0, new_y0, new_x1, new_y1, col)
if tl and tl>0 then
circfill(new_x0, new_y0, tl, col)
end
if tr and tr>0 then
circfill(new_x1, new_y0, tr, col)
end
if bl and bl>0 then
circfill(new_x0, new_y1, bl, col)
end
if br and br>0 then
circfill(new_x1, new_y1, br, col)
end
-- draw top rect
rectfill(new_x0, y0, new_x1, new_y0, col)
-- draw left rect
rectfill(x0, new_y0, new_x0, new_y1, col)
-- draw right rect
rectfill(new_x1, new_y0, x1, new_y1, col)
-- draw bottom rect
rectfill(new_x0, new_y1, new_x1, y1, col)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment