Skip to content

Instantly share code, notes, and snippets.

@scambier
Last active May 12, 2021 12:01
Show Gist options
  • Save scambier/4e48a96c06b6beb2a0d2edcaa95d865b to your computer and use it in GitHub Desktop.
Save scambier/4e48a96c06b6beb2a0d2edcaa95d865b to your computer and use it in GitHub Desktop.
function sunrect()
-- rainbow palette
pal({1,-15,-13,3,-5,11,-6,10,9,-7,8,-8},1)
-- origin x,y and radius
ox,oy,r=64,64,60
::_::
cls()
-- 12 points for the 12 colors
for i=1,12 do
-- the 12 points are equally spread on the circle's top half
-- 0.5 / 12 = ~0.041
a=i*.041
-- anchor point (rect's top left) for the current color
x=ox+cos(a)*r
y=oy+sin(a)*r
-- "mirror" point (rect's bottom left), that will run around the circle in about 5 seconds
lx=ox+cos(a+t()/5)*r
ly=oy+sin(a+.5+t()/5)*r
-- line vector
dx=x-lx
dy=y-ly
-- calculate rect's bottom right
len=4/sqrt(dx^2+dy^2) -- the rect has a width of 4px
dx*=len
dy*=len
-- top left > bottom left
line(x,y,lx,ly,i)
-- > bottom right
line(lx+dy,ly-dx)
-- > top right
line(x+dy,y-dx)
-- > top left, to close the rect
line(x,y)
end
flip()
goto _
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment