I noticed that people relatively often ask for a way to draw an inverted circle and don't have an easy way to implement it, since it requires a bit of math that can be difficult to derive without experience. I decided to make a quick cart and standalone function to do that! This isn't amazingly efficient, and it only does circles (not ellipses), but it is a drop in function:
Update: new function utilizing trig, faster and now subpixel!
x=x or 64
y=y or 64
r=r or 32
left=left or 0
right=right or 128
top=top or 0
bottom=bottom or 128
local p=r*6.28
if(top<y-r)rectfill(left,top,right,y-r,c)
if(bottom>y+r)rectfill(left,y+r,right,bottom,c)
for d=-.001,.25,1/p do
local ex,ey=r*cos(d),r*sin(d)
if(x-ex>left) then
if(y-ey>top) then
rect(left,y-ey,x-ex,y-ey,c)
end
if(y+ey<bottom) then
rect(left,y+ey,x-ex,y+ey,c)
end
end
if(x+ex<right) then
if(y-ey>top) then
rect(x+ex,y-ey,right,y-ey,c)
end
if(y+ey<bottom) then
rect(x+ex,y+ey,right,y+ey,c)
end
end
end |
Old versions:
P#83816 2020-11-05 20:16 ( Edited 2020-11-05 21:17)
[Please log in to post a comment]



