Easing equations (motion tween) for Lua


    Aug 15 2007 | 12:13 am

    • Aug 15 2007 | 8:48 am
    • Aug 15 2007 | 7:52 pm
      Well, if someone wants to start and manage a wiki about jit.gl.lua, I
      think it could be quite useful, but it's not something I can really
      get too much involved with. Of course that doesn't me I wouldn't post
      content.
      wes
      On 8/15/07, MarkDavid Hosale wrote:
      > Hi Alexandre-
      > This is cool stuff. I've been getting into using Lua with Jitter as
      > well. I wonder how many of us are out there using it? Maybe there
      > should be (or is there already?) a jit.gl.lua wiki or something for
      > things like this. Does anyone else think this is a good idea? Wes?...
      > -MarkDavid
      >
      >
      > On Aug 14, 2007, at 5:13 PM, Alexandre Quessy wrote:
      >
      > > Hi all,
      > > I am getting quite familiar with Lua and OpenGL. This is a great
      > > tool. It works very well for 2D and 3D graphics using textures and
      > > such.
      > >
      > > I ported some of Robert Penner's easing equations to Lua in order
      > > to create motion effects with jit.gl.lua. Here they are, for you
      > > delight. Maybe I could port them all and distribute in a more
      > > formal way, but I don't think I will. (exercise left to the reader !)
      > >
      > > Cheers,
      > >
      > > -----
      > > -- Robert Penner easing equations for Adobe ActionScript.
      > > -- Translated to Lua (only some of my favorites)
      > > -- see http://www.robertpenner.com/easing/
      > > -- Open source under the BSD License.
      > > -- Copyright (c) 2001 Robert Penner
      > > -- All rights reserved.
      > >
      > > -- simple linear tweening - no easing
      > > -- t: current time, b: beginning value, c: change in value, d:
      > > duration
      > > function linearTween(t, b, c, d)
      > > return c*t/d + b
      > > end
      > >
      > > ------------/ QUADRATIC EASING: t^2 ------------------/
      > >
      > > -- quadratic easing in - accelerating from zero velocity
      > > -- t: current time, b: beginning value, c: change in value, d:
      > > duration
      > > -- t and d can be in frames or seconds/milliseconds
      > > function easeInQuad(t, b, c, d)
      > > return c*(t/d)*t + b
      > > end
      > >
      > > -- quadratic easing out - decelerating to zero velocity
      > > function easeOutQuad(t, b, c, d)
      > > return -c *(t/d)*(t-2) + b
      > > end
      > >
      > > ------------/ SINUSOIDAL EASING: sin(t) --------------/
      > >
      > > -- sinusoidal easing in - accelerating from zero velocity
      > > -- t: current time, b: beginning value, c: change in position, d:
      > > duration
      > > function easeInSine(t, b, c, d)
      > > return -c * math.cos(t/d * (math.pi/2)) + c + b;
      > > end
      > >
      > > -- sinusoidal easing out - decelerating to zero velocity
      > > function easeOutSine(t, b, c, d)
      > > return c * math.sin(t/d * (math.pi/2)) + b;
      > > end
      > >
      > > -- sinusoidal easing in/out - accelerating until halfway, then
      > > decelerating
      > > function easeInOutSine(t, b, c, d)
      > > return -c/2 * (math.cos(math.pi*t/d) - 1) + b;
      > > end
      > >
      > > ------------/ EXPONENTIAL EASING: 2^t ----------------/
      > >
      > > -- exponential easing in - accelerating from zero velocity
      > > -- t: current time, b: beginning value, c: change in position, d:
      > > duration
      > > function easeInExpo(t, b, c, d)
      > > if (t==0) then
      > > return b
      > > else
      > > return c * math.pow(2, 10 * (t/d - 1)) + b
      > > end
      > > end
      > >
      > > -- exponential easing out - decelerating to zero velocity
      > > function easeOutExpo(t, b, c, d)
      > > if (t==d) then
      > > return b+c
      > > else
      > > return c * (-math.pow(2, -10 * t/d) + 1) + b
      > > end
      > > end
      >
      >
      >
    • Aug 20 2007 | 3:40 pm