Animator is designed to animate shapes and images on the screen. After an object is created, it can be scripted to move along a predefined trajectory or to move in response to forces. The default behavior is for an object to remain fixed at the position were it was created.
id=document.animator.addObject("circle","x=1,y=0");
In order to move an object according to the analytic functions of time xStr and yStr, the object identifier must be known and the setTrajectory method must be called.
document.animator.setTrajectory(id,xStr,yStr);
If an object is to become dynamic, that is, it interacts via forces and obeys Newton's Laws, the setForce method must be called.
fxStr="0";
fyStr="-9.8";
document.animator.setForce(id,fxStr,fyStr,x,y,vx,vy);
Since Newton's laws are second order differential equations, the setForce method requires initial values for both position and velocity. Initial values are fixed; they are passed as numbers, not strings. The solution to these equations of motion is calculated using a Runge-Kutta, RK4/5, algorithm with adaptive step size. This algorithm is not foolproof, but it is a general-purpose algorithm that solves most dynamics problems.
The design goal for Animator was flexibility, not speed. Most computers can easily handle 4 objects interacting via 1/r2 forces but most cannot handle 20. The reason is twofold. First, the number of calculations scale is n*n. Therefore increasing the number of interacting particles by a factor of 5 increases the calculation time by 25. Second, Animator makes extensive use of parsers, not predefined force laws. Interactions between objects are specified using strings that are passed to the applet using JavaScript. These strings must be evaluated repeatedly to determine the object's position and rate of movement. Although this allows any force to be entered, it is considerably slower than knowing the force whereby particles interact, coding this force function in Java, and compiling for optimum performance.
Objects cannot rotate.
See the molecular dynamics Physlets package computations with large numbers of particles.
See the EField Physlet for computations with involving potentials and electrostatic fields.
The following examples are not described in the text. Since these examples are designed to demonstrate scripts and not pedogoy, they are presented with minimal comments. Use the view source option available in most browsers to examine the script.