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.
on xLinear(p) return p * (endX - startX)
+ startX end
on yLinear(p) return p * (endY - startY)
+ startY end
on sine(p, cycles, scale) returnsin(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.