Skip to content

Instantly share code, notes, and snippets.

@lucatronica
Last active July 5, 2020 03:52
Show Gist options
  • Save lucatronica/ab4abb1a004a72b7e962112cb7b30b56 to your computer and use it in GitHub Desktop.
Save lucatronica/ab4abb1a004a72b7e962112cb7b30b56 to your computer and use it in GitHub Desktop.
::_::
cls()
--Iterate 6 jellies. The 0th one will be invisible, but we need it for pal().
for n=0,6 do
--The x position of the Jelly.
x=n*288%112
--Scale of the jelly, from 0..1.
k=n/6
--The jelly fish movements are controlled by this angle.
--The animation loops every q [0..1].
q=k+t()/5
--l determines the amount of horizontal stretch at the bottom of the body.
l=cos(q)
--Each jelly uses an ellipse formula for the general shape.
--h determines the radius of the ellipse.
h=k*(31+l*6)
--Loop from the top of the jelly to the bottom, we'll fill it by drawing
--horizintal lines.
--".5" helps it look solid even when the jelly grows in height.
for i=0,33*k,.5 do
--y is the y position of the line:
-- i-cos(q+.3)*i/5 -- Equivalent to (1-cos(q+.3)/5)*i. Shrinks the jelly
-- vertically up and down over time, 1-cos(q+.3)/5 will oscilate [0.8..1.2].
-- -t()*6*k -- Moves the jelly slowly upward. The ones in the BG move slower.
-- %160-9 -- Wraps the y position from top to bottom.
y=(i-cos(q+.3)*i/5-t()*6*k)%160-9
--Half of the width of the ellipse at the current line.
-- (h*h+9-(i-h)^2)^.5 -- Basically a weird circle equation/pythagoras: sqrt(h^2-(i-h)^2).
-- The +9 makes the top of the ellipse smoother.
-- l*max(i-29*k) -- The stretching at the bottom of the jelly.
-- Note max(0,i-29*k) -> max(i-29*k) since parameters default to 0.
r=(h*h+9-(i-h)^2)^.5+l*max(i-29*k)
--Draw the line.
line(x-r,y,x+r,y,4*k)
--Set the color palette using hidden colours.
--Note when n==0 you get pal(0,nil,1) -> pal(0,0,1).
pal(n,({129,1,140,12})[n],1)
end
--Draw the little tentacles.
for i=-r,r,r/9 do
-- i*l/7 -- Gives the angling of the tentacles.
-- y+7-l*l -- The -l*l shrinks y as the tentacle moves left or right,
-- making it look like it's rotating.
line(x+i,y+1,x+i+i*l/7,y+7-l*l,3*k)
end
end
flip()goto _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment