Home Contents Forum Links Tip Jar
Animation Math in Lingo       

Combining Motions Independently

To start, this demo uses linear as the primary motion, and sine as the secondary motion, or offset. Offsetting linear by sine creates the curve shown in The Sine Wave. The black dot in the demo shows the linear motion, and the red dot shows the linear with a sine function added.

Click to move the dot Sine offset - source movie

on exitframe()
  -- drive p
  p = eTimeOnce(2000) -- two seconds

  --no bias

  -- p drives animation
  sp.loch = xLinear(p) + sine(p, xCycles, 30)
  sp.locv = yLinear(p) + sine(p, yCycles, 30)
  spBlack.loch = xLinear(p)
  spBlack.locv = yLinear(p)
end

on xLinear(p)
  return p * (endX - startX) + startX
end

on yLinear(p)
  return p * (endY - startY) + startY
end

on sine(p, cycles, scale)
  return sin(p * pi * cycles) * scale
end
Only the exitframe handler and animation functions shown here. See source movie for full script.

In particular, set just x cycles or just y cycles and see what it means to offset each independently. Examine the behavior with trails off as well as on.

This script has the same form as previous parametric animation scripts: drive p, bias p, p drives animation. In this one, the linear functions are moved out of the exitframe handler into their own handlers, xLinear() and yLinear(), for easy reuse for both animated objects (black dot and red).

Secondary Motion
For the start and end points of the motion to remain the same after offsetting, the offset function must give a value of 0 when p=0 and when p=1. Otherwise, the start and end points will be offset as well. With the sine function this is easy to do, since sine is 0 at multiples of pi. This explains the expression p * pi * cycles. If cycles is any integer, this expression will evaluate to a multiple of pi when p=0 and p=1. The sine at those values will therefore be 0.

Multiplying by scale makes the offset larger. Without scaling, the curve would hardly be noticeable, since sin() itself doesn't get larger than 1 or -1.

Independent Secondary Motion
Because the sine offset is not related to the linear motion, the object's path is a different shape for different linear directions. This may be the intended effect in an animation.

Other times it is desirable for the object's path to have a consistent shape. This is done by making the secondary motion, sine, dependent on the linear motion. The next section shows how to do this.

 
 


Copyright © 2003 JM Harward 
 jmckell~at~jmckell~dot~com
All lingo provided on this site may be used freely for educational purposes. Not for redistribution as uncompiled code. Instructional materials may not be reproduced without permission.