Löve version of Equations for Organic Motion

Originally by Justin Windle (it seems), I found the Equations for Organic Motion on CodePen a while ago, but I couldn’t get a version working tonight. So I made my own from the source.

I needed a nice wobble motion so my version has wiggling circles to go with the pulsating ones.

-- Equations for Organic Motion

local lg = love.graphics

-- For speed and laziness
local sin = math.sin
local cos = math.cos
local tan = math.tan
local pow = math.pow
local pi  = math.pi
local abs = math.abs
local exp = math.exp

function love.load()
  funcs = {
    function(t) return sin(t) end,
    function(t) return cos(t) end,
    function(t) return cos(t)*sin(t) end,
    function(t) return sin(t)*sin(t*1.5) end,

    function(t) return sin(tan(cos(t)*1.2)) end,
    function(t) return sin(tan(t)*0.05) end,
    function(t) return cos(sin(t*3))*sin(t*0.2) end,
    function(t) return sin(pow(8,sin(t))) end,

    function(t) return sin(exp(cos(t*0.8))*2) end,
    function(t) return sin(t-pi*tan(t)*0.01) end,
    function(t) return pow(sin(t*pi),12) end,
    function(t) return cos(sin(t)*tan(t*pi)*pi/8) end,

    function(t) return sin(tan(t)*pow(sin(t),10)) end,
    function(t) return cos(sin(t*3)+t*3) end,
    function(t) return pow(abs(sin(t*2))*0.6,sin(t*2))*0.6 end,
  }

  mode = 'pulse'
  speed = 1
end

function love.update(dt)
end

function love.keypressed(key, code)
  if key == "p" then mode = 'pulse' end
  if key == "w" then mode = 'wobble' end
  if key == "=" then speed = speed * 2 end
  if key == "-" then speed = speed / 2 end
end

function love.draw()
  lg.setColor(255, 255, 255)
  lg.print("Original Source:\nEquations for Organic Motion", lg.getWidth() - 200, 20)
  lg.print("p : Circle pulse mode\nw : Wobble mode\n+ : Double speed\n- : Half speed", lg.getWidth() - 200, 60)

  local t = love.timer.getTime() * speed

  lg.setColor(255,255,255)
  for i = 1, #funcs do
    xOff = (((i-1) % 4) * 150) + 75
    yOff = math.floor((i-1) / 4) * 150 + 75
    lg.push()
    lg.translate(xOff, yOff)
    
    if mode == 'pulse' then
      local radius = funcs[i](t) * 50
      lg.circle('fill', 0, 0, radius, 22)
    elseif mode == 'wobble' then
      local x = funcs[i](t) * 10
      local y = funcs[i](t/1.3) * 10 ------------ Change Y, fiddle with this for fun
      lg.circle('fill', x, y, 10, 22)
    end
    lg.pop()
  end
  
  -- showfps
  --lg.setFont(game.dFont)
  lg.setColor(255,0,0,255)
  lg.print(tostring(love.timer.getFPS()), lg.getWidth()-30, lg.getHeight()-20)
end

Let nobody doubt my commitment to organic motion.