-- genuary #21 2023
-- persian rug
-- by carson kompon
-- huge thanks to piter pasma's explanation video
function dist(x,y)
return sqrt((x*x+y*y))
end
function edge(x,y)
if x>0 and y>0 then
return dist(x,y)
elseif x>y then
return x
end
return y
end
function sdf_rect(x,y,cx,cy,w,h)
x-=cx
y-=cy
return edge(abs(x)-w,abs(y)-h)
end
function sdf_circle(x,y,cx,cy,r)
x-=cx
y-=cy
return dist(x,y) - r
end
function sdf(x,y)
dd = 1.5
circle = sdf_circle(x,y,cos(t()/4+.5)/dd,sin(t()/16+.5)/dd,.001)
circle = (abs(circle)-.1)*1.2
box = sdf_rect(x,y,0,0,.9,.75)
return max(-circle,box)
end
pal({[0]=0,128,133,141,133,0,0,0,12,140,1,129,130,132,9,10},1)
::_::
x=rnd(2)-1
y=rnd(2)-1
d=sdf(x,y)
c=0
if(d<0)c=d*16
circfill((x+1)*64,(y+1)*64,1,c)
goto _