Skip to content

Instantly share code, notes, and snippets.

@scambier
Created May 15, 2021 09:15
Show Gist options
  • Select an option

  • Save scambier/798dc033e0d9753ce6a62012927b0ecd to your computer and use it in GitHub Desktop.

Select an option

Save scambier/798dc033e0d9753ce6a62012927b0ecd to your computer and use it in GitHub Desktop.
function setting_sun()
-- set the palette with all the necessary color,
-- in the right order
pal({10,-7,8,-7,10,14,1},1)
-- circle radius
radius=40
-- start loop
::_::
-- dithering background fill, with color relative to y
for i=0,3000 do
y=rnd(128)
pset(rnd(128), y+rnd(20)-10, y/64+6)
end
-- the pink background behind the sun
-- to "erase" the dithering that's not in water
rectfill(0,0,128,64,14)
-- loop to draw the lines from top to bottom
for y=1,79 do
-- normalized ratio between radius and y
r = (radius-y)/radius
-- get angle from r, this is basically asin(r)
-- except that pico8 doesn't have asin()
a = atan2(r,-sqrt(1-r*r))
--- line starting point
x = sin(a)*radius
-- color, relative to height
c = y/70*4 + 1
-- y offset value thay will make the sun wobble.
-- this is basically a lot of trial and error to have the desired effect
-- and could certainly be simplified
y_offset = y/6 * (sin(x*x/160+t()/4)) * (50-y)/40
-- draw the line with the new y coordinate
ny = y + 24 + y_offset
line(64+x,ny,64-x,ny,c)
end
flip()
goto _
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment