The Step Function

There are other useful functions you can use to show interesting motions. The step function is rather useful, for instance, and we use it here to produce motion around a square.


The step function gives zero when the expression being evaluated is negative, and gives 1 when the expression is positive. Thus:
step(1-t) is equal to 1 for t<1, and 0 for all times > 1
step(2-t)*step(t-1) is 1 if the time is between 1 and 2, and zero for all other times.

With the step function you can break the motion into different pieces. To produce the square both the x and y functions of time are split into four separate parts, so the addObject statement looks a bit complicated.
c1id=document.Animator.addObject("circle","x=step(1-t)*4*t+step(2-t)*step(t-1)*4+step(3-t)*step(t-2)*(4-4*(t-2)),y=step(t-1)*step(2-t)*4*(t-1)+step(t-2)*step(3-t)*4+step(t-3)*(4-4*(t-3)),r=10");

On the fourth side x=0 so we can leave that out of the statement, and on the first side y=0 so we can leave that out, too.

When the object has gone almost all the way around the setTimeCycle function (in conjunction with setting dt to 0.01 units) is used to produce the illusion of continuous motion.
document.Animator.setTimeCycle(3.99);